From d6a169a82c81e3135c4d0ab6583ab99e48c3db1e Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 5 Dec 2015 11:55:02 +0100 Subject: [PATCH] org-capture: Fix cache in capture buffers * lisp/org-capture.el (org-capture-steal-local-variables): Remove function. (org-capture-fill-template): Apply removal. Use `org-clone-local-variables' instead. Focus on Org specific variables. * lisp/org.el (org-get-local-variables): (org-clone-local-variables): Ignore internal local variables, whose value is probably tied to their respective buffer. In particular, this prevents cache related variables from being copied. * lisp/org-indent.el (org-indent--initial-marker): Renamed from `org-indent-initial-marker'. Marking it as internal prevents it from being copied by `org-clone-local-variables' and alike. (org-indent-mode): (org-indent-initialize-buffer): Apply renaming. --- lisp/org-capture.el | 21 +++++++------------ lisp/org-indent.el | 16 +++++++-------- lisp/org.el | 49 ++++++++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 45 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 6259c0598..f92ea35a8 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -47,19 +47,18 @@ ;;; Code: -(eval-when-compile - (require 'cl)) +(require 'cl-lib) (require 'org) +(declare-function org-at-encrypted-entry-p "org-crypt" ()) (declare-function org-datetree-find-date-create "org-datetree" (date &optional keep-restriction)) -(declare-function org-table-analyze "org-table" ()) -(declare-function org-table-goto-line "org-table" (N)) +(declare-function org-decrypt-entry "org-crypt" ()) +(declare-function org-encrypt-entry "org-crypt" ()) (declare-function org-pop-to-buffer-same-window "org-compat" (&optional buffer-or-name norecord label)) -(declare-function org-at-encrypted-entry-p "org-crypt" ()) -(declare-function org-encrypt-entry "org-crypt" ()) -(declare-function org-decrypt-entry "org-crypt" ()) +(declare-function org-table-analyze "org-table" ()) +(declare-function org-table-goto-line "org-table" (N)) (defvar org-remember-default-headline) (defvar org-remember-templates) @@ -1004,12 +1003,6 @@ a string, return it. However, if it is the empty string, return (progn (org-capture-put :new-buffer t) (find-file-noselect (expand-file-name file org-directory))))) -(defun org-capture-steal-local-variables (buffer) - "Install Org-mode local variables of BUFFER." - (mapc (lambda (v) - (ignore-errors (set (make-local-variable (car v)) (cdr v)))) - (buffer-local-variables buffer))) - (defun org-capture-place-template (&optional inhibit-wconf-store) "Insert the template at the target location, and display the buffer. When `inhibit-wconf-store', don't store the window configuration, as it @@ -1603,7 +1596,7 @@ The template may still contain \"%?\" for cursor positioning." ;; is to support completion in interactive prompts (insert template) (goto-char (point-min)) - (org-capture-steal-local-variables buffer) + (org-clone-local-variables buffer "\\`org-") (setq buffer-file-name nil) (setq mark-active nil) diff --git a/lisp/org-indent.el b/lisp/org-indent.el index 7f0e980b1..dc05757e8 100644 --- a/lisp/org-indent.el +++ b/lisp/org-indent.el @@ -69,7 +69,7 @@ Delay used when the buffer to initialize is current.") Delay used when the buffer to initialize isn't current.") (defvar org-indent-agent-resume-delay '(0 0 100000) "Minimal time for other idle processes before switching back to agent.") -(defvar org-indent-initial-marker nil +(defvar org-indent--initial-marker nil "Position of initialization before interrupt. This is used locally in each buffer being initialized.") (defvar org-hide-leading-stars-before-indent-mode nil @@ -140,7 +140,7 @@ during idle time." (org-indent-mode ;; mode was turned on. (setq-local indent-tabs-mode nil) - (setq-local org-indent-initial-marker (copy-marker 1)) + (setq-local org-indent--initial-marker (copy-marker 1)) (when org-indent-mode-turns-off-org-adapt-indentation (setq-local org-adapt-indentation nil)) (when org-indent-mode-turns-on-hiding-stars @@ -170,8 +170,8 @@ during idle time." (kill-local-variable 'org-adapt-indentation) (setq org-indent-agentized-buffers (delq (current-buffer) org-indent-agentized-buffers)) - (when (markerp org-indent-initial-marker) - (set-marker org-indent-initial-marker nil)) + (when (markerp org-indent--initial-marker) + (set-marker org-indent--initial-marker nil)) (when (boundp 'org-hide-leading-stars-before-indent-mode) (setq-local org-hide-leading-stars org-hide-leading-stars-before-indent-mode)) @@ -234,13 +234,13 @@ a time value." (let ((interruptp ;; Always nil unless interrupted. (catch 'interrupt - (and org-indent-initial-marker - (marker-position org-indent-initial-marker) - (org-indent-add-properties org-indent-initial-marker + (and org-indent--initial-marker + (marker-position org-indent--initial-marker) + (org-indent-add-properties org-indent--initial-marker (point-max) delay) nil)))) - (move-marker org-indent-initial-marker interruptp) + (move-marker org-indent--initial-marker interruptp) ;; Job is complete: un-agentize buffer. (unless interruptp (setq org-indent-agentized-buffers diff --git a/lisp/org.el b/lisp/org.el index 7f2d965ea..f63dc4503 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -9421,37 +9421,40 @@ Possible values in the list of contexts are `table', `headline', and `item'." (defun org-get-local-variables () "Return a list of all local variables in an Org mode buffer." - (let (varlist) - (with-current-buffer (get-buffer-create "*Org tmp*") - (erase-buffer) - (org-mode) - (setq varlist (buffer-local-variables))) - (kill-buffer "*Org tmp*") + (let ((varlist + (prog1 (with-current-buffer (get-buffer-create "*Org tmp*") + (erase-buffer) + (org-mode) + (buffer-local-variables)) + (kill-buffer "*Org tmp*")))) (delq nil (mapcar (lambda (x) - (setq x - (if (symbolp x) - (list x) - (list (car x) (cdr x)))) - (if (and (not (get (car x) 'org-state)) - (string-match - "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)" - (symbol-name (car x)))) - x nil)) + (let* ((binding (if (symbolp x) (list x) (list (car x) (cdr x)))) + (name (car binding))) + (and (not (get name 'org-state)) + ;; Ignore internal local variables, since those + ;; are likely variables that are not meant to be + ;; copied. + (not (string-match-p "--" (symbol-name name))) + (string-match-p + "\\`\\(org-\\|orgtbl-\\|outline-\\|comment-\\|\ +paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)" + (symbol-name name)) + x))) varlist)))) (defun org-clone-local-variables (from-buffer &optional regexp) "Clone local variables from FROM-BUFFER. Optional argument REGEXP selects variables to clone." - (mapc - (lambda (pair) - (and (symbolp (car pair)) - (or (null regexp) - (string-match regexp (symbol-name (car pair)))) - (set (make-local-variable (car pair)) - (cdr pair)))) - (buffer-local-variables from-buffer))) + (dolist (pair (buffer-local-variables from-buffer)) + (let ((name (car pair))) + (when (and (symbolp name) + ;; Ignore internal local variables, since those are + ;; likely variables that are not meant to be copied. + (not (string-match-p "--" (symbol-name name))) + (or (null regexp) (string-match regexp (symbol-name name)))) + (set (make-local-variable name) (cdr pair)))))) ;;;###autoload (defun org-run-like-in-org-mode (cmd)