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.
This commit is contained in:
Nicolas Goaziou 2010-07-21 18:43:47 +02:00
parent 19372845f9
commit 0a14598575
1 changed files with 29 additions and 13 deletions

View File

@ -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