1

I put the following in my .init file:

(defun ndk/org-refile-candidates ()
  (directory-files  "/home/rob/Dokumente/todo/" t ".*\\.org$"))

(add-to-list 'org-refile-targets '(ndk/org-refile-candidates :maxlevel . 3))

It does work when evaluating manually with C-x C-e, but not when I restart Emacs.

I get the error:

Symbol's value as variable is void: org-refile-targets To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the ‘--debug-init’ option to view a complete error backtrace.

Why isn't it setting the value of the variable like when I do it manually? Does it get overwritten by some default somehow? Can somebody point me into the right direction?

5

This is because no variable org-refile-targets has yet been defined when that code in your init file is being evaluated.

(Obviously you've loaded the relevant library by the time you attempt this manually.)

It looks like org-refile is the library which defines this, so you can either forcibly load that before using the variable:

(require 'org-refile)
(add-to-list 'org-refile-targets '(ndk/org-refile-candidates :maxlevel . 3))

But I can see that's going to load much of org in turn, which is a bit of a performance hit at start-up, so I suggest this instead:

(with-eval-after-load 'org-refile
  (add-to-list 'org-refile-targets '(ndk/org-refile-candidates :maxlevel . 3)))
1
  • thank you, sir phils! that was very helpful :) – Robert Synofzik May 11 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.