diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-05-28 19:10:05 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-05-28 19:10:05 +0200 |
commit | 5a57bfffaee3484c152a1cb7e1964c70207cfa0e (patch) | |
tree | 1be02f7a10136715d6d44716542e16758297d22f | |
parent | b39a271fcb6aafc0930d6ce39036e04b861e02f9 (diff) | |
download | org-mode-5a57bfffaee3484c152a1cb7e1964c70207cfa0e.tar.gz |
Preserve subtrees when changing headlines into items
* lisp/org.el (org-toggle-item): when region includes an headline less
indented than first one, set it as the new reference.
-rw-r--r-- | lisp/org.el | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lisp/org.el b/lisp/org.el index 9a57ff3..9232700 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17823,9 +17823,9 @@ argument ARG, change each line in region into an item." (save-excursion (goto-char beg) (cond - ;; Case 1. Start at an item: de-itemize. Note that it only - ;; happens when a region is active: `org-ctrl-c-minus' would - ;; call `org-cycle-list-bullet' otherwise. + ;; Case 1. Start at an item: de-itemize. Note that it only + ;; happens when a region is active: `org-ctrl-c-minus' + ;; would call `org-cycle-list-bullet' otherwise. ((org-at-item-p) (while (< (point) end) (when (org-at-item-p) @@ -17847,8 +17847,12 @@ argument ARG, change each line in region into an item." ;; compared to it to determine hierarchy in the list. (ref-level (org-reduced-level (org-outline-level)))) (while (< (point) end) - (let ((delta (max 0 (- (org-reduced-level (org-outline-level)) - ref-level)))) + (let* ((level (org-reduced-level (org-outline-level))) + (delta (max 0 (- level ref-level)))) + ;; If current headline is less indented than the first + ;; one, set it as reference, in order to preserve + ;; subtrees. + (when (< level ref-level) (setq ref-level level)) (replace-match bul t t) (org-indent-line-to (+ start-ind (* delta bul-len))) ;; Ensure all text down to END (or SECTION-END) belongs |