Commit 0b4d6d30 authored by Dmitry Antipov's avatar Dmitry Antipov

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.
parent 73d4c39e
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,
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment