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.
This commit is contained in:
Nicolas Goaziou 2010-07-20 11:47:54 +02:00
parent 42f82d1bad
commit eebd8eb022
2 changed files with 16 additions and 15 deletions

View File

@ -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-invisible-p))
(< (org-list-bottom-point) (point)))
(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)) (if (not (org-in-item-p))
(let ((list (org-list-parse-list t)) nstars) (error "Not in a list.")
(save-excursion (goto-char (org-list-top-point))
(if (ignore-errors (let ((list (org-list-parse-list t)) nstars)
(org-back-to-heading)) (save-excursion
(progn (org-search-forward-unenclosed org-complex-heading-regexp nil t) (if (ignore-errors
(setq nstars (length (match-string 1)))) (org-back-to-heading))
(setq nstars 0))) (progn (org-search-forward-unenclosed org-complex-heading-regexp nil t)
(org-list-make-subtrees list (1+ nstars)))) (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."

View File

@ -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)) (save-excursion (org-beginning-of-item) (org-at-item-timer-p)))
(>= (org-list-bottom-point) (point)))
(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.