org.el/org-scan-tags: Make use of fast `org-element-cache-map'

This commit is contained in:
Ihor Radchenko 2021-10-17 00:00:01 +08:00
parent 85e0a69567
commit 3c4290e668
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 190 additions and 104 deletions

View File

@ -11533,6 +11533,92 @@ headlines matching this string."
(when (eq action 'sparse-tree)
(org-overview)
(org-remove-occur-highlights))
(if (org-element--cache-active-p)
(let ((fast-re (concat "^"
(if start-level
;; Get the correct level to match
(concat "\\*\\{" (number-to-string start-level) "\\} ")
org-outline-regexp))))
(org-element-cache-map
(lambda (el)
(goto-char (org-element-property :begin el))
(setq todo (org-element-property :todo-keyword el)
level (org-element-property :level el)
category (org-entry-get-with-inheritance "CATEGORY" nil el)
tags-list (org-get-tags el)
org-scanner-tags tags-list)
(when (eq action 'agenda)
(setq ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
ts-date (car ts-date-pair)
ts-date-type (cdr ts-date-pair)))
(catch :skip
(when (and
;; eval matcher only when the todo condition is OK
(and (or (not todo-only) (member todo org-todo-keywords-1))
(if (functionp matcher)
(let ((case-fold-search t) (org-trust-scanner-tags t))
(funcall matcher todo tags-list level))
matcher))
;; Call the skipper, but return t if it does not
;; skip, so that the `and' form continues evaluating.
(progn
(unless (eq action 'sparse-tree) (org-agenda-skip el))
t)
;; Check if timestamps are deselecting this entry
(or (not todo-only)
(and (member todo org-todo-keywords-1)
(or (not org-agenda-tags-todo-honor-ignore-options)
(not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item))))))
;; select this headline
(cond
((eq action 'sparse-tree)
(and org-highlight-sparse-tree-matches
(org-get-heading) (match-end 0)
(org-highlight-new-match
(match-beginning 1) (match-end 1)))
(org-show-context 'tags-tree))
((eq action 'agenda)
(setq txt (org-agenda-format-item
""
(concat
(if (eq org-tags-match-list-sublevels 'indented)
(make-string (1- level) ?.) "")
(org-get-heading))
(make-string level ?\s)
category
tags-list)
priority (org-get-priority txt))
(goto-char (org-element-property :begin el))
(setq marker (org-agenda-new-marker))
(org-add-props txt props
'org-marker marker 'org-hd-marker marker 'org-category category
'todo-state todo
'ts-date ts-date
'priority priority
'type (concat "tagsmatch" ts-date-type))
(push txt rtn))
((functionp action)
(setq org-map-continue-from nil)
(save-excursion
(setq rtn1 (funcall action))
(push rtn1 rtn)))
(t (user-error "Invalid action")))
;; if we are to skip sublevels, jump to end of subtree
(unless org-tags-match-list-sublevels
(goto-char (1- (org-element-property :end el))))))
;; Get the correct position from where to continue
(when org-map-continue-from
(goto-char org-map-continue-from))
;; Return nil.
nil)
:next-re fast-re
:fail-re fast-re
:narrow t))
(while (let (case-fold-search)
(re-search-forward re nil t))
(setq org-map-continue-from nil)
@ -11641,7 +11727,7 @@ headlines matching this string."
;; Get the correct position from where to continue
(if org-map-continue-from
(goto-char org-map-continue-from)
(and (= (point) lspos) (end-of-line 1)))))
(and (= (point) lspos) (end-of-line 1))))))
(when (and (eq action 'sparse-tree)
(not org-sparse-tree-open-archived-trees))
(org-hide-archived-subtrees (point-min) (point-max)))