emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Joe Schafer <joesmoe10@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: 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	[thread overview]
Message-ID: <87shuqdfvj.fsf@saiph.selenimh> (raw)
In-Reply-To: <CAOGO9CquBXF4be=N5vRhSi27WwW-FaVuTGvXZB-uyARsVtr01g@mail.gmail.com> (Joe Schafer's message of "Fri, 29 Jul 2016 01:03:31 -0700")

Hello,

Joe Schafer <joesmoe10@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

  parent reply	other threads:[~2016-07-30 20:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-29  8:03 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/)] Joe Schafer
2016-07-29 15:46 ` Adam Porter
2016-07-30 19:45   ` Nicolas Goaziou
2016-07-30 19:55     ` Adam Porter
2016-07-30 20:34 ` Nicolas Goaziou [this message]
2016-07-31 17:51 ` Joe Schafer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87shuqdfvj.fsf@saiph.selenimh \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=joesmoe10@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).