From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou 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 Message-ID: <87shuqdfvj.fsf@saiph.selenimh> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTay5-0000ba-0u for emacs-orgmode@gnu.org; Sat, 30 Jul 2016 16:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTay3-000769-0n for emacs-orgmode@gnu.org; Sat, 30 Jul 2016 16:34:43 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:35590) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTay2-00075x-RE for emacs-orgmode@gnu.org; Sat, 30 Jul 2016 16:34:42 -0400 In-Reply-To: (Joe Schafer's message of "Fri, 29 Jul 2016 01:03:31 -0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Joe Schafer Cc: emacs-orgmode@gnu.org Hello, Joe Schafer 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