org-element: Simplify drawer and property drawer regexps

* lisp/org-element.el (org-element-drawer-re-nogroup): New constant
regexp matching drawer line without creating regexp groups.
(org-element--current-element): Use the new constant.
* lisp/org.el (org-drawer-regexp): Ensure that it is the same with
org-element version and mark for removal/alias.
(org-property-drawer-re): Simplify, removing unnecessary matching of
node property structures.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225#62
This commit is contained in:
Ihor Radchenko 2023-05-06 13:08:37 +02:00
parent 39466ecf47
commit 2b96501070
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 20 additions and 4 deletions

View File

@ -169,6 +169,13 @@ Style, if any, is located in match group 1.")
"Regexp matching opening or closing line of a drawer.
Drawer's name is located in match group 1.")
(defconst org-element-drawer-re-nogroup
(rx line-start (0+ (any ?\s ?\t))
":" (1+ (any ?- ?_ word)) ":"
(0+ (any ?\s ?\t)) line-end)
"Regexp matching opening or closing line of a drawer.
Drawer's name is located in match group 1.")
(defconst org-element-dynamic-block-open-re
(rx line-start (0+ (any ?\s ?\t))
"#+BEGIN:" (0+ (any ?\s ?\t))

View File

@ -594,7 +594,11 @@ Matched keyword is in group 1.")
;;;; Drawer
(defconst org-drawer-regexp "^[ \t]*:\\(\\(?:\\w\\|[-_]\\)+\\):[ \t]*$"
(defconst org-drawer-regexp
;; FIXME: Duplicate of `org-element-drawer-re'.
(rx line-start (0+ (any ?\s ?\t))
":" (group (1+ (any ?- ?_ word))) ":"
(0+ (any ?\s ?\t)) line-end)
"Matches first or last line of a hidden block.
Group 1 contains drawer's name or \"END\".")
@ -617,9 +621,14 @@ Group 1 contains drawer's name or \"END\".")
"Matches an entire LOGBOOK drawer.")
(defconst org-property-drawer-re
(concat "^[ \t]*:PROPERTIES:[ \t]*\n"
"\\(?:[ \t]*:\\S-+:\\(?:[ \t].*\\)?[ \t]*\n\\)*?"
"[ \t]*:END:[ \t]*$")
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225#62
(rx
;; Drawer begin line.
bol (0+ (in " \t")) ":PROPERTIES:" (0+ (in " \t")) "\n"
;; Node properties.
(*? (0+ (in " \t")) ":" (+ (not (in " \t\n:"))) ":" (* nonl) "\n")
;; Drawer end line.
(0+ (in " \t")) ":END:" (0+ (in " \t")) eol)
"Matches an entire property drawer.")
(defconst org-clock-drawer-re