mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-25 15:02:53 +00:00
org-element-entity-parser: Refactor entity regexp using `rx'
* lisp/org-element.el (org-element-entity-parser): Rewrite entity regexp using more readable `rx' form. * testing/lisp/test-org-element.el (test-org-element/entity-parser): Add new test cases for whitespace entities.
This commit is contained in:
parent
627097c7d3
commit
e34d7781f0
|
@ -3466,7 +3466,17 @@ properties. Otherwise, return nil.
|
|||
|
||||
Assume point is at the beginning of the entity."
|
||||
(catch 'no-object
|
||||
(when (looking-at "\\\\\\(?:\\(?1:_ +\\)\\|\\(?1:there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\(?2:$\\|{}\\|[^[:alpha:]]\\)\\)")
|
||||
(when (looking-at
|
||||
(rx "\\"
|
||||
(or
|
||||
(group-n 1 (seq "_" (1+ " ")))
|
||||
(seq
|
||||
(group-n 1
|
||||
(or "there4"
|
||||
(seq "sup" (in "123"))
|
||||
(seq "frac" (in "13") (in "24"))
|
||||
(1+ (in "a-zA-Z"))))
|
||||
(group-n 2 (or eol "{}" (not letter)))))))
|
||||
(save-excursion
|
||||
(let* ((value (or (org-entity-get (match-string 1))
|
||||
(throw 'no-object nil)))
|
||||
|
|
|
@ -1318,6 +1318,21 @@ CLOCK: [2023-10-13 Fri 14:40]--[2023-10-13 Fri 14:51] => 0:11"
|
|||
(should
|
||||
(org-test-with-temp-text "\\sin"
|
||||
(org-element-map (org-element-parse-buffer) 'entity 'identity)))
|
||||
;; Special case: space-based entities.
|
||||
(should
|
||||
(equal
|
||||
"_ "
|
||||
;; Space after entity must be a part of its name.
|
||||
(org-test-with-temp-text "\\_ Foo"
|
||||
(org-element-property
|
||||
:name
|
||||
(car (org-element-map (org-element-parse-buffer) 'entity 'identity))))))
|
||||
(should-not
|
||||
;; {} is not a part of whitespace entity name.
|
||||
(org-test-with-temp-text "\\_ {}Foo"
|
||||
(org-element-property
|
||||
:bracketsp
|
||||
(car (org-element-map (org-element-parse-buffer) 'entity 'identity)))))
|
||||
;; With brackets.
|
||||
(should
|
||||
(org-element-property
|
||||
|
|
Loading…
Reference in a new issue