1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-23 07:18:53 +00:00

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.
This commit is contained in:
Nicolas Goaziou 2015-12-05 11:55:02 +01:00
parent 43009088b7
commit d6a169a82c
3 changed files with 41 additions and 45 deletions

View File

@ -47,19 +47,18 @@
;;; Code: ;;; Code:
(eval-when-compile (require 'cl-lib)
(require 'cl))
(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-decrypt-entry "org-crypt" ())
(declare-function org-table-goto-line "org-table" (N)) (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-table-analyze "org-table" ())
(declare-function org-encrypt-entry "org-crypt" ()) (declare-function org-table-goto-line "org-table" (N))
(declare-function org-decrypt-entry "org-crypt" ())
(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)

View File

@ -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) (when (markerp org-indent--initial-marker)
(set-marker org-indent-initial-marker nil)) (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 (and org-indent--initial-marker
(marker-position org-indent-initial-marker) (marker-position org-indent--initial-marker)
(org-indent-add-properties 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

View File

@ -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) (let ((varlist
(with-current-buffer (get-buffer-create "*Org tmp*") (prog1 (with-current-buffer (get-buffer-create "*Org tmp*")
(erase-buffer) (erase-buffer)
(org-mode) (org-mode)
(setq varlist (buffer-local-variables))) (buffer-local-variables))
(kill-buffer "*Org tmp*") (kill-buffer "*Org tmp*"))))
(delq nil (delq nil
(mapcar (mapcar
(lambda (x) (lambda (x)
(setq x (let* ((binding (if (symbolp x) (list x) (list (car x) (cdr x))))
(if (symbolp x) (name (car binding)))
(list x) (and (not (get name 'org-state))
(list (car x) (cdr x)))) ;; Ignore internal local variables, since those
(if (and (not (get (car x) 'org-state)) ;; are likely variables that are not meant to be
(string-match ;; copied.
"^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)" (not (string-match-p "--" (symbol-name name)))
(symbol-name (car x)))) (string-match-p
x nil)) "\\`\\(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 (dolist (pair (buffer-local-variables from-buffer))
(lambda (pair) (let ((name (car pair)))
(and (symbolp (car pair)) (when (and (symbolp name)
(or (null regexp) ;; Ignore internal local variables, since those are
(string-match regexp (symbol-name (car pair)))) ;; likely variables that are not meant to be copied.
(set (make-local-variable (car pair)) (not (string-match-p "--" (symbol-name name)))
(cdr pair)))) (or (null regexp) (string-match regexp (symbol-name name))))
(buffer-local-variables from-buffer))) (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)