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.

  • 1
    Yes, using save-excursion and motion (go there and get point) 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

This can be done using save-excursion, then moving the cursor.

(defun point-calc-lines-offset (pt lines)
    (goto-char pt)
    (forward-line lines)
  • Turns our this is how to do it, thanks @Drew. – ideasman42 Jul 21 '19 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.