Browse Source

Fixed bug in `org-in-item-p' with point at an heading just beyond list.

* org-list.el (org-in-item-p): Handle case when point is at an
  heading.
* org-list.el (org-list-make-subtree): Add protection when used
  outside of list
* org-list.el (org-insert-item): Removed useless hack now
  `org-in-item-p' is fixed.
* org-timer.el (org-timer-item): Removed useless hack now
  `org-in-item-p' is fixed.
Nicolas Goaziou 14 years ago
parent
commit
eebd8eb022
2 changed files with 16 additions and 15 deletions
  1. 15 13
      lisp/org-list.el
  2. 1 2
      lisp/org-timer.el

+ 15 - 13
lisp/org-list.el

@@ -420,7 +420,8 @@ function ends."
 
 
 (defun org-in-item-p ()
 (defun org-in-item-p ()
   "Is the cursor inside a plain list ?"
   "Is the cursor inside a plain list ?"
-  (save-excursion
+  (unless (org-at-heading-p)
+    (save-excursion
     ;; Move to eol so that current line can be matched by
     ;; Move to eol so that current line can be matched by
     ;; `org-item-re'.
     ;; `org-item-re'.
     (let* ((limit (save-excursion (outline-previous-heading)))
     (let* ((limit (save-excursion (outline-previous-heading)))
@@ -432,7 +433,7 @@ function ends."
       ;; an item before and there is no valid list ender between us
       ;; an item before and there is no valid list ender between us
       ;; and the item found.
       ;; and the item found.
       (and last-item-start
       (and last-item-start
-	   (not list-ender)))))
+	   (not list-ender))))))
 
 
 (defun org-first-list-item-p ()
 (defun org-first-list-item-p ()
   "Is this heading the first item in a plain list?"
   "Is this heading the first item in a plain list?"
@@ -697,8 +698,7 @@ new item will be created before the current one. Return t when
 things worked, nil when we are not in an item, or item is
 things worked, nil when we are not in an item, or item is
 invisible."
 invisible."
   (unless (or (not (org-in-item-p))
   (unless (or (not (org-in-item-p))
-	      (org-invisible-p)
-	      (< (org-list-bottom-point) (point)))
+	      (org-invisible-p))
     (if (save-excursion
     (if (save-excursion
 	  (org-beginning-of-item)
 	  (org-beginning-of-item)
 	  (org-at-item-timer-p))
 	  (org-at-item-timer-p))
@@ -1383,15 +1383,17 @@ sublevels as a list of strings."
 (defun org-list-make-subtree ()
 (defun org-list-make-subtree ()
   "Convert the plain list at point into a subtree."
   "Convert the plain list at point into a subtree."
   (interactive)
   (interactive)
-  (goto-char (org-list-top-point))
-  (let ((list (org-list-parse-list t)) nstars)
-    (save-excursion
-      (if (ignore-errors
-	    (org-back-to-heading))
-	  (progn (org-search-forward-unenclosed org-complex-heading-regexp nil t)
-		 (setq nstars (length (match-string 1))))
-	(setq nstars 0)))
-    (org-list-make-subtrees list (1+ nstars))))
+  (if (not (org-in-item-p))
+      (error "Not in a list.")
+    (goto-char (org-list-top-point))
+    (let ((list (org-list-parse-list t)) nstars)
+      (save-excursion
+	(if (ignore-errors
+	      (org-back-to-heading))
+	    (progn (org-search-forward-unenclosed org-complex-heading-regexp nil t)
+		   (setq nstars (length (match-string 1))))
+	  (setq nstars 0)))
+      (org-list-make-subtrees list (1+ nstars)))))
 
 
 (defun org-list-make-subtrees (list level)
 (defun org-list-make-subtrees (list level)
   "Convert LIST into subtrees starting at LEVEL."
   "Convert LIST into subtrees starting at LEVEL."

+ 1 - 2
lisp/org-timer.el

@@ -203,8 +203,7 @@ it in the buffer."
   (cond
   (cond
    ;; In a timer list, insert with `org-list-insert-item-generic'.
    ;; In a timer list, insert with `org-list-insert-item-generic'.
    ((and (org-in-item-p)
    ((and (org-in-item-p)
-	 (save-excursion (org-beginning-of-item) (org-at-item-timer-p))
-	 (>= (org-list-bottom-point) (point)))
+	 (save-excursion (org-beginning-of-item) (org-at-item-timer-p)))
     (org-list-insert-item-generic
     (org-list-insert-item-generic
      (point) nil (concat (org-timer (when arg '(4)) t) ":: ")))
      (point) nil (concat (org-timer (when arg '(4)) t) ":: ")))
    ;; In a list of another type, don't break anything: throw an error.
    ;; In a list of another type, don't break anything: throw an error.