Make C-y insert subtrees in folded state.

This commit is contained in:
Carsten Dominik 2008-09-14 08:03:55 +02:00
parent 521c7adf21
commit 53693652b0
2 changed files with 45 additions and 14 deletions

View File

@ -35,6 +35,21 @@
as a tty key replacement. as a tty key replacement.
** Details ** Details
*** Yanking inserts folded subtrees
If the kill is a subtree or a sequence of subtrees, yanking
them with =C-y= will leave all the subtrees in a folded
state. This basically means, that kill and yank are now
much more useful in moving stuff around in your outline. If
you do not like this, customize the variable
=org-yank-folded-subtrees=.
Right now, I am only binding =C-y= to this new function,
should I modify all bindings of yank? Do we need to amend
=yank-pop= as well?
This feature was requested by John Wiegley.
*** Prefix arg 0 to S-RET disabled integer increment during copy *** Prefix arg 0 to S-RET disabled integer increment during copy
This was a request by Chris Randle. This was a request by Chris Randle.
*** Column view capture tables can have formulas and plotting instructions *** Column view capture tables can have formulas and plotting instructions

View File

@ -632,6 +632,14 @@ When t, the following will happen while the cursor is in the headline:
:group 'org-edit-structure :group 'org-edit-structure
:type 'boolean) :type 'boolean)
(defcustom org-yank-folded-subtrees t
"Non-nil means, when yanking subtrees, fold them.
If the kill is a single subtree, or a sequence of subtrees, i.e. if
it starts with a heading and all other headings in it are either children
or siblings, then fold all the subtrees."
:group 'org-edit-structure
:type 'boolean)
(defcustom org-M-RET-may-split-line '((default . t)) (defcustom org-M-RET-may-split-line '((default . t))
"Non-nil means, M-RET will split the line at the cursor position. "Non-nil means, M-RET will split the line at the cursor position.
When nil, it will go to the end of the line before making a When nil, it will go to the end of the line before making a
@ -5131,7 +5139,7 @@ If optional TXT is given, check this string instead of the current kill."
kill) kill)
(- (match-end 2) (match-beginning 2) 1))) (- (match-end 2) (match-beginning 2) 1)))
(re (concat "^" org-outline-regexp)) (re (concat "^" org-outline-regexp))
(start (1+ (match-beginning 2)))) (start (1+ (or (match-beginning 2) -1))))
(if (not start-level) (if (not start-level)
(progn (progn
nil) ;; does not even start with a heading nil) ;; does not even start with a heading
@ -14395,20 +14403,28 @@ beyond the end of the headline."
(define-key org-mode-map "\C-k" 'org-kill-line) (define-key org-mode-map "\C-k" 'org-kill-line)
(defun org-yank-and-fold-if-subtree () (defun org-yank ()
"Yank, and if the yanked text is a single subtree, fold it." "Yank, and if the yanked text is a single subtree, fold it.
In fact, if the yanked text is a sequence of subtrees, fold all of them."
(interactive) (interactive)
(let ((pos (point)) p1) (if org-yank-folded-subtrees
(call-interactively 'yank) (let ((beg (point)) end)
(setq p1 (point)) (call-interactively 'yank)
(goto-char pos) (setq end (point))
(when (and (bolp) (goto-char beg)
(looking-at outline-regexp) (when (and (bolp)
(org-kill-is-subtree-p)) (org-kill-is-subtree-p))
(hide-subtree) (or (looking-at outline-regexp)
(org-cycle-show-empty-lines 'folded)) (re-search-forward (concat "^" outline-regexp) end t))
(goto-char p1) (while (and (< (point) end) (looking-at outline-regexp))
(skip-chars-forward " \t\n\r"))) (hide-subtree)
(org-cycle-show-empty-lines 'folded)
(outline-forward-same-level 1)))
(goto-char end)
(skip-chars-forward " \t\n\r"))
(call-interactively 'yank)))
(define-key org-mode-map "\C-y" 'org-yank)
(defun org-invisible-p () (defun org-invisible-p ()
"Check if point is at a character currently not visible." "Check if point is at a character currently not visible."