org-element: Fix parsing of orphaned keyword at the end of an element
* lisp/org-element.el (org-element--current-element): Add a limit argument. (org-element--collect-affiliated-keywords): Fix parsing of orphaned keyword at the end of an element. * testing/lisp/test-org-element.el: Add test.
This commit is contained in:
parent
4b0ceee39a
commit
94bcc7e282
|
@ -3762,8 +3762,13 @@ element it has to parse."
|
|||
((org-at-heading-p)
|
||||
(org-element-inlinetask-parser limit raw-secondary-p))
|
||||
;; From there, elements can have affiliated keywords.
|
||||
(t (let ((affiliated (org-element--collect-affiliated-keywords)))
|
||||
(t (let ((affiliated (org-element--collect-affiliated-keywords limit)))
|
||||
(cond
|
||||
;; Jumping over affiliated keywords put point off-limits.
|
||||
;; Parse them as regular keywords.
|
||||
((>= (point) limit)
|
||||
(goto-char (car affiliated))
|
||||
(org-element-keyword-parser limit nil))
|
||||
;; LaTeX Environment.
|
||||
((looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}[ \t]*$")
|
||||
(org-element-latex-environment-parser limit affiliated))
|
||||
|
@ -3824,8 +3829,8 @@ element it has to parse."
|
|||
;; that element, and, in the meantime, collect information they give
|
||||
;; into appropriate properties. Hence the following function.
|
||||
|
||||
(defun org-element--collect-affiliated-keywords ()
|
||||
"Collect affiliated keywords from point.
|
||||
(defun org-element--collect-affiliated-keywords (limit)
|
||||
"Collect affiliated keywords from point down to LIMIT.
|
||||
|
||||
Return a list whose CAR is the position at the first of them and
|
||||
CDR a plist of keywords and values and move point to the
|
||||
|
@ -3841,7 +3846,7 @@ position of point and CDR is nil."
|
|||
;; keywords value.
|
||||
(restrict (org-element-restriction 'keyword))
|
||||
output)
|
||||
(while (and (not (eobp)) (looking-at org-element--affiliated-re))
|
||||
(while (and (< (point) limit) (looking-at org-element--affiliated-re))
|
||||
(let* ((raw-kwd (upcase (match-string 1)))
|
||||
;; Apply translation to RAW-KWD. From there, KWD is
|
||||
;; the official keyword.
|
||||
|
|
|
@ -215,7 +215,17 @@ Some other text
|
|||
(equal
|
||||
'((("l1")) (nil "s1"))
|
||||
(org-test-with-temp-text "#+CAPTION[s1]:\n#+CAPTION: l1\nParagraph"
|
||||
(org-element-property :caption (org-element-at-point))))))
|
||||
(org-element-property :caption (org-element-at-point)))))
|
||||
;; Corner case: orphaned keyword at the end of an element.
|
||||
(should
|
||||
(eq 'keyword
|
||||
(org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
|
||||
(progn (search-forward "name")
|
||||
(org-element-type (org-element-at-point))))))
|
||||
(should-not
|
||||
(org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
|
||||
(progn (search-forward "Some")
|
||||
(org-element-property :name (org-element-at-point))))))
|
||||
|
||||
|
||||
;;;; Babel Call
|
||||
|
|
Loading…
Reference in New Issue