I want to run newline command after whenever I run org-cut-subtree. I tried

(add-hook 'after-org-cut-subtree-hook 'newline)
(add-hook 'org-cut-subtree-hook 'newline)
(add-hook 'org-after-cut-subtree-hook 'newline)

but none of them worked. How can I add newline command to the post-command hook of org-cut-subtree?

  • You can use after advice on the function instead if there are no hooks. – Dan Jul 23 '16 at 13:37

I typed M-x find-function RET org-cut-subtree RET and saw that it was just a few lines of code that calls org-copy-subtree. Then, I typed M-x find-function RET org-copy-subtree RET and looked through about 25 lines of code to see if there were any built-in hooks -- I did not find any.

I recommend creating a new function called my-org-cut-subtree to avoid any unintended side effects that would likely occur if the original poster tried to alter the behavior of the core functions at issue, since they are used by other aspects of org-mode. I recommend using (insert "\n") instead of newline to insert a new line.

(defun my-org-cut-subtree (&optional n)
  "Cut the current subtree into the clipboard.
With prefix arg N, cut this many sequential subtrees.
This is a short-hand for marking the subtree and then cutting it."
  (interactive "p")
  (org-copy-subtree n 'cut)
  (insert "\n"))

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.