3

Q:  How can I delete a marker after it has been created?

I see how to create markers and how to move markers, but I see nothing in the manual about how to delete them:

lawlist
  • 18,826
  • 5
  • 37
  • 118

1 Answers1

3

Markers that point nowhere are garbage-collected. From the Elisp manual, node Overview of Markers:

Insertion and deletion in a buffer must check all the markers and relocate them if necessary. This slows processing in a buffer with a large number of markers. For this reason, it is a good idea to make a marker point nowhere if you are sure you don’t need it any more. Markers that can no longer be accessed are eventually removed (*note Garbage Collection::).

To make a marker point nowhere, use set-marker to set it to nil:

(set-marker my-marker nil)

Is that not enough for you? Can you explain why you want to explicitly (i.e., immediately) delete a marker?

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Not original questioner but creating markers in a function calls into unknown code which could raise an error, I need to know if I should use `unwind-protect` and set-marker to nil in case of failure. – ideasman42 Oct 28 '21 at 00:25
  • Sorry; I don't understand what you're looking for / asking. The question, not comments, is the place to clarify it. You might want to pose a separate question, showing some code or specifying the context more clearly etc. – Drew Oct 28 '21 at 04:29
  • I had the same question as the questioner, the "why" may be the same - they don't state why. I just mention if markers are created in code that might later error... this seems like a case where the script author may want to clean up - although that can be a question on it's own since I'm not sure of what's the best practice in this case. – ideasman42 Oct 28 '21 at 05:55
  • Asked a related question https://emacs.stackexchange.com/questions/69117 – ideasman42 Oct 28 '21 at 06:24