mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 21:37:50 +00:00
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-at-heading-p)
|
||||||
(org-element-inlinetask-parser limit raw-secondary-p))
|
(org-element-inlinetask-parser limit raw-secondary-p))
|
||||||
;; From there, elements can have affiliated keywords.
|
;; 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
|
(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.
|
;; LaTeX Environment.
|
||||||
((looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}[ \t]*$")
|
((looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}[ \t]*$")
|
||||||
(org-element-latex-environment-parser limit affiliated))
|
(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
|
;; that element, and, in the meantime, collect information they give
|
||||||
;; into appropriate properties. Hence the following function.
|
;; into appropriate properties. Hence the following function.
|
||||||
|
|
||||||
(defun org-element--collect-affiliated-keywords ()
|
(defun org-element--collect-affiliated-keywords (limit)
|
||||||
"Collect affiliated keywords from point.
|
"Collect affiliated keywords from point down to LIMIT.
|
||||||
|
|
||||||
Return a list whose CAR is the position at the first of them and
|
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
|
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.
|
;; keywords value.
|
||||||
(restrict (org-element-restriction 'keyword))
|
(restrict (org-element-restriction 'keyword))
|
||||||
output)
|
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)))
|
(let* ((raw-kwd (upcase (match-string 1)))
|
||||||
;; Apply translation to RAW-KWD. From there, KWD is
|
;; Apply translation to RAW-KWD. From there, KWD is
|
||||||
;; the official keyword.
|
;; the official keyword.
|
||||||
|
|
|
@ -215,7 +215,17 @@ Some other text
|
||||||
(equal
|
(equal
|
||||||
'((("l1")) (nil "s1"))
|
'((("l1")) (nil "s1"))
|
||||||
(org-test-with-temp-text "#+CAPTION[s1]:\n#+CAPTION: l1\nParagraph"
|
(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
|
;;;; Babel Call
|
||||||
|
|
Loading…
Reference in a new issue