I use AucTeX to edit LaTeX files and a PDF viewer that supports inverse search using SyncTeX. When I click on a location in the PDF, it simply calls emacsclient with the corresponding file and line. Often I want to make a quick change and jump back to where I was before. Unfortunately, point is not pushed to the mark ring, so I have to navigate back manually.

Is there any way to have emacsclient set the mark before jumping in an already opened file?

1 Answer 1


To give a possible answer to my own question (hope that's ok), here's a solution I just came up with by looking through server.el. It's possible to advise the function that does the jumping:

(defun server-goto-line-column@push-mark (orig &rest args)
  (let ((p (save-excursion
             (apply orig args)
    (unless (eq p (point))
    (goto-char p)))
(advice-add 'server-goto-line-column :around
  • This is really a comment on ChrisR's answer, but I am unable to comment for reputation reasons. I found (using emacs 26.3 and auctex 12.1.2) that TeX-source-correlate-sync-source rather than server-goto-line-column is called when I do an inverse search. Also, I use evil, so I use evil-set-marker rather than push-mark. Here is the resulting code: ``` (defun TeX-source-correlate-sync-source@set-marker (orig &rest args) (let ((p (save-excursion (apply orig args) (point)))) (unless (eq p (point)) (evil-set-marker ?')) (goto-char p))) (advice-add 'TeX-source-correlate-sync-source :around #'
    – Joj Helfer
    Jan 21, 2020 at 2:25

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.