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.
This commit is contained in:
Nicolas Goaziou 2011-03-09 20:30:18 +01:00
parent 6ff4c9f42f
commit f8ca5d85ba
1 changed files with 15 additions and 5 deletions

View File

@ -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.