From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcin Borkowski Subject: Re: Clocking in on non-org files Date: Sat, 16 Aug 2014 16:37:27 +0200 Message-ID: <20140816163727.06c6dc1b@aga-netbook> References: <20131006140745.1a38e497@aga-netbook> <20131006151125.GG2622@kuru.dyndns-at-home.com> <20131006232625.2f42aa85@aga-netbook> <20140816141248.524ea25c@aga-netbook> <20140816143117.2c442296@aga-netbook> <20140816154758.7ec02caa@aga-netbook> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIf6v-0007vS-4F for emacs-orgmode@gnu.org; Sat, 16 Aug 2014 10:37:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIf6p-0002EF-1s for emacs-orgmode@gnu.org; Sat, 16 Aug 2014 10:37:37 -0400 Received: from msg.wmi.amu.edu.pl ([150.254.78.50]:53730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIf6o-0002E9-R9 for emacs-orgmode@gnu.org; Sat, 16 Aug 2014 10:37:30 -0400 Received: from localhost (localhost [127.0.0.1]) by msg.wmi.amu.edu.pl (Postfix) with ESMTP id 26D9777B8C for ; Sat, 16 Aug 2014 16:37:29 +0200 (CEST) Received: from msg.wmi.amu.edu.pl ([127.0.0.1]) by localhost (msg.wmi.amu.edu.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sXohvmgnKOYo for ; Sat, 16 Aug 2014 16:37:29 +0200 (CEST) Received: from aga-netbook (unknown [185.13.171.31]) by msg.wmi.amu.edu.pl (Postfix) with ESMTPSA id F0AD377B8A for ; Sat, 16 Aug 2014 16:37:28 +0200 (CEST) In-Reply-To: <20140816154758.7ec02caa@aga-netbook> 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Dnia 2014-08-16, o godz. 15:47:58 Marcin Borkowski napisa=C5=82(a): > OK, sorry for spamming the list, but here's what I established (with > the help of Edebug). The problem is with org-heading-components; for > some reason, the variable org-complex-heading-regexp is nil when > running that function. This variable is buffer-local, and it seems > that (somehow) the value org-clock-in sees is nil. A further > inspection shows that the (current-buffer) is (at that time) *not* the > one jumped to by org-open-at-point-global. Anyone knows why that is > so? Got it. Here's an excerpt from the Elisp manual: "When an editing command returns to the editor command loop, Emacs automatically calls `set-buffer' on the buffer shown in the selected window." In other words, I guess that org-open-at-point-global (and I assume that also org-open-link-from-string) change the /selected window/ and rely on Emacs command loop to make the respective buffer /the current buffer/ after they exit. Is this a good behavior? I guess not - it makes using them non-interactively harder. (I was only able to find that bug because of a recent, unrelated thread - also started by me;) - on the Emacs mailing list!) So let me file a feature request for such functions to actually set the current buffer. And here's the corrected code, which seems to work: (defun org-clock-in-anywhere (&optional select) "Clock in. If called without prefix and not in Org-mode, clock in the entry pointed by org-default-link." (interactive "P") (if (or select (equal major-mode 'org-mode)) (org-clock-in select) (save-window-excursion (save-selected-window (org-goto-default-link) (set-buffer (window-buffer (selected-window))) (org-clock-in))))) Best, --=20 Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Adam Mickiewicz University