diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-01-10 18:55:39 +0100 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-02-18 12:45:10 +0100 |
commit | 215d3fa0306484d5246b1ddcc8ace7e1a1f18e37 (patch) | |
tree | 5c5b9468f6442e67ed6bf60b6d778646adc94525 | |
parent | d7a799cc8627a2d8e9b2988788accbcd464c98a5 (diff) | |
download | org-mode-215d3fa0306484d5246b1ddcc8ace7e1a1f18e37.tar.gz |
Improve usage of `org-in-item-p'
When the function needs to know if cursor is in a plain list and move
to item beginning if it is the case, a fast way is to ignore errors on
(goto-char (org-in-item-p)).
-rw-r--r-- | lisp/org-list.el | 5 | ||||
-rw-r--r-- | lisp/org-mouse.el | 9 | ||||
-rw-r--r-- | lisp/org.el | 49 |
3 files changed, 26 insertions, 37 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el index a29e5fa..b30ef90 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -2479,12 +2479,11 @@ Point is left at list end." (defun org-list-make-subtree () "Convert the plain list at point into a subtree." (interactive) - (if (not (org-in-item-p)) + (if (not (ignore-errors (goto-char (org-in-item-p)))) (error "Not in a list") (let ((list (org-list-parse-list t)) nstars) (save-excursion - (if (ignore-errors - (org-back-to-heading)) + (if (ignore-errors (org-back-to-heading)) (progn (looking-at org-complex-heading-regexp) (setq nstars (length (match-string 1)))) (setq nstars 0))) diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el index b660435..7aa313f 100644 --- a/lisp/org-mouse.el +++ b/lisp/org-mouse.el @@ -579,12 +579,9 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:" (defun org-mouse-for-each-item (funct) ;; Functions called by `org-apply-on-list' need an argument - (let ((wrap-fun (lambda (c) (funcall funct))) - (item-beg (org-in-item-p))) - (when item-beg - (save-excursion - (goto-char item-beg) - (org-apply-on-list wrap-fun nil))))) + (let ((wrap-fun (lambda (c) (funcall funct)))) + (when (ignore-errors (goto-char (org-in-item-p))) + (save-excursion (org-apply-on-list wrap-fun nil))))) (defun org-mouse-bolp () "Return true if there only spaces, tabs, and '*' before point. diff --git a/lisp/org.el b/lisp/org.el index 9968848..ed415e5 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -11819,13 +11819,12 @@ EXTRA is additional text that will be inserted into the notes buffer." (defun org-skip-over-state-notes () "Skip past the list of State notes in an entry." (if (looking-at "\n[ \t]*- State") (forward-char 1)) - (let ((itemp (org-in-item-p))) - (when itemp - (let* ((struct (progn (goto-char itemp) (org-list-struct))) - (prevs (org-list-struct-prev-alist struct))) - (while (looking-at "[ \t]*- State") - (goto-char (or (org-list-get-next-item (point) struct prevs) - (org-list-get-item-end (point) struct)))))))) + (when (ignore-errors (goto-char (org-in-item-p))) + (let* ((struct (org-list-struct)) + (prevs (org-list-struct-prev-alist struct))) + (while (looking-at "[ \t]*- State") + (goto-char (or (org-list-get-next-item (point) struct prevs) + (org-list-get-item-end (point) struct))))))) (defun org-add-log-note (&optional purpose) "Pop up a window for taking a note, and add this note later at point." @@ -11911,20 +11910,17 @@ EXTRA is additional text that will be inserted into the notes buffer." (end-of-line 1) (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n"))) (setq ind (save-excursion - (let ((itemp (org-in-item-p))) - (if itemp - (progn - (goto-char itemp) - (let ((struct (org-list-struct))) - (org-list-get-ind - (org-list-get-top-point struct) struct))) - (skip-chars-backward " \r\t\n") - (cond - ((and (org-at-heading-p) - org-adapt-indentation) - (1+ (org-current-level))) - ((org-at-heading-p) 0) - (t (org-get-indentation))))))) + (if (ignore-errors (goto-char (org-in-item-p))) + (let ((struct (org-list-struct))) + (org-list-get-ind + (org-list-get-top-point struct) struct)) + (skip-chars-backward " \r\t\n") + (cond + ((and (org-at-heading-p) + org-adapt-indentation) + (1+ (org-current-level))) + ((org-at-heading-p) 0) + (t (org-get-indentation)))))) (setq bul (org-list-bullet-string "-")) (org-indent-line-to ind) (insert bul (pop lines)) @@ -18833,8 +18829,7 @@ If point is in an inline task, mark that task instead." (org-get-indentation) (org-get-indentation (match-string 0))))) ;; Lists - ((let ((in-item-p (org-in-item-p))) - (and in-item-p (goto-char in-item-p))) + ((ignore-errors (goto-char (org-in-item-p))) (or (org-at-item-description-p) (org-at-item-p)) (setq bpos (match-beginning 1) tpos (match-end 0) bcol (progn (goto-char bpos) (current-column)) @@ -18856,11 +18851,9 @@ If point is in an inline task, mark that task instead." (and (looking-at "[ \t]*#\\+end_") (re-search-backward "[ \t]*#\\+begin_"nil t)) (looking-at "[ \t]*[\n:#|]") - (let ((itemp (org-in-item-p))) - (and itemp - (goto-char itemp) - (goto-char - (org-list-get-top-point (org-list-struct))))) + (and (ignore-errors (goto-char (org-in-item-p))) + (goto-char + (org-list-get-top-point (org-list-struct)))) (and (not inline-task-p) (featurep 'org-inlinetask) (org-inlinetask-in-task-p) |