In org-mode, C-c C-x C-j
executes org-clock-goto
, jumping the cursor to the currently active or most recently used clock.
After using this, I almost always want to go back to the point where I was, often another buffer. I would expect running org-clock-goto
a second time would get me there, toggling back to where I started. But unfortunately, that doesn't work. org-clock-goto
does only what the name says.
In search of a solution, I came up with a pair of simple elisp functions:
(defun my/org-clock-goto ()
(interactive)
(bookmark-set "before goto clock")
(org-clock-goto))
(defun my/org-clock-return ()
(interactive)
(bookmark-jump "before goto clock"))
This only works if I am starting off in a buffer which is a file (not *scratch*
for instance). But more importantly, what I really want is a single function bound to C-c C-x C-j
that will let me jump between the original point and the last clock.
Any hints?
(defadvice org-clock-goto (around bp/org-clock-goto--around) "Push mark to global-mark-ring for navigation purposes." (if (eq last-command 'org-clock-goto) (pop-global-mark) (push-mark (point)) ad-do-it)) (ad-activate 'org-clock-goto)
Pushes a mark to thegobal-mark-ring
when usingorg-clock-goto
. Usingorg-clock-goto
immediately afterwards will jump back to the starting position. When not just jumping back and forth, usepop-global-mark
(C-x C-SPC) to go back.org-clock-goto
should(push-mark (point))
first before going there. But otherwise (which is to say, if the mark is already at the active or most recent clock) thenorg-clock-goto
should(pop-global-mark)
. If you can incorporate those conditions into this defadvice, then I expect it will work very nicely.