andrei
andrei

Reputation: 325

refiling to a given subtree by a keybinding

The problem is probably very simple, but I'm struggling because I am new to ELISP.

I want to have a keybinding to refile current subtree to subtree TRASH.

I have written the code, which doesn't work, though. Could you please help me to fix it? Thanks in advance!

The code:

(defun org-move-to-trash()
  (org-refile "TRASH") ;; the function fails here because the parameter has to be specified in a different way. But how?
)

(global-set-key (kbd "C-c b") 'org-move-to-trash)

Upvotes: 3

Views: 416

Answers (1)

event_jr
event_jr

Reputation: 17707

If you're interested in elisp, you can read the source of org-refile to see how to prepare the arguments it expects (it's not straight forward). However, to solve this and many other more general problems, you don't need elisp at all. You need a keyboard macro. See manual.

I'll outline the steps I would take to solve this:

  1. C-x (
  2. C-c C-w TRASH
  3. C-x )
  4. M-x name-last-kbd-macro
  5. org-refile-to-TRASH
  6. C-x b scratch
  7. M-x insert-kbd-macro
  8. org-refile-to-TRASH

You should see:

(fset 'org-refile-to-TRASH
   [?\C-c ?\C-w ?T ?R ?A ?S ?H return])

You can paste this code into your init file, and use org-refile-to-TRASH as a command, exactly like if it were a defun e.g. in global-set-key, M-x, etc.

Upvotes: 6

Related Questions