summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-02-11 09:47:54 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-02-11 09:47:54 +0100
commit9f737bdf1408d29a618cdab71eefe379b9f13476 (patch)
tree35e487b4548b19c9d6817399a69a2a0b52570835
parent6e88bf07d1f23cf59038744f620fb3056cf0dd63 (diff)
downloadorg-mode-9f737bdf1408d29a618cdab71eefe379b9f13476.tar.gz
org-element: Fix search failed error in `org-element-context'
* lisp/org-element.el (org-element-context): Make sure point is on tag line before searching for it. * testing/lisp/test-org-element.el (test-org-element/context): Add test. Small refactoring. Reported-by: Kaushal Modi <kaushal.modi@gmail.com> <http://permalink.gmane.org/gmane.emacs.orgmode/105018>
-rw-r--r--lisp/org-element.el9
-rw-r--r--testing/lisp/test-org-element.el74
2 files changed, 41 insertions, 42 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 1438a0f..2576c3f 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -5735,15 +5735,15 @@ Providing it allows for quicker computation."
(org-with-wide-buffer
(let* ((pos (point))
(element (or element (org-element-at-point)))
- (type (org-element-type element)))
+ (type (org-element-type element))
+ (post (org-element-property :post-affiliated element)))
;; If point is inside an element containing objects or
;; a secondary string, narrow buffer to the container and
;; proceed with parsing. Otherwise, return ELEMENT.
(cond
;; At a parsed affiliated keyword, check if we're inside main
;; or dual value.
- ((let ((post (org-element-property :post-affiliated element)))
- (and post (< pos post)))
+ ((and post (< pos post))
(beginning-of-line)
(let ((case-fold-search t)) (looking-at org-element--affiliated-re))
(cond
@@ -5762,7 +5762,8 @@ Providing it allows for quicker computation."
;; At an item, objects can only be located within tag, if any.
((eq type 'item)
(let ((tag (org-element-property :tag element)))
- (if (not tag) (throw 'objects-forbidden element)
+ (if (or (not tag) (/= (line-beginning-position) post))
+ (throw 'objects-forbidden element)
(beginning-of-line)
(search-forward tag (line-end-position))
(goto-char (match-beginning 0))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 4d4adec..b2ccb30 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -3332,36 +3332,43 @@ Text
;; Return closest object containing point.
(should
(eq 'underline
- (org-test-with-temp-text "Some *text with _underline_ text*"
- (progn (search-forward "under")
- (org-element-type (org-element-context))))))
+ (org-test-with-temp-text "Some *text with _under<point>line_ text*"
+ (org-element-type (org-element-context)))))
;; Find objects in secondary strings.
(should
(eq 'underline
- (org-test-with-temp-text "* Headline _with_ underlining"
- (progn (search-forward "w")
- (org-element-type (org-element-context))))))
+ (org-test-with-temp-text "* Headline _<point>with_ underlining"
+ (org-element-type (org-element-context)))))
;; Find objects in objects.
(should
(eq 'macro
- (org-test-with-temp-text "| a | {{{macro}}} |"
- (progn (search-forward "{")
- (org-element-type (org-element-context))))))
+ (org-test-with-temp-text "| a | {<point>{{macro}}} |"
+ (org-element-type (org-element-context)))))
(should
(eq 'table-cell
- (org-test-with-temp-text "| a | b {{{macro}}} |"
- (progn (search-forward "b")
- (org-element-type (org-element-context))))))
+ (org-test-with-temp-text "| a | b<point> {{{macro}}} |"
+ (org-element-type (org-element-context)))))
;; Find objects in planning lines.
(should
(eq 'timestamp
- (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>"
- (search-forward "2012")
+ (org-test-with-temp-text "* H\n SCHEDULED: <2012<point>-03-29 thu.>"
(org-element-type (org-element-context)))))
(should-not
(eq 'timestamp
- (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>"
- (search-forward "SCHEDULED")
+ (org-test-with-temp-text "* H\n SCHEDULED<point>: <2012-03-29 thu.>"
+ (org-element-type (org-element-context)))))
+ ;; Find objects in item tags.
+ (should
+ (eq 'bold
+ (org-test-with-temp-text "- *bo<point>ld* ::"
+ (org-element-type (org-element-context)))))
+ (should-not
+ (eq 'bold
+ (org-test-with-temp-text "- *bold* ::<point>"
+ (org-element-type (org-element-context)))))
+ (should-not
+ (eq 'bold
+ (org-test-with-temp-text "- *bold* ::\n<point>"
(org-element-type (org-element-context)))))
;; Do not find objects in table rules.
(should
@@ -3371,14 +3378,12 @@ Text
;; Find objects in parsed affiliated keywords.
(should
(eq 'macro
- (org-test-with-temp-text "#+CAPTION: {{{macro}}}\n| a | b |."
- (progn (search-forward "{")
- (org-element-type (org-element-context))))))
+ (org-test-with-temp-text "#+CAPTION: {<point>{{macro}}}\n| a | b |"
+ (org-element-type (org-element-context)))))
(should
(eq 'bold
- (org-test-with-temp-text "#+caption: *bold*\nParagraph"
- (progn (search-forward "*")
- (org-element-type (org-element-context))))))
+ (org-test-with-temp-text "#+caption: *<point>bold*\nParagraph"
+ (org-element-type (org-element-context)))))
;; Find objects at the end of buffer.
(should
(eq 'bold
@@ -3388,35 +3393,28 @@ Text
;; Correctly set `:parent' property.
(should
(eq 'paragraph
- (org-test-with-temp-text "Some *bold* text"
- (progn (search-forward "bold")
- (org-element-type
- (org-element-property :parent (org-element-context)))))))
+ (org-test-with-temp-text "Some *bold<point>* text"
+ (org-element-type
+ (org-element-property :parent (org-element-context))))))
;; Between two objects, return the second one.
(should
(eq 'macro
- (org-test-with-temp-text "<<target>>{{{test}}}"
- (progn (search-forward "{")
- (backward-char)
- (org-element-type (org-element-context))))))
+ (org-test-with-temp-text "<<target>><point>{{{test}}}"
+ (org-element-type (org-element-context)))))
;; Test optional argument.
(should
(eq 'underline
- (org-test-with-temp-text "Some *text with _underline_ text*"
- (progn
- (search-forward "under")
- (org-element-type (org-element-context (org-element-at-point)))))))
+ (org-test-with-temp-text "Some *text with _under<point>line_ text*"
+ (org-element-type (org-element-context (org-element-at-point))))))
;; Special case: bold object at the beginning of a headline.
(should
(eq 'bold
- (org-test-with-temp-text "* *bold*"
- (search-forward "bo")
+ (org-test-with-temp-text "* *bo<point>ld*"
(org-element-type (org-element-context)))))
;; Special case: incomplete cell at the end of a table row.
(should
(eq 'table-cell
- (org-test-with-temp-text "|a|b|c"
- (goto-char (point-max))
+ (org-test-with-temp-text "|a|b|c<point>"
(org-element-type (org-element-context)))))
;; Special case: objects in inline footnotes.
(should