I have followed these instruction to create a stack of visited position across buffers:
(defvar jedi:goto-stack '())
(defun jedi:jump-to-definition ()
(interactive)
(add-to-list 'jedi:goto-stack
(list (buffer-name) (point)))
(jedi:goto-definition))
(defun jedi:jump-back ()
(interactive)
(let ((p (pop jedi:goto-stack)))
(if p (progn
(switch-to-buffer (nth 0 p))
(goto-char (nth 1 p))))))
This worked well in most case, except when you visited files with the same name under different directories.
Example, you have two files ~/a/test.py
and ~/b/test.py
. When you first visit ~/a/test.py
, the emacs buffer name will be test.py
. Now, I used jedi:jump-to-definition
function above to go to ~/b/test.py
.
As it intended to do, before switching to ~/b/test.py
, it push current buffer name and position to stack jedi:goto-stack
as (test.py (point))
.
But emacs saw two files have the same name, they uniquify them, make their buffer name to test.py<a>
and test.py<b>
. Now, I can't use jedi:jump-back
to go to previous buffer ~/a/test.py
, because the stack only contains (test.py (point))
.
Can I check when did emacs uniquify the buffer name, and push the new uniquify name to my stack instead of the old one?