* search.c (find_newline): Accept start and end byte positions
[bpt/emacs.git] / src / xdisp.c
index 3838d23..c6e2047 100644 (file)
@@ -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);
     }