org-element: Optimize working with match data and Emacs regexps
* lisp/org-element.el: Add commentary explaining some regexp-related optimizations useful for the parser. Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225 (org-element--headline-deferred): (org-element-item-parser): (org-element-item-interpreter): (org-element--list-struct): (org-element-plain-list-parser): (org-element-example-block-parser): (org-element-fixed-width-interpreter): (org-element-paragraph-parser): (org-element-src-block-parser): (org-element-table-parser): (org-element--parse-generic-emphasis): (org-element-export-snippet-interpreter): (org-element-link-parser): (org-element--current-element): (org-element--collect-affiliated-keywords): (org-element-parse-buffer): (org-element-normalize-string): (org-element-normalize-contents): (org-element--parse-to): (org-element--cache-before-change): (org-element--cache-for-removal): (org-element-context): Avoid storing match data unless strictly necessary. Explain the necessity in places where we have to use `save-match-data'. Prefer `looking-at-p' (does not alter match data) to `looking-at'. Simplify regexps. Update docstrings clearly indicating when match data might be modified. * lisp/org.el: (org-offer-links-in-entry): * lisp/ob-exp.el (org-babel-exp-process-buffer): * lisp/org-agenda.el: Fix places where we need to protect match data.
This commit is contained in:
parent
dfd36d1969
commit
fefaadc2d5
|
@ -173,7 +173,7 @@ this template."
|
|||
;; buffer.
|
||||
(org-fold-core-ignore-modifications
|
||||
(while (re-search-forward regexp nil t)
|
||||
(setq element (org-element-at-point))
|
||||
(setq element (save-match-data (org-element-at-point)))
|
||||
(unless (save-match-data
|
||||
(or (org-in-commented-heading-p nil element)
|
||||
(org-in-archived-heading-p nil element)))
|
||||
|
|
|
@ -6892,7 +6892,7 @@ scheduled items with an hour specification like [h]h:mm."
|
|||
(while (re-search-forward regexp nil t)
|
||||
(catch :skip
|
||||
(unless (save-match-data (org-at-planning-p)) (throw :skip nil))
|
||||
(org-agenda-skip)
|
||||
(save-match-data (org-agenda-skip))
|
||||
(let* ((s (match-string 1))
|
||||
(pos (1- (match-beginning 1)))
|
||||
(todo-state (save-match-data (org-get-todo-state)))
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8537,7 +8537,7 @@ there is one, return it."
|
|||
;; Only consider valid links or links openable via
|
||||
;; `org-open-at-point'.
|
||||
(when (org-element-type-p
|
||||
(org-element-context)
|
||||
(save-match-data (org-element-context))
|
||||
'(link comment comment-block node-property keyword))
|
||||
(push (match-string 0) links)))
|
||||
(setq links (org-uniquify (reverse links))))
|
||||
|
|
Loading…
Reference in New Issue