/* Indentation functions.
Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1998, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
#include <stdio.h>
+#include <setjmp.h>
#include "lisp.h"
#include "buffer.h"
static int last_known_column_modified;
-static double current_column_1 P_ ((void));
-static double position_indentation P_ ((int));
+static double current_column_1 (void);
+static double position_indentation (int);
/* Cache of beginning of line found by the last call of
current_column. */
/* Get the display table to use for the current buffer. */
struct Lisp_Char_Table *
-buffer_display_table ()
+buffer_display_table (void)
{
Lisp_Object thisbuf;
/* Return the width of character C under display table DP. */
static int
-character_width (c, dp)
- int c;
- struct Lisp_Char_Table *dp;
+character_width (int c, struct Lisp_Char_Table *dp)
{
Lisp_Object elt;
invalidate the buffer's width_run_cache. */
int
-disptab_matches_widthtab (disptab, widthtab)
- struct Lisp_Char_Table *disptab;
- struct Lisp_Vector *widthtab;
+disptab_matches_widthtab (struct Lisp_Char_Table *disptab, struct Lisp_Vector *widthtab)
{
int i;
/* Recompute BUF's width table, using the display table DISPTAB. */
void
-recompute_width_table (buf, disptab)
- struct buffer *buf;
- struct Lisp_Char_Table *disptab;
+recompute_width_table (struct buffer *buf, struct Lisp_Char_Table *disptab)
{
int i;
struct Lisp_Vector *widthtab;
state of current_buffer's cache_long_line_scans variable. */
static void
-width_run_cache_on_off ()
+width_run_cache_on_off (void)
{
if (NILP (current_buffer->cache_long_line_scans)
/* And, for the moment, this feature doesn't work on multibyte
will equal the return value. */
EMACS_INT
-skip_invisible (pos, next_boundary_p, to, window)
- EMACS_INT pos;
- EMACS_INT *next_boundary_p;
- EMACS_INT to;
- Lisp_Object window;
+skip_invisible (EMACS_INT pos, EMACS_INT *next_boundary_p, EMACS_INT to, Lisp_Object window)
{
Lisp_Object prop, position, overlay_limit, proplimit;
Lisp_Object buffer, tmp;
{
/* Don't scan terribly far. */
XSETFASTINT (proplimit, min (pos + 100, to));
- /* No matter what. don't go past next overlay change. */
+ /* No matter what, don't go past next overlay change. */
if (XFASTINT (overlay_limit) < XFASTINT (proplimit))
proplimit = overlay_limit;
tmp = Fnext_single_property_change (position, Qinvisible,
int c; \
\
wide_column = 0; \
- c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, bytes); \
+ c = STRING_CHAR_AND_LENGTH (p, bytes); \
if (BYTES_BY_CHAR_HEAD (*p) != bytes) \
width = bytes * 4; \
else \
/* Cancel any recorded value of the horizontal position. */
void
-invalidate_current_column ()
+invalidate_current_column (void)
{
last_known_column_point = 0;
}
double
-current_column ()
+current_column (void)
{
register int col;
register unsigned char *ptr, *stop;
width = XINT (prop) - col;
else if (FLOATP (prop))
width = (int)(XFLOAT_DATA (prop) + 0.5) - col;
-
+
if (width >= 0)
{
EMACS_INT start;
register struct Lisp_Char_Table *dp = buffer_display_table ();
int multibyte = !NILP (current_buffer->enable_multibyte_characters);
struct composition_it cmp_it;
+ Lisp_Object window;
+ struct window *w;
/* Start the scan at the beginning of this line with column number 0. */
register EMACS_INT col = 0, prev_col = 0;
next_boundary = scan;
}
+ window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
+ w = ! NILP (window) ? XWINDOW (window) : NULL;
+
if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
bzero (&cmp_it, sizeof cmp_it);
cmp_it.id = -1;
if (cmp_it.id >= 0
|| (scan == cmp_it.stop_pos
&& composition_reseat_it (&cmp_it, scan, scan_byte, end,
- XWINDOW (selected_window), NULL, Qnil)))
+ w, NULL, Qnil)))
composition_update_it (&cmp_it, scan, scan_byte, Qnil);
if (cmp_it.id >= 0)
{
to this character. */
if (dp != 0
- && ! (multibyte && BASE_LEADING_CODE_P (c))
+ && ! (multibyte && LEADING_CODE_P (c))
&& VECTORP (DISP_CHAR_VECTOR (dp, c)))
{
Lisp_Object charvec;
col += tab_width;
col = col / tab_width * tab_width;
}
- else if (multibyte && BASE_LEADING_CODE_P (c))
+ else if (multibyte && LEADING_CODE_P (c))
{
/* Start of multi-byte form. */
unsigned char *ptr;
due to text properties or overlays. */
static double
-current_column_1 ()
+current_column_1 (void)
{
EMACS_INT col = MOST_POSITIVE_FIXNUM;
EMACS_INT opoint = PT;
}
\f
-static double position_indentation P_ ((int));
+static double position_indentation (int);
DEFUN ("current-indentation", Fcurrent_indentation, Scurrent_indentation,
0, 0, 0,
}
static double
-position_indentation (pos_byte)
- register int pos_byte;
+position_indentation (register int pos_byte)
{
register EMACS_INT column = 0;
register EMACS_INT tab_width = XINT (current_buffer->tab_width);
preceding line. */
int
-indented_beyond_p (pos, pos_byte, column)
- int pos, pos_byte;
- double column;
+indented_beyond_p (int pos, int pos_byte, double column)
{
double val;
int opoint = PT, opoint_byte = PT_BYTE;
the scroll bars if they are turned on. */
struct position *
-compute_motion (from, fromvpos, fromhpos, did_motion, to, tovpos, tohpos, width, hscroll, tab_offset, win)
- EMACS_INT from, fromvpos, fromhpos, to, tovpos, tohpos;
- int did_motion;
- EMACS_INT width;
- EMACS_INT hscroll, tab_offset;
- struct window *win;
+compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_motion, EMACS_INT to, EMACS_INT tovpos, EMACS_INT tohpos, EMACS_INT width, EMACS_INT hscroll, EMACS_INT tab_offset, struct window *win)
{
register EMACS_INT hpos = fromhpos;
register EMACS_INT vpos = fromvpos;
}
if (dp != 0
- && ! (multibyte && BASE_LEADING_CODE_P (c))
+ && ! (multibyte && LEADING_CODE_P (c))
&& VECTORP (DISP_CHAR_VECTOR (dp, c)))
{
charvec = DISP_CHAR_VECTOR (dp, c);
hpos = width;
}
}
- else if (multibyte && BASE_LEADING_CODE_P (c))
+ else if (multibyte && LEADING_CODE_P (c))
{
/* Start of multi-byte form. */
unsigned char *ptr;
struct position val_vmotion;
struct position *
-vmotion (from, vtarget, w)
- register EMACS_INT from, vtarget;
- struct window *w;
+vmotion (register EMACS_INT from, register EMACS_INT vtarget, struct window *w)
{
EMACS_INT hscroll = XINT (w->hscroll);
struct position pos;
}
else
{
- int it_start, oselective, first_x, it_overshoot_expected;
+ int it_start, first_x, it_overshoot_expected;
SET_TEXT_POS (pt, PT, PT_BYTE);
start_display (&it, w, pt);
{
if (it.cmp_it.id >= 0)
it_overshoot_expected = 1;
- if (it.method == GET_FROM_STRING)
+ else if (it.method == GET_FROM_STRING)
{
const char *s = SDATA (it.string);
const char *e = s + SBYTES (it.string);
really at some x > 0. */
reseat_at_previous_visible_line_start (&it);
it.current_x = it.hpos = 0;
- /* Temporarily disable selective display so we don't move too far */
- oselective = it.selective;
- it.selective = 0;
- move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
- it.selective = oselective;
+ if (IT_CHARPOS (it) != PT)
+ /* We used to temporarily disable selective display here; the
+ comment said this is "so we don't move too far" (2005-01-19
+ checkin by kfs). But this does nothing useful that I can
+ tell, and it causes Bug#2694 . -- cyd */
+ move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
if (XINT (lines) <= 0)
{
}
else
{
- if (IT_CHARPOS (it) > PT)
+ if (IT_CHARPOS (it) > it_start)
{
/* IT may move too far if truncate-lines is on and PT
lies beyond the right margin. In that case,
which might span multiple screen lines (e.g., if it's
on a multi-line display string). We want to start
from the last line that it occupies. */
- it.vpos = 0;
- if (PT < ZV)
+ if (it_start < ZV)
{
- while (IT_CHARPOS (it) <= PT)
- move_it_by_lines (&it, 1, 0);
- move_it_by_lines (&it, XINT (lines) - 1, 0);
+ while (IT_CHARPOS (it) <= it_start)
+ {
+ it.vpos = 0;
+ move_it_by_lines (&it, 1, 0);
+ }
+ if (XINT (lines) > 1)
+ move_it_by_lines (&it, XINT (lines) - 1, 0);
}
else
- move_it_by_lines (&it, XINT (lines), 0);
+ {
+ it.vpos = 0;
+ move_it_by_lines (&it, XINT (lines), 0);
+ }
}
}
/* File's initialization. */
void
-syms_of_indent ()
+syms_of_indent (void)
{
DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode,
doc: /* *Indentation can insert tabs if this is non-nil. */);