I use org-refile quite a bit, but for my use-case, I want to refile my org-mode subtrees not to an org-agenda file, but to the current file or another file I'm currently visiting.

I had a way of doing this that was working correctly, but now has stopped working. I'm not sure what I changed that broke it.

Here's the code I'm using for org-refile:

(setq org-outline-path-complete-in-steps nil) ; Refile in a single go 
(setq org-completion-use-ido nil) 
(setq org-refile-use-outline-path t) ; Show full paths for refiling 
(setq org-refile-allow-creating-parent-nodes (quote confirm)) ; allow refile to create parent tasks with confirmation

(defun my-org-files-list ()
 (mapcar (lambda (buffer)
   (buffer-file-name buffer))
   (org-buffer-list 'files t))) 

(setq org-refile-targets '((my-org-files-list :maxlevel . 3))) 

Again, this used to work. But now when I run org-refile, I get this:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  org-refile-get-targets(nil (#("this" 0 4 (fontified t face org-level-1))))
  org-refile-get-location("Refile subtree \"this\" to" nil confirm nil)
  call-interactively(org-refile record nil)
  command-execute(org-refile record)
  execute-extended-command(nil "org-refile")
  call-interactively(execute-extended-command nil nil)

Any suggestions on how to fix this? Thanks!


1 Answer 1


The eventual list of targets derived from the variable org-refile-targets by org-refile-get-targets needs to be valid buffers or files, or else org-get-agenda-file-buffer will complain when it uses org-find-base-buffer-visiting. The original custom function my-org-files-list will return one or more nil entries in the list when there are non-file-visiting-buffers in org-mode. The solution is to delete the nil entries from the list using delq.

(defun my-org-files-list ()
  (delq nil
    (mapcar (lambda (buffer)
      (buffer-file-name buffer))
      (org-buffer-list 'files t))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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