]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid unwanted point motion in Fline_beginning_position.
authorDmitry Antipov <dmantipov@yandex.ru>
Wed, 15 Oct 2014 13:37:10 +0000 (17:37 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Wed, 15 Oct 2014 13:37:10 +0000 (17:37 +0400)
* lisp.h (scan_newline_from_point): Add prototype.
* search.c (scan_newline_from_point): New function, refactored from...
* cmds.c (Fforward_line): ...adjusted user.
* editfns.c (Fline_beginning_position): Use scan_newline_from_point
and simplify the former since the latter doesn't move point.

src/ChangeLog
src/cmds.c
src/editfns.c
src/lisp.h
src/search.c

index c1b7c6cc8c3680669001dd0687e3aa01a5308e77..6823f6d3127387a56b1aa0391b30781112cb09eb 100644 (file)
@@ -1,3 +1,12 @@
+2014-10-15  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       Avoid unwanted point motion in Fline_beginning_position.
+       * lisp.h (scan_newline_from_point): Add prototype.
+       * search.c (scan_newline_from_point): New function, refactored from...
+       * cmds.c (Fforward_line): ...adjusted user.
+       * editfns.c (Fline_beginning_position): Use scan_newline_from_point
+       and simplify the former since the latter doesn't move point.
+
 2014-10-14  Dmitry Antipov  <dmantipov@yandex.ru>
 
        Cleanup terminal handling code.
index 20234638778ab22a6f722fc7efca2a27fcd193a7..9a05218b77bec16cf2e53588f5054188cdbabbea 100644 (file)
@@ -131,12 +131,7 @@ successfully moved (for the return value).  */)
       count = XINT (n);
     }
 
-  if (count <= 0)
-    pos = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1,
-                       &shortage, &pos_byte, 1);
-  else
-    pos = find_newline (PT, PT_BYTE, ZV, ZV_BYTE, count,
-                       &shortage, &pos_byte, 1);
+  shortage = scan_newline_from_point (count, &pos, &pos_byte);
 
   SET_PT_BOTH (pos, pos_byte);
 
index be1062dbbc55ac8699be3afd90692d20b7032dcc..376d8e3a0eae779e84a12143bea43468dcac5bb0 100644 (file)
@@ -787,26 +787,17 @@ boundaries, bind `inhibit-field-text-motion' to t.
 This function does not move point.  */)
   (Lisp_Object n)
 {
-  ptrdiff_t orig, orig_byte, end;
-  ptrdiff_t count = SPECPDL_INDEX ();
-  specbind (Qinhibit_point_motion_hooks, Qt);
+  ptrdiff_t charpos, bytepos;
 
   if (NILP (n))
     XSETFASTINT (n, 1);
   else
     CHECK_NUMBER (n);
 
-  orig = PT;
-  orig_byte = PT_BYTE;
-  Fforward_line (make_number (XINT (n) - 1));
-  end = PT;
-
-  SET_PT_BOTH (orig, orig_byte);
-
-  unbind_to (count, Qnil);
+  scan_newline_from_point (XINT (n) - 1, &charpos, &bytepos);
 
   /* Return END constrained to the current input field.  */
-  return Fconstrain_to_field (make_number (end), make_number (orig),
+  return Fconstrain_to_field (make_number (charpos), make_number (PT),
                              XINT (n) != 1 ? Qt : Qnil,
                              Qt, Qnil);
 }
index 89f29ea268b6c68492200b7af716f2dc72935661..d8809fd10d7fb64ce00ceb063c6cf6b76cb8d967 100644 (file)
@@ -4066,6 +4066,7 @@ extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
                               ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
 extern ptrdiff_t scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
                               ptrdiff_t, bool);
+extern ptrdiff_t scan_newline_from_point (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,
index 9eed390244fc47ab2309d0002b03d885a85c8128..c6ae9d7e9228f818a4fdafc79b3fdb8dc51225bc 100644 (file)
@@ -985,6 +985,24 @@ scan_newline (ptrdiff_t start, ptrdiff_t start_byte,
   return shortage;
 }
 
+/* Like above, but always scan from point and report the
+   resulting position in *CHARPOS and *BYTEPOS.  */
+
+ptrdiff_t
+scan_newline_from_point (ptrdiff_t count, ptrdiff_t *charpos,
+                        ptrdiff_t *bytepos)
+{
+  ptrdiff_t shortage;
+
+  if (count <= 0)
+    *charpos = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1,
+                            &shortage, bytepos, 1);
+  else
+    *charpos = find_newline (PT, PT_BYTE, ZV, ZV_BYTE, count,
+                            &shortage, bytepos, 1);
+  return shortage;
+}
+
 /* Like find_newline, but doesn't allow QUITting and doesn't return
    SHORTAGE.  */
 ptrdiff_t