refiling to a given subtree by a keybinding

笑着哭i 提交于 2019-12-23 17:31:31

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/7681326/refiling-to-a-given-subtree-by-a-keybinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!