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

View file

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