0

I would like to create a function that uses the refile interface to jump to a heading (C-u C-c C-w or 'Refile-Goto'), where I can enter the filename and Heading as arguments. Following instructions here - org-refile to a known fixed location , I have written the following function that successfully refiles subtrees with arguments.

;;Org-Refile with parameters
(defun my/refile-params (file headline)
(interactive)
  (let ((pos (save-excursion
               (find-file file)
               (org-find-exact-headline-in-buffer headline))))
    (org-refile nil nil (list headline file nil pos))))
(map! :leader :desc "file away" "zf" (lambda () (interactive) (my/refile-params "~/orgnotes/casenotes.org" "Destination")))

I have created another function that successfully calls Refile-Goto, but requires manually enter the destination.

;;Org-Refile-Goto without parameters
(defun my/refile-goto ()
  (interactive)
  (setq current-prefix-arg '(4)) 
  (call-interactively (org-refile)))
(map! :leader :desc "file away" "zn" (lambda () (interactive) (my/refile-goto)))

All seems good, but when I combine the two as below, instead of just jumping, it refiles, and throws up a Wrong Type Argument error to boot.

;;Org-Refile-Goto with Parameters *Not Working*
(defun my/refile-params-goto (file headline)
  (interactive)
  (setq current-prefix-arg '(4)) 
  (call-interactively (my/refile-params file headline)))
(map! :leader :desc "Go to @In-Progress" "zg" (lambda () (interactive) (my/refile-params-goto "~/orgnotes/casenotes.org" "Destination")))

All help greatly appreciated.

NB: Using doom, if that helps understanding the keyboard mapping. Including the mapping lines, as they include 'lambda', which is mysterious black magic to me, so I may be getting it wrong.

randouser
  • 91
  • 7

1 Answers1

0

I learnt that call-interactively takes a symbol for a command, and no arguments. I was evaluating (my/refile-params file headline), then trying to interactively call the value it returns. That's not a command, so I got a wrong type argument error.

Using current-prefix-arg and call-interactively wasn't working, so instead I passed the prefix argument as the first argument in the org-refile call, as below:

(defun my/refile-params-goto (file headline)
(interactive)
  (let ((pos (save-excursion
               (find-file file)
               (org-find-exact-headline-in-buffer headline))))
    (org-refile '(4) nil (list headline file nil pos))))
(map! :leader :desc "file away" "zg" (lambda () (interactive) (my/refile-params-goto "~/orgnotes/casenotes.org" "Destination")))

Working just great now.

randouser
  • 91
  • 7