Explorar el Código

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)).
Nicolas Goaziou hace 14 años
padre
commit
215d3fa030
Se han modificado 3 ficheros con 26 adiciones y 37 borrados
  1. 2 3
      lisp/org-list.el
  2. 3 6
      lisp/org-mouse.el
  3. 21 28
      lisp/org.el

+ 2 - 3
lisp/org-list.el

@@ -2479,12 +2479,11 @@ Point is left at list end."
 (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)
-  (if (not (org-in-item-p))
+  (if (not (ignore-errors (goto-char (org-in-item-p))))
       (error "Not in a list")
       (error "Not in a list")
     (let ((list (org-list-parse-list t)) nstars)
     (let ((list (org-list-parse-list t)) nstars)
       (save-excursion
       (save-excursion
-	(if (ignore-errors
-	      (org-back-to-heading))
+	(if (ignore-errors (org-back-to-heading))
 	    (progn (looking-at org-complex-heading-regexp)
 	    (progn (looking-at org-complex-heading-regexp)
 		   (setq nstars (length (match-string 1))))
 		   (setq nstars (length (match-string 1))))
 	  (setq nstars 0)))
 	  (setq nstars 0)))

+ 3 - 6
lisp/org-mouse.el

@@ -579,12 +579,9 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
 
 
 (defun org-mouse-for-each-item (funct)
 (defun org-mouse-for-each-item (funct)
   ;; Functions called by `org-apply-on-list' need an argument
   ;; 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 ()
 (defun org-mouse-bolp ()
   "Return true if there only spaces, tabs, and '*' before point.
   "Return true if there only spaces, tabs, and '*' before point.

+ 21 - 28
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 ()
 (defun org-skip-over-state-notes ()
   "Skip past the list of State notes in an entry."
   "Skip past the list of State notes in an entry."
   (if (looking-at "\n[ \t]*- State") (forward-char 1))
   (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)
 (defun org-add-log-note (&optional purpose)
   "Pop up a window for taking a note, and add this note later at point."
   "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)
 	  (end-of-line 1)
 	  (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
 	  (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
 	  (setq ind (save-excursion
 	  (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 "-"))
 	  (setq bul (org-list-bullet-string "-"))
 	  (org-indent-line-to ind)
 	  (org-indent-line-to ind)
 	  (insert bul (pop lines))
 	  (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)
 	      (org-get-indentation (match-string 0)))))
 	      (org-get-indentation (match-string 0)))))
      ;; Lists
      ;; 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))
       (or (org-at-item-description-p) (org-at-item-p))
       (setq bpos (match-beginning 1) tpos (match-end 0)
       (setq bpos (match-beginning 1) tpos (match-end 0)
 	    bcol (progn (goto-char bpos) (current-column))
 	    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_")
 		      (and (looking-at "[ \t]*#\\+end_")
 			   (re-search-backward "[ \t]*#\\+begin_"nil t))
 			   (re-search-backward "[ \t]*#\\+begin_"nil t))
 		      (looking-at "[ \t]*[\n:#|]")
 		      (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)
 		      (and (not inline-task-p)
 			   (featurep 'org-inlinetask)
 			   (featurep 'org-inlinetask)
 			   (org-inlinetask-in-task-p)
 			   (org-inlinetask-in-task-p)