Dnia 2014-08-16, o godz. 15:47:58
Marcin Borkowski <mb...@wmi.amu.edu.pl> napisaƂ(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,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University

Reply via email to