From 69773248c505e6041bee9c039debe8f482d11d1a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 23 Jun 2014 12:28:11 +0200 Subject: [PATCH] org-element: Fix cache * lisp/org-element.el (org-element--cache-after-change): Preserve match data. Thanks to Matt Lundin for reporting it. http://permalink.gmane.org/gmane.emacs.orgmode/87871 --- lisp/org-element.el | 71 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index abf5f6205..c140b388d 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5449,47 +5449,46 @@ text. See `before-change-functions' for more information." BEG and END are the beginning and end of the range of changed text, and the length in bytes of the pre-change text replaced by that range. See `after-change-functions' for more information." - (let ((inhibit-quit t)) - (when (org-element--cache-active-p) - (org-with-wide-buffer - (goto-char beg) - (beginning-of-line) + (when (org-element--cache-active-p) + (org-with-wide-buffer + (goto-char beg) + (beginning-of-line) + (save-match-data (let ((top (point)) (bottom (save-excursion (goto-char end) (line-end-position)))) (org-with-limited-levels - (save-match-data - ;; Determine if modified area needs to be extended, - ;; according to both previous and current state. We make - ;; a special case for headline editing: if a headline is - ;; modified but not removed, do not extend. - (when (let ((previous-state org-element--cache-change-warning) - (sensitive-re - (concat "\\(" org-outline-regexp-bol "\\)" "\\|" - org-element--cache-closing-line "\\|" - org-element--cache-opening-line)) - (case-fold-search t)) - (cond ((eq previous-state t)) - ((not (re-search-forward sensitive-re bottom t)) - (eq previous-state 'headline)) - ((match-beginning 1) - (or (not (eq previous-state 'headline)) - (and (progn (goto-char bottom) - (re-search-backward - sensitive-re (match-end 1) t)) - (not (match-beginning 1))))) - (t))) - ;; Effectively extend modified area. - (setq top (progn (goto-char top) - (when (outline-previous-heading) (forward-line)) - (point))) - (setq bottom (progn (goto-char bottom) - (if (outline-next-heading) (1- (point)) - (point))))))) + ;; Determine if modified area needs to be extended, + ;; according to both previous and current state. We make + ;; a special case for headline editing: if a headline is + ;; modified but not removed, do not extend. + (when (let ((previous-state org-element--cache-change-warning) + (sensitive-re + (concat "\\(" org-outline-regexp-bol "\\)" "\\|" + org-element--cache-closing-line "\\|" + org-element--cache-opening-line)) + (case-fold-search t)) + (cond ((eq previous-state t)) + ((not (re-search-forward sensitive-re bottom t)) + (eq previous-state 'headline)) + ((match-beginning 1) + (or (not (eq previous-state 'headline)) + (and (progn (goto-char bottom) + (re-search-backward + sensitive-re (match-end 1) t)) + (not (match-beginning 1))))) + (t))) + ;; Effectively extend modified area. + (setq top (progn (goto-char top) + (when (outline-previous-heading) (forward-line)) + (point))) + (setq bottom (progn (goto-char bottom) + (if (outline-next-heading) (1- (point)) + (point)))))) ;; Store synchronization request. (let ((offset (- end beg pre))) - (org-element--cache-submit-request top (- bottom offset) offset)))) - ;; Activate a timer to process the request during idle time. - (org-element--cache-set-timer (current-buffer))))) + (org-element--cache-submit-request top (- bottom offset) offset))))) + ;; Activate a timer to process the request during idle time. + (org-element--cache-set-timer (current-buffer)))) (defun org-element--cache-for-removal (beg end offset) "Return first element to remove from cache.