8

I'm using org-mode's clocking functions to track the hours I spend on projects. Since my main org file is rather large and I scroll through it a lot, it would be great to have a visual cue of the task that's currently clocked in.

Ideally some marker (e.g. a red arrow) in the fringe would be nice, especially if it 'moves' to the parent header if the subheaders are collapsed. Alternatively a highlighted line would be an options (somewhat similar to hl-line-mode, but fixed to the current task (or its parent)). Unfortunately my (e)lisp skills are almost non existent, so I don't have much of a clue where to start. Going through the Emacs manual it looks like overlay-arrow-string and overlay-arrow-position are the variables I could use, and org-clock-in-hook and org-clock-out-hook from org-clock.el look like places where I could (un)set these variables.

I know you can easily jump to the current task with C-c C-x C-j, but a visual cue would be much appreciated.

1
  • 3
    It should appear in modeline.
    – Muihlinn
    Commented Mar 7, 2019 at 20:58

1 Answer 1

1

Here is a quick way to do it with a fringe arrow and org clock hooks, as you suggested.

(defun org-clock-flag-active-task ()
  "Identify the clocked-in task with a fringe arrow on its header
line."
  (save-excursion
    (org-clock-goto)
    (make-variable-buffer-local 'overlay-arrow-position)
    (setq overlay-arrow-position (make-marker))
    (set-marker overlay-arrow-position (point))))

(defun org-clock-unflag-active-task ()
  "Remove the fringe arrow from the most recent clocked task."
  (with-current-buffer
      (marker-buffer (car org-clock-history))
    (setq overlay-arrow-position nil)))

(add-hook 'org-clock-in-hook 'org-clock-flag-active-task)
(add-hook 'org-clock-out-hook 'org-clock-unflag-active-task)
1
  • Thanks! That looks really neat. Learning a bit of Elisp along the way :-). I've given it a try and it works. One thing that this solution does not have is that it doesn't show the marker when the Org tree is collapsed. But it sure is a nice start. I'll incorporate it into my .emacs!
    – ph0t0nix
    Commented May 1 at 13:51

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.