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) (if (not (member (org-element-property :key element)
org-element-document-properties)) org-element-document-properties))
(throw 'objects-forbidden element) (throw 'objects-forbidden element)
(beginning-of-line) (goto-char (org-element-property :begin element))
(search-forward ":") (search-forward ":")
(if (and (>= origin (point)) (< origin (line-end-position))) (if (and (>= origin (point)) (< origin (line-end-position)))
(narrow-to-region (point) (line-end-position)) (narrow-to-region (point) (line-end-position))

View file

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