emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111976: * search.c (find_newline): A


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111976: * search.c (find_newline): Accept start and end byte positions
Date: Fri, 08 Mar 2013 13:34:35 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111976
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Fri 2013-03-08 13:34:35 +0400
message:
  * 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.
modified:
  src/ChangeLog
  src/bidi.c
  src/editfns.c
  src/indent.c
  src/lisp.h
  src/search.c
  src/xdisp.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-03-08 02:32:21 +0000
+++ b/src/ChangeLog     2013-03-08 09:34:35 +0000
@@ -1,3 +1,20 @@
+2013-03-08  Dmitry Antipov  <address@hidden>
+
+       * 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  <address@hidden>
 
        print.c, process.c: Use bool for booleans.

=== modified file 'src/bidi.c'
--- a/src/bidi.c        2013-03-07 23:37:36 +0000
+++ b/src/bidi.c        2013-03-08 09:34:35 +0000
@@ -1104,11 +1104,14 @@
   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;

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2013-03-07 03:01:17 +0000
+++ b/src/editfns.c     2013-03-08 09:34:35 +0000
@@ -669,7 +669,8 @@
 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 @@
              /* 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.  */

=== modified file 'src/indent.c'
--- a/src/indent.c      2013-03-07 04:42:59 +0000
+++ b/src/indent.c      2013-03-08 09:34:35 +0000
@@ -1840,10 +1840,13 @@
 
       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 @@
                                                       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 @@
       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 @@
                                                   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),

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2013-03-08 02:32:21 +0000
+++ b/src/lisp.h        2013-03-08 09:34:35 +0000
@@ -3364,11 +3364,12 @@
 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);

=== modified file 'src/search.c'
--- a/src/search.c      2013-03-06 16:35:23 +0000
+++ b/src/search.c      2013-03-08 09:34:35 +0000
@@ -621,7 +621,7 @@
 }
 
 
-/* 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 @@
    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 @@
                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 @@
                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 @@
 /* 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 @@
                          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)
     {

=== modified file 'src/xdisp.c'
--- a/src/xdisp.c       2013-03-07 23:37:36 +0000
+++ b/src/xdisp.c       2013-03-08 09:34:35 +0000
@@ -5905,8 +5905,10 @@
 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 @@
   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 @@
       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 @@
          && 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);
     }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]