3

I have some insert functions that take some time (e.g., doing network IO). I like to store the current point position, and then insert the text at the stored point.

This should be robust to some small edits. I think bookmarks.el already has such a 'fuzzy' point storing machinery, but I am not sure if it's the best way to do this (or how to use bookmarks.el's presumably private API).

1
  • 2
    See "Markers" in the Emacs Lisp manual. Do C-h ig(elisp)Markers.
    – NickD
    Commented Oct 3, 2021 at 10:30

1 Answer 1

3

From your description, you don't want to return to a particular buffer position. You want to return to a particular text position, that is, a position in context, a position relative to the text surrounding the original position.

As @NickD suggested in a comment, what you want to do is to create and store a marker at the original location. Markers move along with the surrounding text.

(let ((opt  (point-marker)))
  ;; DO STUFF
  (goto-char opt))

Read about markers in the Elisp manual, node Markers.

2
  • (point-marker). (make-marker) doesn't accept arguments and creates an empty marker.
    – HappyFace
    Commented Oct 9, 2021 at 10:17
  • @HappyFace: Oops! Duh, 100% right. Thx - fixed.
    – Drew
    Commented Oct 9, 2021 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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