3

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?

stacko
  • 1,597
  • 1
  • 11
  • 19

1 Answers1

5

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"))
lawlist
  • 19,106
  • 5
  • 38
  • 120