Say I was working in a big file somewhere in the middle and all of the sudden I realise that I need to edit the top of the file. I do a M-<
to go to the top and make my edits. Now I want to move back to the exact point where I was working before.
Is it possible to call a function before moving to the top, memorising the current point then going somewhere and calling the same function again but this time the cursor is moved to the point which was previously memorised and the memory is erased; ready to memorise a new point.
Edit: Here is what I ended up with,
(defconst POINT-REGISTER 0
"Register to save the current point in.")
(defcustom saved-point nil
"Whether a point is saved in `POINT-REGISTER`."
:type 'boolean)
(defun save-or-goto-saved-point ()
"Interactively memorise a point and return to it."
(interactive)
(if saved-point
(progn (register-to-point POINT-REGISTER)
(setq saved-point nil))
(progn (point-to-register POINT-REGISTER)
(message "[<Your Name>] Point saved!")
(setq saved-point t))))