Pārlūkot izejas kodu

org-list: small refactoring

* lisp/org-list.el (org-list-in-valid-block-p): new function.
(org-at-item-p,org-list-search-generic): use new function.
Nicolas Goaziou 14 gadi atpakaļ
vecāks
revīzija
f8ca5d85ba
1 mainītis faili ar 15 papildinājumiem un 5 dzēšanām
  1. 15 5
      lisp/org-list.el

+ 15 - 5
lisp/org-list.el

@@ -400,6 +400,17 @@ group 4: description tag")
            (goto-char (match-end 0)))
 	 (looking-at regexp))))
 
+(defun org-list-in-valid-block-p ()
+  "Non-nil if point is in a valid block.
+Invalid blocks are referring to `org-list-forbidden-blocks'."
+  (save-match-data
+    (let ((case-fold-search t))
+      (not (org-in-regexps-block-p
+	    (concat "^[ \t]*#\\+begin_\\("
+		    (mapconcat 'regexp-quote org-list-forbidden-blocks "\\|")
+		    "\\)")
+	    '(concat "^[ \t]*#\\+end_" (match-string 1)))))))
+
 (defun org-in-item-p ()
   "Return item beginning position when in a plain list, nil otherwise.
 This checks `org-list-ending-method'."
@@ -476,8 +487,7 @@ This checks `org-list-ending-method'."
   "Is point in a line starting a hand-formatted item?"
   (save-excursion
     (beginning-of-line)
-    (and (looking-at (org-item-re))
-	 (not (eq (nth 2 (org-list-context)) 'invalid)))))
+    (and (looking-at (org-item-re)) (org-list-in-valid-block-p))))
 
 (defun org-at-item-bullet-p ()
   "Is point at the bullet of a plain list item?"
@@ -1037,9 +1047,9 @@ in `re-search-forward'."
 	(unless (funcall search re bound noerr)
 	  (throw 'exit (and (goto-char (if (memq noerr '(t nil)) origin bound))
 			    nil)))
-	;; 2. Match in an `invalid' context: continue searching. Else,
-	;;    return point.
-	(unless (eq (org-list-context) 'invalid) (throw 'exit (point)))))))
+	;; 2. Match in valid context: return point. Else, continue
+	;;    searching.
+	(when (org-list-in-valid-block-p) (throw 'exit (point)))))))
 
 (defun org-list-search-backward (regexp &optional bound noerror)
   "Like `re-search-backward' but stop only where lists are recognized.