diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2010-08-21 15:23:58 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2010-09-01 19:05:54 +0200 |
commit | bac9497d7aa14dc486638ad027804774c14f06a3 (patch) | |
tree | 321feaaaaf3014ae0e2e25ce8a54639e4996404d | |
parent | 50f2c13ddc9a73203064df4a8180a4a1742e50aa (diff) | |
download | org-mode-bac9497d7aa14dc486638ad027804774c14f06a3.tar.gz |
Handle drawers correctly.
-rw-r--r-- | lisp/org-list.el | 97 | ||||
-rw-r--r-- | lisp/org.el | 4 |
2 files changed, 62 insertions, 39 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el index a7bf4ff..bf43b4a 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -381,26 +381,33 @@ Return the position of the previous item, if applicable." (beginning-of-line))) (beginning-of-line) (or (and (org-at-item-p) (point-at-bol)) - (let ((case-fold-search t) - (bound (save-excursion - (when (org-search-backward-unenclosed - org-item-beginning-re limit t) - (cons (point-at-bol) (org-get-indentation)))))) - (and bound + (let* ((case-fold-search t) + (pos (point)) + (ind-ref (org-get-indentation)) + ;; Is there an item above? + (up-item-p (save-excursion + (goto-char limit) + (org-search-forward-unenclosed + org-item-beginning-re pos t)))) + (and up-item-p (catch 'exit (while t - (let ((ind (org-get-indentation))) - (cond - ((looking-at "^[ \t]*$") - (skip-chars-backward " \r\t\n") - (beginning-of-line)) - ((looking-at "^[ \t]*#\\+end_") - (re-search-backward "^[ \t]*#\\+begin_")) - ((= (point) (car bound)) - (throw 'exit (car bound))) - ((>= (cdr bound) ind) - (throw 'exit nil)) - (t (forward-line -1))))))))))) + (cond + ((or (= (point) limit) + (looking-at "^[ \t]*:END:")) + (throw 'exit nil)) + ((looking-at "^[ \t]*$") + (skip-chars-backward " \r\t\n") + (beginning-of-line)) + ((looking-at "^[ \t]*#\\+end_") + (re-search-backward "^[ \t]*#\\+begin_")) + ((looking-at org-item-beginning-re) + (if (< (org-get-indentation) ind-ref) + (throw 'exit (point-at-bol)) + (forward-line -1))) + (t + (setq ind-ref (min (org-get-indentation) ind-ref)) + (forward-line -1)))))))))) (defun org-list-in-item-p-with-regexp (limit) "Is the cursor inside a plain list? @@ -474,7 +481,8 @@ List ending is determined by indentation of text. See (while t (let ((ind (org-get-indentation))) (cond - ((<= (point) limit) + ((or (<= (point) limit) + (looking-at "^[ \t]*:END:")) (throw 'exit item-ref)) ((looking-at "^[ \t]*$") (skip-chars-backward " \r\t\n") @@ -512,8 +520,9 @@ List ending is determined by the indentation of text. See (while t (let ((ind (org-get-indentation))) (cond - ((>= (point) limit) - (throw 'exit limit)) + ((or (>= (point) limit) + (looking-at "^[ \t]*:END:")) + (throw 'exit (point))) ((looking-at "^[ \t]*$") (skip-chars-forward " \r\t\n") (beginning-of-line)) @@ -670,8 +679,13 @@ function ends." "Is the cursor inside a plain list? This checks `org-list-ending-method'." (unless (let ((outline-regexp org-outline-regexp)) (org-at-heading-p)) - (let ((bound (or (save-excursion (outline-previous-heading)) - (point-min)))) + (let* ((prev-head (save-excursion (outline-previous-heading))) + (bound (if prev-head + (or (save-excursion + (let ((case-fold-search t)) + (re-search-backward "^[ \t]*:END:" prev-head t))) + prev-head) + (point-min)))) (cond ((eq org-list-ending-method 'indent) (org-list-in-item-p-with-indent bound)) @@ -740,29 +754,38 @@ A checkbox is blocked if all of the following conditions are fulfilled: (defun org-list-top-point () "Return point at the top level in a list, or nil if not in a list." - (let ((limit (or (save-excursion (outline-previous-heading)) - (point-min)))) + (let* ((prev-head (save-excursion (outline-previous-heading))) + (bound (if prev-head + (or (save-excursion + (let ((case-fold-search t)) + (re-search-backward "^[ \t]*:END:" prev-head t))) + prev-head) + (point-min)))) (cond ((eq org-list-ending-method 'indent) - (org-list-top-point-with-indent limit)) + (org-list-top-point-with-indent bound)) ((eq org-list-ending-method 'both) - (let ((top-re (org-list-top-point-with-regexp limit)) - (top-ind (org-list-top-point-with-indent limit))) + (let ((top-re (org-list-top-point-with-regexp bound)) + (top-ind (org-list-top-point-with-indent bound))) (if (and top-re top-ind) (max top-re top-ind) (or top-re top-ind)))) - (t (org-list-top-point-with-regexp limit))))) + (t (org-list-top-point-with-regexp bound))))) (defun org-list-bottom-point () "Return point just before list ending or nil if not in a list." - (let ((limit (or (save-excursion - (and (let ((outline-regexp org-outline-regexp)) - ;; Use default regexp because folding - ;; changes OUTLINE-REGEXP. - (outline-next-heading)) - (skip-chars-backward " \r\t\n") - (1+ (point-at-eol)))) - (point-max)))) + (let* ((next-head (save-excursion + (and (let ((outline-regexp org-outline-regexp)) + ;; Use default regexp because folding + ;; changes OUTLINE-REGEXP. + (outline-next-heading)) + (skip-chars-backward " \r\t\n") + (1+ (point-at-eol))))) + (limit (or (save-excursion + (and (re-search-forward "^[ \t]*:END:" next-head t) + (point-at-bol))) + next-head + (point-max)))) (cond ((eq org-list-ending-method 'indent) (org-list-bottom-point-with-indent limit)) diff --git a/lisp/org.el b/lisp/org.el index ead7234..ff73c22 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -11699,7 +11699,7 @@ This is done in the same way as adding a state change note." (defvar org-property-end-re) (defun org-add-log-setup (&optional purpose state prev-state - findpos how &optional extra) + findpos how extra) "Set up the post command hook to take a note. If this is about to TODO state change, the new state is expected in STATE. When FINDPOS is non-nil, find the correct position for the note in @@ -11848,8 +11848,8 @@ EXTRA is additional text that will be inserted into the notes buffer." (move-marker org-log-note-marker nil) (end-of-line 1) (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n"))) - (insert "- " (pop lines)) (org-indent-line-function) + (insert "- " (pop lines)) (beginning-of-line 1) (looking-at "[ \t]*") (setq ind (concat (match-string 0) " ")) |