Given a point, how can I get the point N lines before/after it?
Will post own answer, but I'm not sure it's optimal.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityGiven a point, how can I get the point N lines before/after it?
Will post own answer, but I'm not sure it's optimal.
This can be done using save-excursion
, then moving the cursor.
(defun point-calc-lines-offset (pt lines)
(save-excursion
(goto-char pt)
(forward-line lines)
(point))
save-excursion
and motion (go there and getpoint
) is what is used. Some motion functions are more efficient than others.forward-line
is efficient, for example. – Drew Jul 20 '19 at 16:50