When indenting a region, first check if there is any item to move.

This commit is contained in:
Nicolas Goaziou 2010-08-23 11:24:57 +02:00
parent 668e5832c2
commit 7e6778c16f
1 changed files with 74 additions and 74 deletions

View File

@ -690,40 +690,42 @@ function ends."
When number ARG is a negative, item will be outdented, otherwise
it will be indented.
If a region is active and its first line is an item beginning,
all items inside will be moved.
If a region is active, all items inside will be moved.
If NO-SUBTREE is non-nil, only indent the item itself, not its
children.
Return t if successful."
(save-restriction
(unless (or (org-at-item-p)
(and (org-region-active-p)
(goto-char (region-beginning))
(org-at-item-p)))
(let* ((regionp (org-region-active-p))
(rbeg (and regionp (region-beginning)))
(rend (and regionp (region-end))))
(cond
((and regionp
(goto-char rbeg)
(not (org-search-forward-unenclosed org-item-beginning-re rend t)))
(error "No item in region"))
((not (org-at-item-p))
(error "Not on an item"))
(t
;; Are we going to move the whole list?
(let ((specialp (and (cdr (assq 'indent org-list-automatic-rules))
(not no-subtree)
(= (org-list-top-point) (point-at-bol)))))
;; Determine begin and end points of zone to indent. If moving by
;; subtrees, ensure we don't drag additional items on subsequent
;; moves.
;; Determine begin and end points of zone to indent. If moving
;; more than one item, ensure we keep them on subsequent moves.
(unless (and (memq last-command '(org-shiftmetaright org-shiftmetaleft))
(memq this-command '(org-shiftmetaright org-shiftmetaleft)))
(if (org-region-active-p)
(if regionp
(progn
(set-marker org-last-indent-begin-marker (region-beginning))
(set-marker org-last-indent-end-marker (region-end)))
(set-marker org-last-indent-begin-marker rbeg)
(set-marker org-last-indent-end-marker rend))
(set-marker org-last-indent-begin-marker (point-at-bol))
(set-marker org-last-indent-end-marker
(save-excursion
(cond
(specialp
(org-list-bottom-point))
(no-subtree
(org-end-of-item-or-at-child))
(specialp (org-list-bottom-point))
(no-subtree (org-end-of-item-or-at-child))
(t (org-end-of-item)))))))
;; Get everything ready
(let* ((beg (marker-position org-last-indent-begin-marker))
@ -754,7 +756,7 @@ Return t if successful."
;; Forbidden move
((and (< arg 0)
(or (and no-subtree
(not (org-region-active-p))
(not regionp)
(org-list-struct-get-child beg-item struct))
(let ((last-item (save-excursion
(goto-char end)
@ -769,9 +771,7 @@ Return t if successful."
(org-list-struct-outdent beg end origins)
(org-list-struct-indent beg end origins struct))))
(org-list-struct-fix-struct struct shifted-ori)
(org-list-struct-apply-struct struct)))))))
;; Return value
t)
(org-list-struct-apply-struct struct)))))))))))
;;; Predicates