emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Bug: Reading currently clocked headline interferes with org-capt


From: Nicolas Goaziou
Subject: Re: [O] Bug: Reading currently clocked headline interferes with org-capture-finalize [8.3.4 (8.3.4-93-g0d72c3-elpaplus @ /home/joe/.emacs.d/elpa/org-20160627/)]
Date: Sat, 30 Jul 2016 22:34:40 +0200

Hello,

Joe Schafer <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]