3

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 at 16:50
5

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))
  • Turns our this is how to do it, thanks @Drew. – ideasman42 Jul 21 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.