aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2014-10-15 17:37:10 +0400
committerDmitry Antipov2014-10-15 17:37:10 +0400
commit0b4d6d30be2822df7d6b086bbab32b8ff419ed5d (patch)
treebb4d69129f2dc53af8736945bfdaf8bd22dbf966 /src
parent73d4c39e1519a5fec742686e3c81941113d41448 (diff)
downloademacs-0b4d6d30be2822df7d6b086bbab32b8ff419ed5d.tar.gz
emacs-0b4d6d30be2822df7d6b086bbab32b8ff419ed5d.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/cmds.c7
-rw-r--r--src/editfns.c15
-rw-r--r--src/lisp.h1
-rw-r--r--src/search.c18
5 files changed, 32 insertions, 18 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c1b7c6cc8c3..6823f6d3127 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12014-10-15 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Avoid unwanted point motion in Fline_beginning_position.
4 * lisp.h (scan_newline_from_point): Add prototype.
5 * search.c (scan_newline_from_point): New function, refactored from...
6 * cmds.c (Fforward_line): ...adjusted user.
7 * editfns.c (Fline_beginning_position): Use scan_newline_from_point
8 and simplify the former since the latter doesn't move point.
9
12014-10-14 Dmitry Antipov <dmantipov@yandex.ru> 102014-10-14 Dmitry Antipov <dmantipov@yandex.ru>
2 11
3 Cleanup terminal handling code. 12 Cleanup terminal handling code.
diff --git a/src/cmds.c b/src/cmds.c
index 20234638778..9a05218b77b 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -131,12 +131,7 @@ successfully moved (for the return value). */)
131 count = XINT (n); 131 count = XINT (n);
132 } 132 }
133 133
134 if (count <= 0) 134 shortage = scan_newline_from_point (count, &pos, &pos_byte);
135 pos = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1,
136 &shortage, &pos_byte, 1);
137 else
138 pos = find_newline (PT, PT_BYTE, ZV, ZV_BYTE, count,
139 &shortage, &pos_byte, 1);
140 135
141 SET_PT_BOTH (pos, pos_byte); 136 SET_PT_BOTH (pos, pos_byte);
142 137
diff --git a/src/editfns.c b/src/editfns.c
index be1062dbbc5..376d8e3a0ea 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -787,26 +787,17 @@ boundaries, bind `inhibit-field-text-motion' to t.
787This function does not move point. */) 787This function does not move point. */)
788 (Lisp_Object n) 788 (Lisp_Object n)
789{ 789{
790 ptrdiff_t orig, orig_byte, end; 790 ptrdiff_t charpos, bytepos;
791 ptrdiff_t count = SPECPDL_INDEX ();
792 specbind (Qinhibit_point_motion_hooks, Qt);
793 791
794 if (NILP (n)) 792 if (NILP (n))
795 XSETFASTINT (n, 1); 793 XSETFASTINT (n, 1);
796 else 794 else
797 CHECK_NUMBER (n); 795 CHECK_NUMBER (n);
798 796
799 orig = PT; 797 scan_newline_from_point (XINT (n) - 1, &charpos, &bytepos);
800 orig_byte = PT_BYTE;
801 Fforward_line (make_number (XINT (n) - 1));
802 end = PT;
803
804 SET_PT_BOTH (orig, orig_byte);
805
806 unbind_to (count, Qnil);
807 798
808 /* Return END constrained to the current input field. */ 799 /* Return END constrained to the current input field. */
809 return Fconstrain_to_field (make_number (end), make_number (orig), 800 return Fconstrain_to_field (make_number (charpos), make_number (PT),
810 XINT (n) != 1 ? Qt : Qnil, 801 XINT (n) != 1 ? Qt : Qnil,
811 Qt, Qnil); 802 Qt, Qnil);
812} 803}
diff --git a/src/lisp.h b/src/lisp.h
index 89f29ea268b..d8809fd10d7 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4066,6 +4066,7 @@ extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
4066 ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool); 4066 ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
4067extern ptrdiff_t scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, 4067extern ptrdiff_t scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
4068 ptrdiff_t, bool); 4068 ptrdiff_t, bool);
4069extern ptrdiff_t scan_newline_from_point (ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
4069extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t, 4070extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t,
4070 ptrdiff_t, ptrdiff_t *); 4071 ptrdiff_t, ptrdiff_t *);
4071extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t, 4072extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t,
diff --git a/src/search.c b/src/search.c
index 9eed390244f..c6ae9d7e922 100644
--- a/src/search.c
+++ b/src/search.c
@@ -985,6 +985,24 @@ scan_newline (ptrdiff_t start, ptrdiff_t start_byte,
985 return shortage; 985 return shortage;
986} 986}
987 987
988/* Like above, but always scan from point and report the
989 resulting position in *CHARPOS and *BYTEPOS. */
990
991ptrdiff_t
992scan_newline_from_point (ptrdiff_t count, ptrdiff_t *charpos,
993 ptrdiff_t *bytepos)
994{
995 ptrdiff_t shortage;
996
997 if (count <= 0)
998 *charpos = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1,
999 &shortage, bytepos, 1);
1000 else
1001 *charpos = find_newline (PT, PT_BYTE, ZV, ZV_BYTE, count,
1002 &shortage, bytepos, 1);
1003 return shortage;
1004}
1005
988/* Like find_newline, but doesn't allow QUITting and doesn't return 1006/* Like find_newline, but doesn't allow QUITting and doesn't return
989 SHORTAGE. */ 1007 SHORTAGE. */
990ptrdiff_t 1008ptrdiff_t