瀏覽代碼

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.
Nicolas Goaziou 10 年之前
父節點
當前提交
d6a169a82c
共有 3 個文件被更改,包括 41 次插入45 次删除
  1. 7 14
      lisp/org-capture.el
  2. 8 8
      lisp/org-indent.el
  3. 26 23
      lisp/org.el

+ 7 - 14
lisp/org-capture.el

@@ -47,19 +47,18 @@
 
 
 ;;; Code:
 ;;; Code:
 
 
-(eval-when-compile
-  (require 'cl))
+(require 'cl-lib)
 (require 'org)
 (require 'org)
 
 
+(declare-function org-at-encrypted-entry-p "org-crypt" ())
 (declare-function org-datetree-find-date-create "org-datetree"
 (declare-function org-datetree-find-date-create "org-datetree"
 		  (date &optional keep-restriction))
 		  (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"
 (declare-function org-pop-to-buffer-same-window "org-compat"
 		  (&optional buffer-or-name norecord label))
 		  (&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-default-headline)
 (defvar org-remember-templates)
 (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)
       (progn (org-capture-put :new-buffer t)
 	     (find-file-noselect (expand-file-name file org-directory)))))
 	     (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)
 (defun org-capture-place-template (&optional inhibit-wconf-store)
   "Insert the template at the target location, and display the buffer.
   "Insert the template at the target location, and display the buffer.
 When `inhibit-wconf-store', don't store the window configuration, as it
 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
       ;; is to support completion in interactive prompts
       (insert template)
       (insert template)
       (goto-char (point-min))
       (goto-char (point-min))
-      (org-capture-steal-local-variables buffer)
+      (org-clone-local-variables buffer "\\`org-")
       (setq buffer-file-name nil)
       (setq buffer-file-name nil)
       (setq mark-active nil)
       (setq mark-active nil)
 
 

+ 8 - 8
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.")
 Delay used when the buffer to initialize isn't current.")
 (defvar org-indent-agent-resume-delay '(0 0 100000)
 (defvar org-indent-agent-resume-delay '(0 0 100000)
   "Minimal time for other idle processes before switching back to agent.")
   "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.
   "Position of initialization before interrupt.
 This is used locally in each buffer being initialized.")
 This is used locally in each buffer being initialized.")
 (defvar org-hide-leading-stars-before-indent-mode nil
 (defvar org-hide-leading-stars-before-indent-mode nil
@@ -140,7 +140,7 @@ during idle time."
    (org-indent-mode
    (org-indent-mode
     ;; mode was turned on.
     ;; mode was turned on.
     (setq-local indent-tabs-mode nil)
     (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
     (when org-indent-mode-turns-off-org-adapt-indentation
       (setq-local org-adapt-indentation nil))
       (setq-local org-adapt-indentation nil))
     (when org-indent-mode-turns-on-hiding-stars
     (when org-indent-mode-turns-on-hiding-stars
@@ -170,8 +170,8 @@ during idle time."
     (kill-local-variable 'org-adapt-indentation)
     (kill-local-variable 'org-adapt-indentation)
     (setq org-indent-agentized-buffers
     (setq org-indent-agentized-buffers
 	  (delq (current-buffer) 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)
     (when (boundp 'org-hide-leading-stars-before-indent-mode)
       (setq-local org-hide-leading-stars
       (setq-local org-hide-leading-stars
 		  org-hide-leading-stars-before-indent-mode))
 		  org-hide-leading-stars-before-indent-mode))
@@ -234,13 +234,13 @@ a time value."
        (let ((interruptp
        (let ((interruptp
 	      ;; Always nil unless interrupted.
 	      ;; Always nil unless interrupted.
 	      (catch 'interrupt
 	      (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)
 						(point-max)
 						delay)
 						delay)
 		     nil))))
 		     nil))))
-	 (move-marker org-indent-initial-marker interruptp)
+	 (move-marker org-indent--initial-marker interruptp)
 	 ;; Job is complete: un-agentize buffer.
 	 ;; Job is complete: un-agentize buffer.
 	 (unless interruptp
 	 (unless interruptp
 	   (setq org-indent-agentized-buffers
 	   (setq org-indent-agentized-buffers

+ 26 - 23
lisp/org.el

@@ -9421,37 +9421,40 @@ Possible values in the list of contexts are `table', `headline', and `item'."
 
 
 (defun org-get-local-variables ()
 (defun org-get-local-variables ()
   "Return a list of all local variables in an Org mode buffer."
   "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
     (delq nil
           (mapcar
           (mapcar
            (lambda (x)
            (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))))
            varlist))))
 
 
 (defun org-clone-local-variables (from-buffer &optional regexp)
 (defun org-clone-local-variables (from-buffer &optional regexp)
   "Clone local variables from FROM-BUFFER.
   "Clone local variables from FROM-BUFFER.
 Optional argument REGEXP selects variables to clone."
 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
 ;;;###autoload
 (defun org-run-like-in-org-mode (cmd)
 (defun org-run-like-in-org-mode (cmd)