calling org-content from lisp not working

Viewed 36

When I call org-content from the active buffer I get the outline I want. However if I use it in a lisp function like this

(split-window-right (truncate (* W 0.75)))
    (if (get-buffer "inbox.org")
        (set-window-buffer nil "inbox.org")
      (progn
        (find-file "~/Documents/GTD/inbox.org")
        (text-scale-set -1)))
    (org-content)

The windows splits and the right buffer gets loaded but the org-content bit doesn't seem to do anything. Any ideas of what I do wrong ?

Thanks,

Jouke

1 Answers

Here is a reproducible example, open a new buffer named test.org and define the following function in the *scratch* buffer:

(defun test ()
  (let ((buffer (get-buffer "test.org")))
    (when buffer
      (set-window-buffer nil buffer)
      (message "%s" (current-buffer)))))

The message being outputted is *scratch*: only the buffer associated with the window was changed, but what Emacs considers the current buffer did not.

If instead you use switch-to-buffer, as follows, the message displays the selected buffer:

(defun test ()
  (let ((buffer (get-buffer "test.org")))
    (when buffer
      (switch-to-buffer buffer)
      (message "%s" (current-buffer)))))

Applying the same change to your code makes (org-content) happy.

Related