From 2824502e2ebe2744e5f53acabb5b3b04f9a391b9 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 28 Jun 2014 00:28:45 +0200 Subject: [PATCH] org-element: Fix cache corruption when altering a drawer * lisp/org-element.el (org-element--cache-submit-request): Correctly update cache when changes alter the contents of a greater element (e.g. a property drawer). Thanks to Alan Schmitt for reporting it. http://permalink.gmane.org/gmane.emacs.orgmode/88086 --- lisp/org-element.el | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 242c97f7e..11f142b24 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5494,11 +5494,20 @@ change, as an integer." (progn (incf (aref next 2) offset) (incf (aref next 3) offset) - (when (> (aref next 1) beg) - (let ((first (org-element--cache-for-removal beg end offset))) - (when first - (aset next 0 (org-element--cache-key first)) - (aset next 1 (org-element-property :begin first)))))) + ;; If last changes happened before old ones, we need to + ;; recompute the key of the first element to remove. + ;; Otherwise, we need to extend boundaries of robust parents + ;; (see `org-element--cache-for-removal'), if any. + (let ((first-beg (aref next 1))) + (if (> first-beg beg) + (let ((first (org-element--cache-for-removal beg end offset))) + (when first + (aset next 0 (org-element--cache-key first)) + (aset next 1 (org-element-property :begin first)))) + (let ((up (org-element--cache-find first-beg))) + (while (setq up (org-element-property :parent up)) + (org-element--cache-shift-positions + up offset '(:contents-end :end))))))) ;; Ensure cache is correct up to END. Also make sure that NEXT, ;; if any, is no longer a 0-phase request, thus ensuring that ;; phases are properly ordered. We need to provide OFFSET as