org-element: Fix cache bug

* lisp/org-element.el (org-element--cache-for-removal): Be more
  careful when altering a properties drawer.

* testing/lisp/test-org-element.el (test-org-element/cache): Add test.
This commit is contained in:
Nicolas Goaziou 2015-04-06 00:37:49 +02:00
parent 789ddf155a
commit 1ba8413b0a
2 changed files with 23 additions and 7 deletions

View File

@ -5451,13 +5451,20 @@ changes."
(let ((up before)
(robust-flag t))
(while up
(if (and (memq (org-element-type up)
'(center-block drawer dynamic-block
quote-block special-block))
(let ((cbeg (org-element-property :contents-begin up)))
(and cbeg
(<= cbeg beg)
(> (org-element-property :contents-end up) end))))
(if (let ((type (org-element-type up)))
(and (or (memq type '(center-block dynamic-block quote-block
special-block))
;; Drawers named "PROPERTIES" are probably
;; a properties drawer being edited. Force
;; parsing to check if editing is over.
(and (eq type 'drawer)
(not (string=
(org-element-property :drawer-name up)
"PROPERTIES"))))
(let ((cbeg (org-element-property :contents-begin up)))
(and cbeg
(<= cbeg beg)
(> (org-element-property :contents-end up) end)))))
;; UP is a robust greater element containing changes.
;; We only need to extend its ending boundaries.
(org-element--cache-shift-positions

View File

@ -3488,6 +3488,15 @@ Text
(search-forward "# ")
(delete-char -1)
(search-backward "Para1")
(org-element-type (org-element-at-point))))))
;; Corner case: watch out drawers named "PROPERTIES" as they are
;; fragile, unlike to other drawers.
(should
(eq 'node-property
(org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A<point>\n:END:"
(let ((org-element-use-cache t))
(org-element-at-point)
(insert "+:")
(org-element-type (org-element-at-point)))))))