Hello, Joe Schafer <joesmo...@gmail.com> writes:
> I have a function to save the currently clocked item into a file so I > can display it in my terminal. The hook seems to interfere with > org-capture. If I capture something the following > happens: > > 1. org-capture dialog appears > 2. Fill-in capture. The capture is clocked-in. > 3. Finish capture with C-c C-c > 4. The capture is still clocked in. The clock should go back to the > previous clocked-in entry. > > Trying to bisect the issue was difficult. Sometimes the new capture would > clock-out, but the original entry would not clock back in. Other times > the clock would be left running in the new capture entry. [...] > For reference, here's the full code I'm using > > (defun my:org-get-clocked-in-headline () > "Get the headline of the currently clocked in headline. > If no headline is clocked in, then return an empty string." > (interactive) > (if (not (org-clocking-p)) > "" > (with-current-buffer (marker-buffer org-clock-marker) > (save-excursion > (save-restriction > (when (or (< org-clock-marker (point-min)) (> > org-clock-marker (point-max))) > (widen)) > (goto-char org-clock-marker) > (org-no-properties (org-get-heading 'no-tags 'no-todo))))))) > > (defvar my:org-clocked-in-file-path "/tmp/org-currently-clocked-in-task" > "Where to save the currently clocked in task for all to see.") > > (defun my:org-save-clocked-in-entry-to-file () > "Save currently clocked-in task to a file." > (let ((last-message (current-message)) > ;; Suppress echo area to see clock out information. Doesn't > seem to > ;; work, so we'll just re-display last-message. > (inhibit-message nil)) > (with-temp-buffer > (insert (my:org-get-clocked-in-headline)) AFAIU, the last expression fails because (my:org-get-clocked-in-headline) returns nil at empty headlines. This prevents the whole process from properly clocking out. I fixed it on master; `org-get-heading' now always returns a string. If you're using stable release, you may want to use (or (org-no-properties (org-get-heading 'no-tags 'no-todo)) "") in `my:org-get-clocked-in-headline' instead. Regards, -- Nicolas Goaziou