aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2013-03-08 13:34:35 +0400
committerDmitry Antipov2013-03-08 13:34:35 +0400
commitb5426561089d39f18b42bed9dbfcb531f43ed562 (patch)
treeea345a9966321890c6abc989182429a5f76de121 /src
parentc3e2de4c1a98a45557008700c3e0a654ecdbe447 (diff)
downloademacs-b5426561089d39f18b42bed9dbfcb531f43ed562.tar.gz
emacs-b5426561089d39f18b42bed9dbfcb531f43ed562.zip
* 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 @@
12013-03-08 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * search.c (find_newline): Accept start and end byte positions
4 as arguments and allow -1 if not known.
5 (find_newline_no_quit): Likewise for start position.
6 * lisp.h (find_newline, find_newline_no_quit): Adjust prototype.
7 * bidi.c (bidi_find_paragraph_start): Pass byte position to
8 find_newline_no_quit, thus eliminating CHAR_TO_BYTE.
9 * editfns.c (Fconstrain_to_field): Break long line. Adjust
10 call to find_newline.
11 * indent.c (vmotion): Adjust calls to find_newline_no_quit.
12 Use DEC_BOTH to start next search from the previous buffer
13 position, where appropriate.
14 * xdisp.c (back_to_previous_line_start, forward_to_next_line_start)
15 (get_visually_first_element, move_it_vertically_backward): Likewise.
16 Obtain byte position from the display iterator, where appropriate.
17
12013-03-08 Paul Eggert <eggert@cs.ucla.edu> 182013-03-08 Paul Eggert <eggert@cs.ucla.edu>
2 19
3 print.c, process.c: Use bool for booleans. 20 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)
1104 while (pos_byte > BEGV_BYTE 1104 while (pos_byte > BEGV_BYTE
1105 && n++ < MAX_PARAGRAPH_SEARCH 1105 && n++ < MAX_PARAGRAPH_SEARCH
1106 && fast_looking_at (re, pos, pos_byte, limit, limit_byte, Qnil) < 0) 1106 && fast_looking_at (re, pos, pos_byte, limit, limit_byte, Qnil) < 0)
1107 /* FIXME: What if the paragraph beginning is covered by a 1107 {
1108 display string? And what if a display string covering some 1108 /* FIXME: What if the paragraph beginning is covered by a
1109 of the text over which we scan back includes 1109 display string? And what if a display string covering some
1110 paragraph_start_re? */ 1110 of the text over which we scan back includes
1111 pos = find_newline_no_quit (pos - 1, -1, &pos_byte); 1111 paragraph_start_re? */
1112 DEC_BOTH (pos, pos_byte);
1113 pos = find_newline_no_quit (pos, pos_byte, -1, &pos_byte);
1114 }
1112 if (n >= MAX_PARAGRAPH_SEARCH) 1115 if (n >= MAX_PARAGRAPH_SEARCH)
1113 pos_byte = BEGV_BYTE; 1116 pos_byte = BEGV_BYTE;
1114 return pos_byte; 1117 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
669a non-nil property of that name, then any field boundaries are ignored. 669a non-nil property of that name, then any field boundaries are ignored.
670 670
671Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */) 671Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
672 (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge, Lisp_Object only_in_line, Lisp_Object inhibit_capture_property) 672 (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge,
673 Lisp_Object only_in_line, Lisp_Object inhibit_capture_property)
673{ 674{
674 /* If non-zero, then the original point, before re-positioning. */ 675 /* If non-zero, then the original point, before re-positioning. */
675 ptrdiff_t orig_point = 0; 676 ptrdiff_t orig_point = 0;
@@ -735,7 +736,8 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
735 /* This is the ONLY_IN_LINE case, check that NEW_POS and 736 /* This is the ONLY_IN_LINE case, check that NEW_POS and
736 FIELD_BOUND are on the same line by seeing whether 737 FIELD_BOUND are on the same line by seeing whether
737 there's an intervening newline or not. */ 738 there's an intervening newline or not. */
738 || (find_newline (XFASTINT (new_pos), XFASTINT (field_bound), 739 || (find_newline (XFASTINT (new_pos), -1,
740 XFASTINT (field_bound), -1,
739 fwd ? -1 : 1, &shortage, NULL, 1), 741 fwd ? -1 : 1, &shortage, NULL, 1),
740 shortage != 0))) 742 shortage != 0)))
741 /* Constrain NEW_POS to FIELD_BOUND. */ 743 /* 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,
1840 1840
1841 while ((vpos > vtarget || first) && from > BEGV) 1841 while ((vpos > vtarget || first) && from > BEGV)
1842 { 1842 {
1843 ptrdiff_t bytepos; 1843 ptrdiff_t bytepos = from_byte;
1844 Lisp_Object propval; 1844 Lisp_Object propval;
1845 1845
1846 prevline = find_newline_no_quit (from - 1, -1, &bytepos); 1846 prevline = from;
1847 DEC_BOTH (prevline, bytepos);
1848 prevline = find_newline_no_quit (prevline, bytepos, -1, &bytepos);
1849
1847 while (prevline > BEGV 1850 while (prevline > BEGV
1848 && ((selective > 0 1851 && ((selective > 0
1849 && indented_beyond_p (prevline, bytepos, selective)) 1852 && indented_beyond_p (prevline, bytepos, selective))
@@ -1853,7 +1856,10 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
1853 Qinvisible, 1856 Qinvisible,
1854 text_prop_object), 1857 text_prop_object),
1855 TEXT_PROP_MEANS_INVISIBLE (propval)))) 1858 TEXT_PROP_MEANS_INVISIBLE (propval))))
1856 prevline = find_newline_no_quit (prevline - 1, -1, &bytepos); 1859 {
1860 DEC_BOTH (prevline, bytepos);
1861 prevline = find_newline_no_quit (prevline, bytepos, -1, &bytepos);
1862 }
1857 pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from, 1863 pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from,
1858 /* Don't care for VPOS... */ 1864 /* Don't care for VPOS... */
1859 1 << (BITS_PER_SHORT - 1), 1865 1 << (BITS_PER_SHORT - 1),
@@ -1890,7 +1896,7 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
1890 ptrdiff_t bytepos; 1896 ptrdiff_t bytepos;
1891 Lisp_Object propval; 1897 Lisp_Object propval;
1892 1898
1893 prevline = find_newline_no_quit (from, -1, &bytepos); 1899 prevline = find_newline_no_quit (from, from_byte, -1, &bytepos);
1894 while (prevline > BEGV 1900 while (prevline > BEGV
1895 && ((selective > 0 1901 && ((selective > 0
1896 && indented_beyond_p (prevline, bytepos, selective)) 1902 && indented_beyond_p (prevline, bytepos, selective))
@@ -1900,7 +1906,10 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
1900 Qinvisible, 1906 Qinvisible,
1901 text_prop_object), 1907 text_prop_object),
1902 TEXT_PROP_MEANS_INVISIBLE (propval)))) 1908 TEXT_PROP_MEANS_INVISIBLE (propval))))
1903 prevline = find_newline_no_quit (prevline - 1, -1, &bytepos); 1909 {
1910 DEC_BOTH (prevline, bytepos);
1911 prevline = find_newline_no_quit (prevline, bytepos, -1, &bytepos);
1912 }
1904 pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from, 1913 pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from,
1905 /* Don't care for VPOS... */ 1914 /* Don't care for VPOS... */
1906 1 << (BITS_PER_SHORT - 1), 1915 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 *,
3364extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object); 3364extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
3365extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t, 3365extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
3366 ptrdiff_t, ptrdiff_t, Lisp_Object); 3366 ptrdiff_t, ptrdiff_t, Lisp_Object);
3367extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, 3367extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3368 ptrdiff_t *, ptrdiff_t *, bool); 3368 ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
3369extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, 3369extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3370 EMACS_INT, bool); 3370 EMACS_INT, bool);
3371extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t, ptrdiff_t *); 3371extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t,
3372 ptrdiff_t, ptrdiff_t *);
3372extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t, 3373extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t,
3373 ptrdiff_t, ptrdiff_t *); 3374 ptrdiff_t, ptrdiff_t *);
3374extern void syms_of_search (void); 3375extern 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)
621} 621}
622 622
623 623
624/* Search for COUNT newlines between START and END. 624/* Search for COUNT newlines between START/START_BYTE and END/END_BYTE.
625 625
626 If COUNT is positive, search forwards; END must be >= START. 626 If COUNT is positive, search forwards; END must be >= START.
627 If COUNT is negative, search backwards for the -COUNTth instance; 627 If COUNT is negative, search backwards for the -COUNTth instance;
@@ -645,11 +645,11 @@ newline_cache_on_off (struct buffer *buf)
645 except when inside redisplay. */ 645 except when inside redisplay. */
646 646
647ptrdiff_t 647ptrdiff_t
648find_newline (ptrdiff_t start, ptrdiff_t end, ptrdiff_t count, 648find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end,
649 ptrdiff_t *shortage, ptrdiff_t *bytepos, bool allow_quit) 649 ptrdiff_t end_byte, ptrdiff_t count, ptrdiff_t *shortage,
650 ptrdiff_t *bytepos, bool allow_quit)
650{ 651{
651 struct region_cache *newline_cache; 652 struct region_cache *newline_cache;
652 ptrdiff_t start_byte = -1, end_byte = -1;
653 int direction; 653 int direction;
654 654
655 if (count > 0) 655 if (count > 0)
@@ -706,7 +706,7 @@ find_newline (ptrdiff_t start, ptrdiff_t end, ptrdiff_t count,
706 next_change is the position of the next known region. */ 706 next_change is the position of the next known region. */
707 ceiling_byte = min (CHAR_TO_BYTE (next_change) - 1, ceiling_byte); 707 ceiling_byte = min (CHAR_TO_BYTE (next_change) - 1, ceiling_byte);
708 } 708 }
709 else 709 else if (start_byte == -1)
710 start_byte = CHAR_TO_BYTE (start); 710 start_byte = CHAR_TO_BYTE (start);
711 711
712 /* The dumb loop can only scan text stored in contiguous 712 /* 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,
783 next_change is the position of the next known region. */ 783 next_change is the position of the next known region. */
784 ceiling_byte = max (CHAR_TO_BYTE (next_change), ceiling_byte); 784 ceiling_byte = max (CHAR_TO_BYTE (next_change), ceiling_byte);
785 } 785 }
786 else 786 else if (start_byte == -1)
787 start_byte = CHAR_TO_BYTE (start); 787 start_byte = CHAR_TO_BYTE (start);
788 788
789 /* Stop scanning before the gap. */ 789 /* Stop scanning before the gap. */
@@ -944,9 +944,10 @@ scan_newline (ptrdiff_t start, ptrdiff_t start_byte,
944/* Like find_newline, but doesn't allow QUITting and doesn't return 944/* Like find_newline, but doesn't allow QUITting and doesn't return
945 SHORTAGE. */ 945 SHORTAGE. */
946ptrdiff_t 946ptrdiff_t
947find_newline_no_quit (ptrdiff_t from, ptrdiff_t cnt, ptrdiff_t *bytepos) 947find_newline_no_quit (ptrdiff_t from, ptrdiff_t frombyte,
948 ptrdiff_t cnt, ptrdiff_t *bytepos)
948{ 949{
949 return find_newline (from, 0, cnt, NULL, bytepos, 0); 950 return find_newline (from, frombyte, 0, -1, cnt, NULL, bytepos, 0);
950} 951}
951 952
952/* Like find_newline, but returns position before the newline, not 953/* Like find_newline, but returns position before the newline, not
@@ -958,7 +959,7 @@ find_before_next_newline (ptrdiff_t from, ptrdiff_t to,
958 ptrdiff_t cnt, ptrdiff_t *bytepos) 959 ptrdiff_t cnt, ptrdiff_t *bytepos)
959{ 960{
960 ptrdiff_t shortage; 961 ptrdiff_t shortage;
961 ptrdiff_t pos = find_newline (from, to, cnt, &shortage, bytepos, 1); 962 ptrdiff_t pos = find_newline (from, -1, to, -1, cnt, &shortage, bytepos, 1);
962 963
963 if (shortage == 0) 964 if (shortage == 0)
964 { 965 {
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)
5905static void 5905static void
5906back_to_previous_line_start (struct it *it) 5906back_to_previous_line_start (struct it *it)
5907{ 5907{
5908 IT_CHARPOS (*it) = find_newline_no_quit (IT_CHARPOS (*it) - 1, -1, 5908 ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
5909 &IT_BYTEPOS (*it)); 5909
5910 DEC_BOTH (cp, bp);
5911 IT_CHARPOS (*it) = find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it));
5910} 5912}
5911 5913
5912 5914
@@ -5978,7 +5980,8 @@ forward_to_next_line_start (struct it *it, int *skipped_p,
5978 if (!newline_found_p) 5980 if (!newline_found_p)
5979 { 5981 {
5980 ptrdiff_t bytepos, start = IT_CHARPOS (*it); 5982 ptrdiff_t bytepos, start = IT_CHARPOS (*it);
5981 ptrdiff_t limit = find_newline_no_quit (start, 1, &bytepos); 5983 ptrdiff_t limit = find_newline_no_quit (start, IT_BYTEPOS (*it),
5984 1, &bytepos);
5982 Lisp_Object pos; 5985 Lisp_Object pos;
5983 5986
5984 eassert (!STRINGP (it->string)); 5987 eassert (!STRINGP (it->string));
@@ -7432,7 +7435,8 @@ get_visually_first_element (struct it *it)
7432 if (string_p) 7435 if (string_p)
7433 it->bidi_it.charpos = it->bidi_it.bytepos = 0; 7436 it->bidi_it.charpos = it->bidi_it.bytepos = 0;
7434 else 7437 else
7435 it->bidi_it.charpos = find_newline_no_quit (IT_CHARPOS (*it), -1, 7438 it->bidi_it.charpos = find_newline_no_quit (IT_CHARPOS (*it),
7439 IT_BYTEPOS (*it), -1,
7436 &it->bidi_it.bytepos); 7440 &it->bidi_it.bytepos);
7437 bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, 1); 7441 bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, 1);
7438 do 7442 do
@@ -9067,10 +9071,11 @@ move_it_vertically_backward (struct it *it, int dy)
9067 && IT_CHARPOS (*it) > BEGV 9071 && IT_CHARPOS (*it) > BEGV
9068 && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n') 9072 && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n')
9069 { 9073 {
9070 ptrdiff_t nl_pos = find_newline_no_quit (IT_CHARPOS (*it) - 1, -1, 9074 ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
9071 NULL);
9072 9075
9073 move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS); 9076 DEC_BOTH (cp, bp);
9077 cp = find_newline_no_quit (cp, bp, -1, NULL);
9078 move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS);
9074 } 9079 }
9075 bidi_unshelve_cache (it3data, 1); 9080 bidi_unshelve_cache (it3data, 1);
9076 } 9081 }