summaryrefslogtreecommitdiff
path: root/src/indent.c
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2013-08-29 11:03:18 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2013-08-29 11:03:18 +0400
commitd2b368135803170fc2d1f65237b7ef22676f9ecb (patch)
tree366956b20df8e76e561878824bd5e96fa5936d85 /src/indent.c
parente8dfd19797fa7224ae726a8be78726fefd260c0e (diff)
downloademacs-d2b368135803170fc2d1f65237b7ef22676f9ecb.tar.gz
Hook scanning and indentation functions to find_newline. This helps
to avoid duplicated code and renders more respect to newline cache. * lisp.h (scan_newline): Prefer ptrdiff_t to EMACS_INT. * cmds.c (Fforward_line): * indent.c (scan_for_column, Fcurrent_indentation, indented_beyond_p): Use find_newline and avoid unnecessary point movements. * search.c (scan_newline): Implement on top of find_newline.
Diffstat (limited to 'src/indent.c')
-rw-r--r--src/indent.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/indent.c b/src/indent.c
index 6aaf86579d7..891b42788ed 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -510,15 +510,10 @@ scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t *prevcol)
register ptrdiff_t col = 0, prev_col = 0;
EMACS_INT goal = goalcol ? *goalcol : MOST_POSITIVE_FIXNUM;
ptrdiff_t end = endpos ? *endpos : PT;
- ptrdiff_t scan, scan_byte;
- ptrdiff_t next_boundary;
- {
- ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
- scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
- scan = PT, scan_byte = PT_BYTE;
- SET_PT_BOTH (opoint, opoint_byte);
+ ptrdiff_t scan, scan_byte, next_boundary;
+
+ scan = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &scan_byte, 1);
next_boundary = scan;
- }
window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
w = ! NILP (window) ? XWINDOW (window) : NULL;
@@ -835,14 +830,10 @@ This is the horizontal position of the character
following any initial whitespace. */)
(void)
{
- Lisp_Object val;
- ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
-
- scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1);
+ ptrdiff_t posbyte;
- XSETFASTINT (val, position_indentation (PT_BYTE));
- SET_PT_BOTH (opoint, opoint_byte);
- return val;
+ find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &posbyte, 1);
+ return make_number (position_indentation (posbyte));
}
static ptrdiff_t
@@ -935,16 +926,13 @@ position_indentation (ptrdiff_t pos_byte)
bool
indented_beyond_p (ptrdiff_t pos, ptrdiff_t pos_byte, EMACS_INT column)
{
- ptrdiff_t val;
- ptrdiff_t opoint = PT, opoint_byte = PT_BYTE;
-
- SET_PT_BOTH (pos, pos_byte);
- while (PT > BEGV && FETCH_BYTE (PT_BYTE) == '\n')
- scan_newline (PT - 1, PT_BYTE - 1, BEGV, BEGV_BYTE, -1, 0);
-
- val = position_indentation (PT_BYTE);
- SET_PT_BOTH (opoint, opoint_byte);
- return val >= column;
+ while (pos > BEGV && FETCH_BYTE (pos_byte) == '\n')
+ {
+ DEC_BOTH (pos, pos_byte);
+ pos = find_newline (pos, pos_byte, BEGV, BEGV_BYTE,
+ -1, NULL, &pos_byte, 0);
+ }
+ return position_indentation (pos_byte) >= column;
}
DEFUN ("move-to-column", Fmove_to_column, Smove_to_column, 1, 2,