org-element: Fix `org-element-context' when in recursive objects
* lisp/org-element.el (org-element-context, org-element--get-next-object-candidates): Fix `org-element-context'. In particular, the restrictions for an object may be different from those of its container (i.e. table rows and table cells). * testing/lisp/test-org-element.el: Add tests.
This commit is contained in:
parent
21478e1733
commit
daf8cf030c
|
@ -3857,6 +3857,9 @@ Return value is an alist whose CAR is position and CDR the object
|
||||||
type, as a symbol.
|
type, as a symbol.
|
||||||
|
|
||||||
OBJECTS is the previous candidates alist."
|
OBJECTS is the previous candidates alist."
|
||||||
|
;; Filter out any object found but not belonging to RESTRICTION.
|
||||||
|
(setq objects (org-remove-if-not (lambda (obj) (memq (car obj) restriction))
|
||||||
|
objects))
|
||||||
(let (next-candidates types-to-search)
|
(let (next-candidates types-to-search)
|
||||||
;; If no previous result, search every object type in RESTRICTION.
|
;; If no previous result, search every object type in RESTRICTION.
|
||||||
;; Otherwise, keep potential candidates (old objects located after
|
;; Otherwise, keep potential candidates (old objects located after
|
||||||
|
@ -4254,7 +4257,7 @@ and :post-blank properties."
|
||||||
(progn (beginning-of-line)
|
(progn (beginning-of-line)
|
||||||
(skip-chars-forward "* ")
|
(skip-chars-forward "* ")
|
||||||
(setq end (point-at-eol))))
|
(setq end (point-at-eol))))
|
||||||
(and (memq type '(paragraph table-cell verse-block))
|
(and (memq type '(paragraph table-row verse-block))
|
||||||
(let ((cbeg (org-element-property
|
(let ((cbeg (org-element-property
|
||||||
:contents-begin element))
|
:contents-begin element))
|
||||||
(cend (org-element-property
|
(cend (org-element-property
|
||||||
|
@ -4273,7 +4276,7 @@ and :post-blank properties."
|
||||||
candidates)))
|
candidates)))
|
||||||
;; If ORIGIN is before next object in element, there's
|
;; If ORIGIN is before next object in element, there's
|
||||||
;; no point in looking further.
|
;; no point in looking further.
|
||||||
(if (> (cdr closest-cand) origin) (throw 'exit element)
|
(if (> (cdr closest-cand) origin) (throw 'exit parent)
|
||||||
(let* ((object
|
(let* ((object
|
||||||
(progn (goto-char (cdr closest-cand))
|
(progn (goto-char (cdr closest-cand))
|
||||||
(funcall (intern (format "org-element-%s-parser"
|
(funcall (intern (format "org-element-%s-parser"
|
||||||
|
@ -4293,7 +4296,9 @@ and :post-blank properties."
|
||||||
;; search to the end of its contents.
|
;; search to the end of its contents.
|
||||||
(t (goto-char cbeg)
|
(t (goto-char cbeg)
|
||||||
(org-element-put-property object :parent parent)
|
(org-element-put-property object :parent parent)
|
||||||
(setq parent object end cend)))))))
|
(setq parent object
|
||||||
|
restriction (org-element-restriction object)
|
||||||
|
end cend)))))))
|
||||||
parent))))))
|
parent))))))
|
||||||
|
|
||||||
(defsubst org-element-nested-p (elem-A elem-B)
|
(defsubst org-element-nested-p (elem-A elem-B)
|
||||||
|
|
|
@ -2440,6 +2440,17 @@ Paragraph \\alpha."
|
||||||
(org-test-with-temp-text "* Headline _with_ underlining"
|
(org-test-with-temp-text "* Headline _with_ underlining"
|
||||||
(progn (search-forward "w")
|
(progn (search-forward "w")
|
||||||
(org-element-type (org-element-context))))))
|
(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))))))
|
||||||
|
(should
|
||||||
|
(eq 'table-cell
|
||||||
|
(org-test-with-temp-text "| a | b {{{macro}}} |"
|
||||||
|
(progn (search-forward "b")
|
||||||
|
(org-element-type (org-element-context))))))
|
||||||
;; Correctly set `:parent' property.
|
;; Correctly set `:parent' property.
|
||||||
(should
|
(should
|
||||||
(eq 'paragraph
|
(eq 'paragraph
|
||||||
|
|
Loading…
Reference in New Issue