3

I use org-mode to keep track of time on tasks and also use org-capture to switch to new tasks that interrupt my current task. Is it possible to do something similar, to switch to an already existing task that I have in my org file? In other words, I would like to quickly switch to a task which I already have in an org-file, and once I have finished it, it should automatically take me back to the task which I was on before the switch.

Right now I go through a manual clock in/clock out to switch tasks 2 different times. Using a functionality similar to org-capture would allow me to just clock in to my new task and a clock out should automatically clock in to my previously running task. Google and stackoverflow searches did not point to a solution for this exact scenario.

1 Answer 1

3

I have not used org clocks much, but there is a clock history maintained that may be useful for your work flow. Various clock commands allow you to select recently clocked items when called with a prefix argument C-u.

For example:

  • org-clock-in and org-clock-in-last: With a prefix argument these provide a list of recent tasks to clock in or resume. C-u C-c C-x C-i

  • If you just want to find recently clocked tasks, use org-clock-goto with a prefix to get the same clock history selection: C-u C-c C-x C-j

You can configure Emacs to persist your clock history across sessions, as described here in the manual:

 (setq org-clock-persist 'history)
 (org-clock-persistence-insinuate)

You can also write some custom code to streamline things a bit. In addition to the clock history, org keeps a marker for the active task that gets interrupted when you clock in to a new task. So you can write a command to resume the interrupted task such as:

(defun my-org-clock-in-resume ()
  "Clock in to the last interrupted task, if any."
  (interactive)
  (when (marker-buffer org-clock-interrupted-task)
    (org-with-point-at org-clock-interrupted-task
      (org-clock-in))))

Then you can also bind a command to clock out of the current task and resume the previous interrupted task:

(defun my-org-clock-out-and-resume-previous ()
  "Clock out of the current task, then resume the interrupted task (if any)"
  (interactive)
  (org-clock-out)
  (my-org-clock-in-resume))
3
  • Thank you. That helps out a little. I made a keybinding to the org-clock-in with a C-u argument ('(4)) to avoid having to press 4 key combinations in sequence.
    – jorobins
    Jan 12, 2018 at 20:46
  • I've added some custom commands that might help for the specific work flow of interrupting a task to do something else and then going back to the original task.
    – glucas
    Jan 12, 2018 at 21:11
  • Thank you so much @glucas for the custom code. That sheds light on the org-clock-interrupted-task that seems perfect for this very scenario.
    – jorobins
    Jan 15, 2018 at 16:17

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.