1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-22 07:09:47 +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:
(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)

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.")
(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

View File

@ -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)