From 94bcc7e2828a42d5448757ab28cadbf663c9ff6d Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 11 Feb 2013 14:42:16 +0100 Subject: [PATCH] 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. --- lisp/org-element.el | 13 +++++++++---- testing/lisp/test-org-element.el | 12 +++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 4a73e2692..703b35571 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -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. diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index ab5ba6092..902198ab8 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -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