From 0a14598575faa9609d7a26b3e5909a73a3582b25 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 21 Jul 2010 18:43:47 +0200 Subject: [PATCH] Added a rule for indentation and improved reordering. * org-list.el (org-indent-item-tree): If indent rule is activated, it should be impossible to outdent an item having children without moving its subtree. Improved reordering of lists modified by cycling indentation. --- lisp/org-list.el | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/lisp/org-list.el b/lisp/org-list.el index 076fa0224..48f025309 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -802,16 +802,26 @@ If NO-SUBTREE is set, only indent the item itself, not its children." (cond ;; Going to a negative column is nonsensical. ((< (+ delta ind) 0) (error "Cannot outdent beyond margin")) - ;; Do not indent before top-item, unless point is at top-item. - ((and (< (+ delta ind) origin-ind) - (/= (point-at-bol) (org-list-top-point))) - (error "Cannot outdent beyond top level item")) - ((and firstp (> delta 0) (/= (point-at-bol) (org-list-top-point))) - (error "Cannot indent the beginning of a sublist")) - ;; If *-list is going to column 0, prevent mixing items and - ;; headings by changing bullet to "-". - ((and (= (+ delta ind) 0) (equal bullet "*")) - (org-fix-bullet-type "-"))) + ;; Apply indent rules if activated. + ((cdr (assq 'indent org-list-automatic-rules)) + (cond + ;; If at top-point move the whole list. Moreover, if *-list + ;; is going to column 0, change bullet to "-". + ((= (point-at-bol) (org-list-top-point)) + (when (and (= (+ delta ind) 0) (equal bullet "*")) (org-fix-bullet-type "-")) + (setq end (set-marker org-last-indent-end-marker (org-list-bottom-point)))) + ;; Do not indent before top-item. + ((< (+ delta ind) origin-ind) + (error "Cannot outdent beyond top level item")) + ;; Do not indent the first item of a list. + ((and firstp (> delta 0)) + (error "Cannot indent the beginning of a sublist")) + ;; Do not outdent item that has children without moving subtree. + ((and (/= (save-excursion (org-end-of-item-text-before-children)) + (save-excursion (org-end-of-item))) + (< delta 0) + no-subtree) + (error "Cannot outdent an item having children without moving subtree"))))) ;; Proceed to reindentation. (while (< (point) end) (beginning-of-line) @@ -821,11 +831,17 @@ If NO-SUBTREE is set, only indent the item itself, not its children." (beginning-of-line 2))) (org-fix-bullet-type (and (> arg 0) - (not firstp) (cdr (assoc bullet org-list-demote-modify-bullet)))) + ;; Reorder lists that might have changed (save-excursion (beginning-of-line 0) (ignore-errors (org-beginning-of-item)) + (org-maybe-renumber-ordered-list)) + (save-excursion + (org-end-of-item-text-before-children) + (org-maybe-renumber-ordered-list)) + (save-excursion + (org-end-of-item-list) (org-maybe-renumber-ordered-list)))) (defun org-item-indent-positions () @@ -882,8 +898,8 @@ Assumes cursor in item line." (if (eq last-command 'org-cycle-item-indentation) (condition-case nil (progn (org-outdent-item 1) - (if (equal org-tab-ind-state (org-get-indentation)) - (org-outdent-item 1)) + (when (equal org-tab-ind-state (org-get-indentation)) + (org-outdent-item 1)) (end-of-line)) (error (progn