There seem to be a lot of situations, where a command changes the cursor location (point), but no mark is pushed, making navigating back by popping the mark with C-u SPC impossible.

For isolated use-cases, I can fix this with e.g. advice-add on the affected command, or other ad-hoc fixes (see e.g. Set mark when jumping from emacsclient). I have however found, that it affects just too many situations to manually track down where to put the advice, and maintain that advice as the functions change -- quite often the suitable function is a package-private function like xref--show-pos-in-buf.

Examples, where this makes issues, include:

  • M-x xref-... commands[1]
  • M-x occur
  • M-x grep
  • Latex forward/inverse search
  • ...

Is there some better, cleaner way to achieve more comprehensive "mark-pushing"?

Workflow and Workarounds

Given a setup

|              |                   |
| FileBuffer   |  NavigationBuffer |
| FileWindow   |  NavigationWindow |
|              |                   |
|              |                   |

Where NavigationBuffer is associated e.g. with the xref, diff, find-grep, or occur feature, I may either:

  1. Switch to NavigationWindow with a keyboard command, and activate a command, that causes the point in FileBuffer to change, or
  2. Click somewhere in NavigationWindow to the same effect.

Case (2) can be covered the same way for left-click and right-click events. Many modes however default to reacting only to middle-button clicks; In this case, selected-window and current-buffer remain the same before and after the command.

While I can probably find a workaround for the middle-click case, the solution seems like a messy workaround at this point; A cleaner solution would be preferable.


[1] RichieHH's Answer: In this case, there is M-, aka xref-pop-marker-stack, but setting the mark would still be nice for consistency.

  • 1
    Can you specify (verbally or by code) the situations where you want the mark set? Clearly you don't want to set it by hand - that's one extreme (which most of us prefer, I think). And (clearly?) you don't want it set for every command that moves point. So something in between - but what, exactly? The question seems vague, so far.
    – Drew
    Commented Feb 5, 2020 at 15:32
  • My strategy is using a point history ring where large point motions are automatically stored. See pointhistory.el.
    – Tobias
    Commented Feb 5, 2020 at 17:06
  • 1
    There is also github.com/boyw165/history, it's the best solution for this that I've tried so far.
    – Dmitry
    Commented Feb 6, 2020 at 8:15
  • @Drew Essentially I want to push the mark, whenever navigation in one buffer is triggered by interactive features of another buffer. Phrasing it like that, find these three events: (a) I switch to another buffer, usually in another window, (b) I perform a left-click on another window, or (c) I perform a middle-click in another window.
    – kdb
    Commented Feb 6, 2020 at 8:47
  • Please put such info into the question itself. Comments can be deleted at any time. Questions should stand on their own. Thx.
    – Drew
    Commented Feb 6, 2020 at 16:02

1 Answer 1


Certaily with xref, Use revert: M-, is the default.


M-, (translated from <escape> ,) runs the command xref-pop-marker-stack (found in global-map), which is an interactive compiled Lisp function in xref.el.

It is bound to M-,, <menu-bar> <edit> <goto> <xref-pop>.


Probably introduced at or before Emacs version 25.1.

Pop back to where M-. was last invoked.

  • 2
    Thanks for pointing that out! I think I even knew the solution for xref before but forgot again; Which is part of why I want consistent behavior across the various use-cases...
    – kdb
    Commented Feb 5, 2020 at 14:05

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.