org-element: Fix 'search failed ":"' error

* lisp/org-element.el (org-element-context): Fix 'search failed ":"'
  error when point is on a blank line after a keyword.

* testing/lisp/test-org-element.el (test-org-element/context): Add
  tests.
This commit is contained in:
Nicolas Goaziou 2014-11-18 19:44:46 +01:00
parent 59111b77ef
commit 4f31b68e8f
2 changed files with 11 additions and 4 deletions

View File

@ -4887,7 +4887,7 @@ Providing it allows for quicker computation."
(if (not (member (org-element-property :key element)
org-element-document-properties))
(throw 'objects-forbidden element)
(beginning-of-line)
(goto-char (org-element-property :begin element))
(search-forward ":")
(if (and (>= origin (point)) (< origin (line-end-position)))
(narrow-to-region (point) (line-end-position))

View File

@ -3087,9 +3087,16 @@ Text
;; Find objects in document keywords.
(should
(eq 'macro
(org-test-with-temp-text "#+DATE: {{{macro}}}"
(progn (search-forward "{")
(org-element-type (org-element-context))))))
(org-test-with-temp-text "#+DATE: <point>{{{macro}}}"
(org-element-type (org-element-context)))))
(should-not
(eq 'macro
(org-test-with-temp-text "#+DATE: {{{macro}}}\n<point>"
(org-element-type (org-element-context)))))
(should-not
(eq 'macro
(org-test-with-temp-text "#+RANDOM_KEYWORD: <point>{{{macro}}}"
(org-element-type (org-element-context)))))
;; Do not find objects in table rules.
(should
(eq 'table-row