Browse Source

New function `org-item-has-children-p'.

Nicolas Goaziou 15 years ago
parent
commit
ca106beabb
2 changed files with 14 additions and 6 deletions
  1. 11 5
      lisp/org-list.el
  2. 3 1
      lisp/org.el

+ 11 - 5
lisp/org-list.el

@@ -470,6 +470,15 @@ function ends."
   "Is point at a line starting a plain-list item with a checklet?"
   (org-list-at-regexp-after-bullet-p "\\(\\[[- X]\\]\\)[ \t]+"))
 
+(defun org-item-has-children-p ()
+  "Does the current item have subitems?"
+  (save-excursion
+    (org-beginning-of-item)
+    (let ((ind (org-get-indentation)))
+      (org-end-of-item-text-before-children)
+      (and (org-at-item-p)
+	   (> (org-get-indentation) ind)))))
+
 (defun org-checkbox-blocked-p ()
   "Is the current checkbox blocked from for being checked now?
 A checkbox is blocked if all of the following conditions are fulfilled:
@@ -821,11 +830,8 @@ children. Return t if sucessful."
 	 ;; 4. Do not outdent item that has children without moving.
 	 ;; In the case of a subtree, make sure the check applies to
 	 ;; its last item.
-	 ((and (save-excursion
-		 (goto-char (1- end))
-		 (/= (save-excursion (org-end-of-item-text-before-children))
-		     (save-excursion (org-end-of-item))))
-	       (< delta 0))
+	 ((and (< delta 0)
+	       (save-excursion (goto-char (1- end)) (org-item-has-children-p)))
 	  (error "Cannot outdent an item having children")))))
       ;; Proceed to reindentation.
       (while (< (point) end)

+ 3 - 1
lisp/org.el

@@ -5902,7 +5902,9 @@ in special contexts.
 				(> (funcall outline-level) level))))
       ;; if we're in a list, org-end-of-subtree is in fact org-end-of-item.
       (if (org-at-item-p)
-	  (setq eos (1- (org-end-of-item)))
+	  (setq eos (if (and (org-end-of-item) (bolp))
+			(1- (point))
+		      (point)))
 	(org-end-of-subtree t)
 	(unless (eobp)
 	  (skip-chars-forward " \t\n"))