1

kill-whole-line works as I want. It cuts the line, and when I'm in org-mode it cuts the whole collapsed subtree.

What I need is just that as copy instead of cut. There is a multitude of suggestions here how to copy a whole line, which all work, but in org-mode they simply do not copy the whole collapsed subtree, they just copy the first line.

  • FWIW, a common Emacs idiom for emulating save-* commands is performing the corresponding kill command and then immediately undoing/yanking the kill, e.g. C-k followed by C-y, as the former kill modifies the kill-ring whereas the latter undo or yank does not. – Basil Dec 20 '17 at 18:31
1

How 'bout

(defun save-whole-line ()
  (interactive)
  (save-excursion
    (forward-visible-line 0)
    (let ((start (point)))
      (forward-visible-line 1)
      (kill-new (buffer-substring start (point))))))

The (forward-visible-line 0) was taken from kill-whole-line's source code, and the kill-new was taken from copy-region-as-kill's source code (both of which should be easy to find via C-h f <function-name> RET).

  • Thanks for that code. It works as expected. I don't get it. If kill-whole-line is a part of emacs why not save-whole-line? – Jens Lange Dec 14 '17 at 17:27
  • Better would be a general "kill prefix" which you could use before any navigation command. – Stefan Dec 14 '17 at 19:26
  • How about making a suggestion on the emacs mailing list? I think you have a point here. – Jens Lange Dec 15 '17 at 13:44
2

To copy an entire subtree (including the parts that are hidden) use C-c C-x M-w which runs org-copy-special

To copy an entire subtree (NOT including the parts that are hidden) you can mark the entire section and run C-c C-x v which runs org-copy-visible

(these work for Spacemacs 0.200.9@27.0.50 but I believe they also work for regular emacs)

  • No, what I need is an mode-universal command like kill-whole-line. org-copy-special works quite differently than kill-whole-line. Combining org-copy-special with org-copy-visible works somehow but it is far from the universal behaviour of kill-whole-line – Jens Lange Dec 14 '17 at 17:14

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.