/* Indentation functions.
- Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1998, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+ Copyright (C) 1985-1988, 1993-1995, 1998, 2000-2011
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "dispextern.h"
#include "region-cache.h"
-/* Indentation can insert tabs if this is non-zero;
- otherwise always uses spaces. */
-
-static int indent_tabs_mode;
-
#define CR 015
/* These three values memorize the current column to avoid recalculation. */
Some things in set last_known_column_point to -1
to mark the memorized value as invalid. */
-static double last_known_column;
+static EMACS_INT last_known_column;
/* Value of point when current_column was called. */
static int last_known_column_modified;
-static double current_column_1 (void);
-static double position_indentation (int);
+static EMACS_INT current_column_1 (void);
+static EMACS_INT position_indentation (int);
/* Cache of beginning of line found by the last call of
current_column. */
{
Lisp_Object thisbuf;
- thisbuf = current_buffer->display_table;
+ thisbuf = BVAR (current_buffer, display_table);
if (DISP_TABLE_P (thisbuf))
return XCHAR_TABLE (thisbuf);
if (DISP_TABLE_P (Vstandard_display_table))
int i;
struct Lisp_Vector *widthtab;
- if (!VECTORP (buf->width_table))
- buf->width_table = Fmake_vector (make_number (256), make_number (0));
- widthtab = XVECTOR (buf->width_table);
+ if (!VECTORP (BVAR (buf, width_table)))
+ BVAR (buf, width_table) = Fmake_vector (make_number (256), make_number (0));
+ widthtab = XVECTOR (BVAR (buf, width_table));
if (widthtab->size != 256)
abort ();
static void
width_run_cache_on_off (void)
{
- if (NILP (current_buffer->cache_long_line_scans)
+ if (NILP (BVAR (current_buffer, cache_long_line_scans))
/* And, for the moment, this feature doesn't work on multibyte
characters. */
- || !NILP (current_buffer->enable_multibyte_characters))
+ || !NILP (BVAR (current_buffer, enable_multibyte_characters)))
{
/* It should be off. */
if (current_buffer->width_run_cache)
{
free_region_cache (current_buffer->width_run_cache);
current_buffer->width_run_cache = 0;
- current_buffer->width_table = Qnil;
+ BVAR (current_buffer, width_table) = Qnil;
}
}
else
This macro is used in current_column_1, Fmove_to_column, and
compute_motion. */
-#define MULTIBYTE_BYTES_WIDTH(p, dp) \
+#define MULTIBYTE_BYTES_WIDTH(p, dp, bytes, width) \
do { \
- int c; \
+ int ch; \
\
wide_column = 0; \
- c = STRING_CHAR_AND_LENGTH (p, bytes); \
+ ch = STRING_CHAR_AND_LENGTH (p, bytes); \
if (BYTES_BY_CHAR_HEAD (*p) != bytes) \
width = bytes * 4; \
else \
{ \
- if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, c))) \
- width = XVECTOR (DISP_CHAR_VECTOR (dp, c))->size; \
+ if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, ch))) \
+ width = XVECTOR (DISP_CHAR_VECTOR (dp, ch))->size; \
else \
- width = CHAR_WIDTH (c); \
+ width = CHAR_WIDTH (ch); \
if (width > 1) \
wide_column = width; \
} \
(void)
{
Lisp_Object temp;
- XSETFASTINT (temp, (int) current_column ()); /* iftc */
+ XSETFASTINT (temp, current_column ());
return temp;
}
last_known_column_point = 0;
}
-double
+EMACS_INT
current_column (void)
{
- register int col;
+ register EMACS_INT col;
register unsigned char *ptr, *stop;
register int tab_seen;
- int post_tab;
+ EMACS_INT post_tab;
register int c;
- register int tab_width = XINT (current_buffer->tab_width);
- int ctl_arrow = !NILP (current_buffer->ctl_arrow);
+ register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width));
+ int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
register struct Lisp_Char_Table *dp = buffer_display_table ();
if (PT == last_known_column_point
col++;
else if (c == '\n'
|| (c == '\r'
- && EQ (current_buffer->selective_display, Qt)))
+ && EQ (BVAR (current_buffer, selective_display), Qt)))
{
ptr++;
goto start_of_line_found;
static void
scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
{
- register EMACS_INT tab_width = XINT (current_buffer->tab_width);
- register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
+ register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width));
+ register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
register struct Lisp_Char_Table *dp = buffer_display_table ();
- int multibyte = !NILP (current_buffer->enable_multibyte_characters);
+ int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
struct composition_it cmp_it;
Lisp_Object window;
struct window *w;
prev_col = col;
{ /* Check display property. */
- EMACS_INT end;
- int width = check_display_width (scan, col, &end);
+ EMACS_INT endp;
+ int width = check_display_width (scan, col, &endp);
if (width >= 0)
{
col += width;
- if (end > scan) /* Avoid infinite loops with 0-width overlays. */
+ if (endp > scan) /* Avoid infinite loops with 0-width overlays. */
{
- scan = end; scan_byte = charpos_to_bytepos (scan);
+ scan = endp; scan_byte = charpos_to_bytepos (scan);
continue;
}
}
if (c == '\n')
goto endloop;
- if (c == '\r' && EQ (current_buffer->selective_display, Qt))
+ if (c == '\r' && EQ (BVAR (current_buffer, selective_display), Qt))
goto endloop;
if (c == '\t')
{
if (c == '\n')
goto endloop;
- if (c == '\r' && EQ (current_buffer->selective_display, Qt))
+ if (c == '\r' && EQ (BVAR (current_buffer, selective_display), Qt))
goto endloop;
if (c == '\t')
{
int bytes, width, wide_column;
ptr = BYTE_POS_ADDR (scan_byte);
- MULTIBYTE_BYTES_WIDTH (ptr, dp);
+ MULTIBYTE_BYTES_WIDTH (ptr, dp, bytes, width);
/* Subtract one to compensate for the increment
that is going to happen below. */
scan_byte += bytes - 1;
This function handles characters that are invisible
due to text properties or overlays. */
-static double
+static EMACS_INT
current_column_1 (void)
{
EMACS_INT col = MOST_POSITIVE_FIXNUM;
The return value is COLUMN. */)
(Lisp_Object column, Lisp_Object minimum)
{
- int mincol;
- register int fromcol;
- register int tab_width = XINT (current_buffer->tab_width);
+ EMACS_INT mincol;
+ register EMACS_INT fromcol;
+ register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width));
CHECK_NUMBER (column);
if (NILP (minimum))
}
\f
-static double position_indentation (int);
-
DEFUN ("current-indentation", Fcurrent_indentation, Scurrent_indentation,
0, 0, 0,
doc: /* Return the indentation of the current line.
scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
- XSETFASTINT (val, (int) position_indentation (PT_BYTE)); /* iftc */
+ XSETFASTINT (val, position_indentation (PT_BYTE));
SET_PT_BOTH (opoint, opoint_byte);
return val;
}
-static double
+static EMACS_INT
position_indentation (register int pos_byte)
{
register EMACS_INT column = 0;
- register EMACS_INT tab_width = XINT (current_buffer->tab_width);
+ register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width));
register unsigned char *p;
register unsigned char *stop;
unsigned char *start;
switch (*p++)
{
case 0240:
- if (! NILP (current_buffer->enable_multibyte_characters))
+ if (! NILP (BVAR (current_buffer, enable_multibyte_characters)))
return column;
case ' ':
column++;
break;
default:
if (ASCII_BYTE_P (p[-1])
- || NILP (current_buffer->enable_multibyte_characters))
+ || NILP (BVAR (current_buffer, enable_multibyte_characters)))
return column;
{
int c;
preceding line. */
int
-indented_beyond_p (EMACS_INT pos, EMACS_INT pos_byte, double column)
+indented_beyond_p (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT column)
{
- double val;
+ EMACS_INT val;
EMACS_INT opoint = PT, opoint_byte = PT_BYTE;
SET_PT_BOTH (pos, pos_byte);
val = position_indentation (PT_BYTE);
SET_PT_BOTH (opoint, opoint_byte);
- return val >= column; /* hmm, float comparison */
+ return val >= column;
}
\f
DEFUN ("move-to-column", Fmove_to_column, Smove_to_column, 1, 2, "p",
register EMACS_INT pos;
EMACS_INT pos_byte;
register int c = 0;
- register EMACS_INT tab_width = XFASTINT (current_buffer->tab_width);
- register int ctl_arrow = !NILP (current_buffer->ctl_arrow);
+ register EMACS_INT tab_width = XFASTINT (BVAR (current_buffer, tab_width));
+ register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
register struct Lisp_Char_Table *dp = window_display_table (win);
- int selective
- = (INTEGERP (current_buffer->selective_display)
- ? XINT (current_buffer->selective_display)
- : !NILP (current_buffer->selective_display) ? -1 : 0);
+ EMACS_INT selective
+ = (INTEGERP (BVAR (current_buffer, selective_display))
+ ? XINT (BVAR (current_buffer, selective_display))
+ : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0);
int selective_rlen
= (selective && dp && VECTORP (DISP_INVIS_VECTOR (dp))
? XVECTOR (DISP_INVIS_VECTOR (dp))->size : 0);
EMACS_INT next_width_run = from;
Lisp_Object window;
- int multibyte = !NILP (current_buffer->enable_multibyte_characters);
+ int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
/* If previous char scanned was a wide character,
this is the column where it ended. Otherwise, this is 0. */
EMACS_INT wide_column_end_hpos = 0;
width_run_cache_on_off ();
if (dp == buffer_display_table ())
- width_table = (VECTORP (current_buffer->width_table)
- ? XVECTOR (current_buffer->width_table)->contents
+ width_table = (VECTORP (BVAR (current_buffer, width_table))
+ ? XVECTOR (BVAR (current_buffer, width_table))->contents
: 0);
else
/* If the window has its own display table, we can't use the width
unsigned char *ovstr;
EMACS_INT ovlen = overlay_strings (pos, win, &ovstr);
hpos += ((multibyte && ovlen > 0)
- ? strwidth (ovstr, ovlen) : ovlen);
+ ? strwidth ((char *) ovstr, ovlen) : ovlen);
}
did_motion = 0;
}
if (hscroll || truncate
- || !NILP (current_buffer->truncate_lines))
+ || !NILP (BVAR (current_buffer, truncate_lines)))
{
/* Truncating: skip to newline, unless we are already past
TO (we need to go back below). */
else if (c == '\n')
{
if (selective > 0
- && indented_beyond_p (pos, pos_byte,
- (double) selective)) /* iftc */
+ && indented_beyond_p (pos, pos_byte, selective))
{
/* If (pos == to), we don't have to take care of
selective display. */
}
while (pos < to
&& indented_beyond_p (pos, pos_byte,
- (double) selective)); /* iftc */
+ selective));
/* Allow for the " ..." that is displayed for them. */
if (selective_rlen)
{
{
/* Start of multi-byte form. */
unsigned char *ptr;
- int bytes, width, wide_column;
+ int mb_bytes, mb_width, wide_column;
pos_byte--; /* rewind POS_BYTE */
ptr = BYTE_POS_ADDR (pos_byte);
- MULTIBYTE_BYTES_WIDTH (ptr, dp);
- pos_byte += bytes;
+ MULTIBYTE_BYTES_WIDTH (ptr, dp, mb_bytes, mb_width);
+ pos_byte += mb_bytes;
if (wide_column)
wide_column_end_hpos = hpos + wide_column;
- hpos += width;
+ hpos += mb_width;
}
else if (VECTORP (charvec))
++hpos;
register EMACS_INT first;
EMACS_INT from_byte;
EMACS_INT lmargin = hscroll > 0 ? 1 - hscroll : 0;
- int selective
- = (INTEGERP (current_buffer->selective_display)
- ? XINT (current_buffer->selective_display)
- : !NILP (current_buffer->selective_display) ? -1 : 0);
+ EMACS_INT selective
+ = (INTEGERP (BVAR (current_buffer, selective_display))
+ ? XINT (BVAR (current_buffer, selective_display))
+ : !NILP (BVAR (current_buffer, selective_display)) ? -1 : 0);
Lisp_Object window;
EMACS_INT start_hpos = 0;
int did_motion;
&& ((selective > 0
&& indented_beyond_p (prevline,
CHAR_TO_BYTE (prevline),
- (double) selective)) /* iftc */
+ selective))
/* Watch out for newlines with `invisible' property.
When moving upward, check the newline before. */
|| (propval = Fget_char_property (make_number (prevline - 1),
&& ((selective > 0
&& indented_beyond_p (prevline,
CHAR_TO_BYTE (prevline),
- (double) selective)) /* iftc */
+ selective))
/* Watch out for newlines with `invisible' property.
When moving downward, check the newline after. */
|| (propval = Fget_char_property (make_number (prevline),
Lisp_Object old_buffer;
struct gcpro gcpro1;
Lisp_Object lcols = Qnil;
- double cols;
+ double cols IF_LINT (= 0);
/* Allow LINES to be of the form (HPOS . VPOS) aka (COLUMNS . LINES). */
if (CONSP (lines) && (NUMBERP (XCAR (lines))))
}
else
{
- int it_start, first_x, it_overshoot_expected;
+ int it_start, first_x, it_overshoot_expected IF_LINT (= 0);
SET_TEXT_POS (pt, PT, PT_BYTE);
start_display (&it, w, pt);
it_overshoot_expected = 1;
else if (it.method == GET_FROM_STRING)
{
- const char *s = SDATA (it.string);
+ const char *s = SSDATA (it.string);
const char *e = s + SBYTES (it.string);
while (s < e && *s != '\n')
++s;
/* Do this even if LINES is 0, so that we move back to the
beginning of the current line as we ought. */
if (XINT (lines) == 0 || IT_CHARPOS (it) > 0)
- move_it_by_lines (&it, XINT (lines), 0);
+ move_it_by_lines (&it, XINT (lines));
}
else
{
|| (it_overshoot_expected < 0
&& it.method == GET_FROM_BUFFER
&& it.c == '\n'))
- move_it_by_lines (&it, -1, 0);
+ move_it_by_lines (&it, -1);
it.vpos = 0;
- move_it_by_lines (&it, XINT (lines), 0);
+ move_it_by_lines (&it, XINT (lines));
}
else
{
while (IT_CHARPOS (it) <= it_start)
{
it.vpos = 0;
- move_it_by_lines (&it, 1, 0);
+ move_it_by_lines (&it, 1);
}
if (XINT (lines) > 1)
- move_it_by_lines (&it, XINT (lines) - 1, 0);
+ move_it_by_lines (&it, XINT (lines) - 1);
}
else
{
it.vpos = 0;
- move_it_by_lines (&it, XINT (lines), 0);
+ move_it_by_lines (&it, XINT (lines));
}
}
}
void
syms_of_indent (void)
{
- DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode,
+ DEFVAR_BOOL ("indent-tabs-mode", indent_tabs_mode,
doc: /* *Indentation can insert tabs if this is non-nil. */);
indent_tabs_mode = 1;
defsubr (&Svertical_motion);
defsubr (&Scompute_motion);
}
-
-/* arch-tag: 9adfea44-71f7-4988-8ee3-96da15c502cc
- (do not change this comment) */