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.
This commit is contained in:
parent
73d4c39e15
commit
0b4d6d30be
5 changed files with 32 additions and 18 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
18
src/search.c
18
src/search.c
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue