summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2013-03-08 13:34:35 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2013-03-08 13:34:35 +0400
commitb5426561089d39f18b42bed9dbfcb531f43ed562 (patch)
treeea345a9966321890c6abc989182429a5f76de121 /src
parentc3e2de4c1a98a45557008700c3e0a654ecdbe447 (diff)
downloademacs-b5426561089d39f18b42bed9dbfcb531f43ed562.tar.gz
* search.c (find_newline): Accept start and end byte positions
as arguments and allow -1 if not known. (find_newline_no_quit): Likewise for start position. * lisp.h (find_newline, find_newline_no_quit): Adjust prototype. * bidi.c (bidi_find_paragraph_start): Pass byte position to find_newline_no_quit, thus eliminating CHAR_TO_BYTE. * editfns.c (Fconstrain_to_field): Break long line. Adjust call to find_newline. * indent.c (vmotion): Adjust calls to find_newline_no_quit. Use DEC_BOTH to start next search from the previous buffer position, where appropriate. * xdisp.c (back_to_previous_line_start, forward_to_next_line_start) (get_visually_first_element, move_it_vertically_backward): Likewise. Obtain byte position from the display iterator, where appropriate.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog17
-rw-r--r--src/bidi.c13
-rw-r--r--src/editfns.c6
-rw-r--r--src/indent.c19
-rw-r--r--src/lisp.h7
-rw-r--r--src/search.c19
-rw-r--r--src/xdisp.c19
7 files changed, 69 insertions, 31 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index cadb7e11ce8..fe084b160c4 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,20 @@
+2013-03-08 Dmitry Antipov <dmantipov@yandex.ru>
+
+ * search.c (find_newline): Accept start and end byte positions
+ as arguments and allow -1 if not known.
+ (find_newline_no_quit): Likewise for start position.
+ * lisp.h (find_newline, find_newline_no_quit): Adjust prototype.
+ * bidi.c (bidi_find_paragraph_start): Pass byte position to
+ find_newline_no_quit, thus eliminating CHAR_TO_BYTE.
+ * editfns.c (Fconstrain_to_field): Break long line. Adjust
+ call to find_newline.
+ * indent.c (vmotion): Adjust calls to find_newline_no_quit.
+ Use DEC_BOTH to start next search from the previous buffer
+ position, where appropriate.
+ * xdisp.c (back_to_previous_line_start, forward_to_next_line_start)
+ (get_visually_first_element, move_it_vertically_backward): Likewise.
+ Obtain byte position from the display iterator, where appropriate.
+
2013-03-08 Paul Eggert <eggert@cs.ucla.edu>
print.c, process.c: Use bool for booleans.
diff --git a/src/bidi.c b/src/bidi.c
index 7d070462a85..c6bea62f67b 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -1104,11 +1104,14 @@ bidi_find_paragraph_start (ptrdiff_t pos, ptrdiff_t pos_byte)
while (pos_byte > BEGV_BYTE
&& n++ < MAX_PARAGRAPH_SEARCH
&& fast_looking_at (re, pos, pos_byte, limit, limit_byte, Qnil) < 0)
- /* FIXME: What if the paragraph beginning is covered by a
- display string? And what if a display string covering some
- of the text over which we scan back includes
- paragraph_start_re? */
- pos = find_newline_no_quit (pos - 1, -1, &pos_byte);
+ {
+ /* FIXME: What if the paragraph beginning is covered by a
+ display string? And what if a display string covering some
+ of the text over which we scan back includes
+ paragraph_start_re? */
+ DEC_BOTH (pos, pos_byte);
+ pos = find_newline_no_quit (pos, pos_byte, -1, &pos_byte);
+ }
if (n >= MAX_PARAGRAPH_SEARCH)
pos_byte = BEGV_BYTE;
return pos_byte;
diff --git a/src/editfns.c b/src/editfns.c
index e1813dc65a1..f34c574cae3 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -669,7 +669,8 @@ If the optional argument INHIBIT-CAPTURE-PROPERTY is non-nil, and OLD-POS has
a non-nil property of that name, then any field boundaries are ignored.
Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
- (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge, Lisp_Object only_in_line, Lisp_Object inhibit_capture_property)
+ (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge,
+ Lisp_Object only_in_line, Lisp_Object inhibit_capture_property)
{
/* If non-zero, then the original point, before re-positioning. */
ptrdiff_t orig_point = 0;
@@ -735,7 +736,8 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
/* This is the ONLY_IN_LINE case, check that NEW_POS and
FIELD_BOUND are on the same line by seeing whether
there's an intervening newline or not. */
- || (find_newline (XFASTINT (new_pos), XFASTINT (field_bound),
+ || (find_newline (XFASTINT (new_pos), -1,
+ XFASTINT (field_bound), -1,
fwd ? -1 : 1, &shortage, NULL, 1),
shortage != 0)))
/* Constrain NEW_POS to FIELD_BOUND. */
diff --git a/src/indent.c b/src/indent.c
index fd692f0b149..d1f95da6bcf 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -1840,10 +1840,13 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
while ((vpos > vtarget || first) && from > BEGV)
{
- ptrdiff_t bytepos;
+ ptrdiff_t bytepos = from_byte;
Lisp_Object propval;
- prevline = find_newline_no_quit (from - 1, -1, &bytepos);
+ prevline = from;
+ DEC_BOTH (prevline, bytepos);
+ prevline = find_newline_no_quit (prevline, bytepos, -1, &bytepos);
+
while (prevline > BEGV
&& ((selective > 0
&& indented_beyond_p (prevline, bytepos, selective))
@@ -1853,7 +1856,10 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
Qinvisible,
text_prop_object),
TEXT_PROP_MEANS_INVISIBLE (propval))))
- prevline = find_newline_no_quit (prevline - 1, -1, &bytepos);
+ {
+ DEC_BOTH (prevline, bytepos);
+ prevline = find_newline_no_quit (prevline, bytepos, -1, &bytepos);
+ }
pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from,
/* Don't care for VPOS... */
1 << (BITS_PER_SHORT - 1),
@@ -1890,7 +1896,7 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
ptrdiff_t bytepos;
Lisp_Object propval;
- prevline = find_newline_no_quit (from, -1, &bytepos);
+ prevline = find_newline_no_quit (from, from_byte, -1, &bytepos);
while (prevline > BEGV
&& ((selective > 0
&& indented_beyond_p (prevline, bytepos, selective))
@@ -1900,7 +1906,10 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
Qinvisible,
text_prop_object),
TEXT_PROP_MEANS_INVISIBLE (propval))))
- prevline = find_newline_no_quit (prevline - 1, -1, &bytepos);
+ {
+ DEC_BOTH (prevline, bytepos);
+ prevline = find_newline_no_quit (prevline, bytepos, -1, &bytepos);
+ }
pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from,
/* Don't care for VPOS... */
1 << (BITS_PER_SHORT - 1),
diff --git a/src/lisp.h b/src/lisp.h
index 6e10fc0f838..12906bfa33e 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3364,11 +3364,12 @@ extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
ptrdiff_t, ptrdiff_t, Lisp_Object);
-extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t,
- ptrdiff_t *, ptrdiff_t *, bool);
+extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
+ ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
EMACS_INT, bool);
-extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
+extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t,
+ ptrdiff_t, ptrdiff_t *);
extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t,
ptrdiff_t, ptrdiff_t *);
extern void syms_of_search (void);
diff --git a/src/search.c b/src/search.c
index 090965ead3b..8bcf556eeeb 100644
--- a/src/search.c
+++ b/src/search.c
@@ -621,7 +621,7 @@ newline_cache_on_off (struct buffer *buf)
}
-/* Search for COUNT newlines between START and END.
+/* Search for COUNT newlines between START/START_BYTE and END/END_BYTE.
If COUNT is positive, search forwards; END must be >= START.
If COUNT is negative, search backwards for the -COUNTth instance;
@@ -645,11 +645,11 @@ newline_cache_on_off (struct buffer *buf)
except when inside redisplay. */
ptrdiff_t
-find_newline (ptrdiff_t start, ptrdiff_t end, ptrdiff_t count,
- ptrdiff_t *shortage, ptrdiff_t *bytepos, bool allow_quit)
+find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end,
+ ptrdiff_t end_byte, ptrdiff_t count, ptrdiff_t *shortage,
+ ptrdiff_t *bytepos, bool allow_quit)
{
struct region_cache *newline_cache;
- ptrdiff_t start_byte = -1, end_byte = -1;
int direction;
if (count > 0)
@@ -706,7 +706,7 @@ find_newline (ptrdiff_t start, ptrdiff_t end, ptrdiff_t count,
next_change is the position of the next known region. */
ceiling_byte = min (CHAR_TO_BYTE (next_change) - 1, ceiling_byte);
}
- else
+ else if (start_byte == -1)
start_byte = CHAR_TO_BYTE (start);
/* The dumb loop can only scan text stored in contiguous
@@ -783,7 +783,7 @@ find_newline (ptrdiff_t start, ptrdiff_t end, ptrdiff_t count,
next_change is the position of the next known region. */
ceiling_byte = max (CHAR_TO_BYTE (next_change), ceiling_byte);
}
- else
+ else if (start_byte == -1)
start_byte = CHAR_TO_BYTE (start);
/* Stop scanning before the gap. */
@@ -944,9 +944,10 @@ scan_newline (ptrdiff_t start, ptrdiff_t start_byte,
/* Like find_newline, but doesn't allow QUITting and doesn't return
SHORTAGE. */
ptrdiff_t
-find_newline_no_quit (ptrdiff_t from, ptrdiff_t cnt, ptrdiff_t *bytepos)
+find_newline_no_quit (ptrdiff_t from, ptrdiff_t frombyte,
+ ptrdiff_t cnt, ptrdiff_t *bytepos)
{
- return find_newline (from, 0, cnt, NULL, bytepos, 0);
+ return find_newline (from, frombyte, 0, -1, cnt, NULL, bytepos, 0);
}
/* Like find_newline, but returns position before the newline, not
@@ -958,7 +959,7 @@ find_before_next_newline (ptrdiff_t from, ptrdiff_t to,
ptrdiff_t cnt, ptrdiff_t *bytepos)
{
ptrdiff_t shortage;
- ptrdiff_t pos = find_newline (from, to, cnt, &shortage, bytepos, 1);
+ ptrdiff_t pos = find_newline (from, -1, to, -1, cnt, &shortage, bytepos, 1);
if (shortage == 0)
{
diff --git a/src/xdisp.c b/src/xdisp.c
index 3838d237c91..c6e204702ce 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -5905,8 +5905,10 @@ pop_it (struct it *it)
static void
back_to_previous_line_start (struct it *it)
{
- IT_CHARPOS (*it) = find_newline_no_quit (IT_CHARPOS (*it) - 1, -1,
- &IT_BYTEPOS (*it));
+ ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
+
+ DEC_BOTH (cp, bp);
+ IT_CHARPOS (*it) = find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it));
}
@@ -5978,7 +5980,8 @@ forward_to_next_line_start (struct it *it, int *skipped_p,
if (!newline_found_p)
{
ptrdiff_t bytepos, start = IT_CHARPOS (*it);
- ptrdiff_t limit = find_newline_no_quit (start, 1, &bytepos);
+ ptrdiff_t limit = find_newline_no_quit (start, IT_BYTEPOS (*it),
+ 1, &bytepos);
Lisp_Object pos;
eassert (!STRINGP (it->string));
@@ -7432,7 +7435,8 @@ get_visually_first_element (struct it *it)
if (string_p)
it->bidi_it.charpos = it->bidi_it.bytepos = 0;
else
- it->bidi_it.charpos = find_newline_no_quit (IT_CHARPOS (*it), -1,
+ it->bidi_it.charpos = find_newline_no_quit (IT_CHARPOS (*it),
+ IT_BYTEPOS (*it), -1,
&it->bidi_it.bytepos);
bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, 1);
do
@@ -9067,10 +9071,11 @@ move_it_vertically_backward (struct it *it, int dy)
&& IT_CHARPOS (*it) > BEGV
&& FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n')
{
- ptrdiff_t nl_pos = find_newline_no_quit (IT_CHARPOS (*it) - 1, -1,
- NULL);
+ ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
- move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS);
+ DEC_BOTH (cp, bp);
+ cp = find_newline_no_quit (cp, bp, -1, NULL);
+ move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS);
}
bidi_unshelve_cache (it3data, 1);
}