forked from mirrors/org-mode
ox: Properly transfer bound variables through export process
* lisp/ox.el (org-export--list-bound-variables): Renamed from `org-export--install-letbind-maybe'. Though, only return list of bound variables instead of installing them as buffer-local variables. (org-export-get-environment): Use new function. Take care of the installation of bound variables. (org-export--generate-copy-script): Make sure non-Org variables are also installed in buffer copy. * testing/lisp/test-ox.el: Add test.
This commit is contained in:
parent
fa3b4830b8
commit
55db57dc0a
54
lisp/ox.el
54
lisp/ox.el
|
@ -1429,7 +1429,8 @@ external parameters overriding Org default settings, but still
|
||||||
inferior to file-local settings."
|
inferior to file-local settings."
|
||||||
;; First install #+BIND variables since these must be set before
|
;; First install #+BIND variables since these must be set before
|
||||||
;; global options are read.
|
;; global options are read.
|
||||||
(org-export--install-letbind-maybe)
|
(dolist (pair (org-export--list-bound-variables))
|
||||||
|
(org-set-local (car pair) (nth 1 pair)))
|
||||||
;; Get and prioritize export options...
|
;; Get and prioritize export options...
|
||||||
(org-combine-plists
|
(org-combine-plists
|
||||||
;; ... from global variables...
|
;; ... from global variables...
|
||||||
|
@ -1713,8 +1714,10 @@ process."
|
||||||
;; Return value.
|
;; Return value.
|
||||||
plist))
|
plist))
|
||||||
|
|
||||||
(defun org-export--install-letbind-maybe ()
|
(defun org-export--list-bound-variables ()
|
||||||
"Install the values from #+BIND lines as local variables."
|
"Return variables bound from BIND keywords in current buffer.
|
||||||
|
Also look for BIND keywords in setup files. The return value is
|
||||||
|
an alist where associations are (VARIABLE-NAME VALUE)."
|
||||||
(when org-export-allow-bind-keywords
|
(when org-export-allow-bind-keywords
|
||||||
(let* (collect-bind ; For byte-compiler.
|
(let* (collect-bind ; For byte-compiler.
|
||||||
(collect-bind
|
(collect-bind
|
||||||
|
@ -1745,9 +1748,8 @@ process."
|
||||||
(cons file files)
|
(cons file files)
|
||||||
alist))))))))))
|
alist))))))))))
|
||||||
alist)))))
|
alist)))))
|
||||||
;; Install each variable in current buffer.
|
;; Return value in appropriate order of appearance.
|
||||||
(dolist (pair (nreverse (funcall collect-bind nil nil)))
|
(nreverse (funcall collect-bind nil nil)))))
|
||||||
(org-set-local (car pair) (nth 1 pair))))))
|
|
||||||
|
|
||||||
|
|
||||||
;;;; Tree Properties
|
;;;; Tree Properties
|
||||||
|
@ -2793,28 +2795,28 @@ The function assumes BUFFER's major mode is `org-mode'."
|
||||||
;; Set major mode. Ignore `org-mode-hook' as it has been run
|
;; Set major mode. Ignore `org-mode-hook' as it has been run
|
||||||
;; already in BUFFER.
|
;; already in BUFFER.
|
||||||
(let ((org-mode-hook nil)) (org-mode))
|
(let ((org-mode-hook nil)) (org-mode))
|
||||||
;; Buffer local variables.
|
;; Copy specific buffer local variables and variables set
|
||||||
,@(let (local-vars)
|
;; through BIND keywords.
|
||||||
(mapc
|
,@(let ((bound-variables (org-export--list-bound-variables))
|
||||||
(lambda (entry)
|
vars)
|
||||||
(when (consp entry)
|
(dolist (entry (buffer-local-variables (buffer-base-buffer)) vars)
|
||||||
(let ((var (car entry))
|
(when (consp entry)
|
||||||
(val (cdr entry)))
|
(let ((var (car entry))
|
||||||
(and (not (eq var 'org-font-lock-keywords))
|
(val (cdr entry)))
|
||||||
(or (memq var
|
(and (not (eq var 'org-font-lock-keywords))
|
||||||
'(default-directory
|
(or (memq var
|
||||||
|
'(default-directory
|
||||||
buffer-file-name
|
buffer-file-name
|
||||||
buffer-file-coding-system))
|
buffer-file-coding-system))
|
||||||
(string-match "^\\(org-\\|orgtbl-\\)"
|
(assq var bound-variables)
|
||||||
(symbol-name var)))
|
(string-match "^\\(org-\\|orgtbl-\\)"
|
||||||
;; Skip unreadable values, as they cannot be
|
(symbol-name var)))
|
||||||
;; sent to external process.
|
;; Skip unreadable values, as they cannot be
|
||||||
(or (not val) (ignore-errors (read (format "%S" val))))
|
;; sent to external process.
|
||||||
(push `(set (make-local-variable (quote ,var))
|
(or (not val) (ignore-errors (read (format "%S" val))))
|
||||||
(quote ,val))
|
(push `(set (make-local-variable (quote ,var))
|
||||||
local-vars)))))
|
(quote ,val))
|
||||||
(buffer-local-variables (buffer-base-buffer)))
|
vars))))))
|
||||||
local-vars)
|
|
||||||
;; Whole buffer contents.
|
;; Whole buffer contents.
|
||||||
(insert
|
(insert
|
||||||
,(org-with-wide-buffer
|
,(org-with-wide-buffer
|
||||||
|
|
|
@ -75,35 +75,45 @@ already filled in `info'."
|
||||||
"Test reading #+BIND: keywords."
|
"Test reading #+BIND: keywords."
|
||||||
;; Test with `org-export-allow-bind-keywords' set to t.
|
;; Test with `org-export-allow-bind-keywords' set to t.
|
||||||
(should
|
(should
|
||||||
(org-test-with-temp-text "#+BIND: variable value"
|
(org-test-with-temp-text "#+BIND: test-ox-var value"
|
||||||
(let ((org-export-allow-bind-keywords t))
|
(let ((org-export-allow-bind-keywords t))
|
||||||
(org-export--install-letbind-maybe)
|
(org-export-get-environment)
|
||||||
(eq variable 'value))))
|
(eq test-ox-var 'value))))
|
||||||
;; Test with `org-export-allow-bind-keywords' set to nil.
|
;; Test with `org-export-allow-bind-keywords' set to nil.
|
||||||
(should-not
|
(should-not
|
||||||
(org-test-with-temp-text "#+BIND: variable value"
|
(org-test-with-temp-text "#+BIND: test-ox-var value"
|
||||||
(let ((org-export-allow-bind-keywords nil))
|
(let ((org-export-allow-bind-keywords nil))
|
||||||
(org-export--install-letbind-maybe)
|
(org-export-get-environment)
|
||||||
(boundp 'variable))))
|
(boundp 'test-ox-var))))
|
||||||
;; BIND keywords are case-insensitive.
|
;; BIND keywords are case-insensitive.
|
||||||
(should
|
(should
|
||||||
(org-test-with-temp-text "#+bind: variable value"
|
(org-test-with-temp-text "#+bind: test-ox-var value"
|
||||||
(let ((org-export-allow-bind-keywords t))
|
(let ((org-export-allow-bind-keywords t))
|
||||||
(org-export--install-letbind-maybe)
|
(org-export-get-environment)
|
||||||
(eq variable 'value))))
|
(eq test-ox-var 'value))))
|
||||||
;; Preserve order of BIND keywords.
|
;; Preserve order of BIND keywords.
|
||||||
(should
|
(should
|
||||||
(org-test-with-temp-text "#+BIND: variable 1\n#+BIND: variable 2"
|
(org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
|
||||||
(let ((org-export-allow-bind-keywords t))
|
(let ((org-export-allow-bind-keywords t))
|
||||||
(org-export--install-letbind-maybe)
|
(org-export-get-environment)
|
||||||
(eq variable 2))))
|
(eq test-ox-var 2))))
|
||||||
;; Read BIND keywords in setup files.
|
;; Read BIND keywords in setup files.
|
||||||
(should
|
(should
|
||||||
(org-test-with-temp-text
|
(org-test-with-temp-text
|
||||||
(format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
|
(format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
|
||||||
(let ((org-export-allow-bind-keywords t))
|
(let ((org-export-allow-bind-keywords t))
|
||||||
(org-export--install-letbind-maybe)
|
(org-export-get-environment)
|
||||||
(eq variable 'value)))))
|
(eq variable 'value))))
|
||||||
|
;; Verify that bound variables are seen during export.
|
||||||
|
(should
|
||||||
|
(equal "Yes\n"
|
||||||
|
(org-test-with-temp-text "#+BIND: test-ox-var value"
|
||||||
|
(let ((org-export-allow-bind-keywords t)
|
||||||
|
org-export-registered-backends)
|
||||||
|
(org-export-define-backend 'check
|
||||||
|
'((section . (lambda (s c i)
|
||||||
|
(if (eq test-ox-var 'value) "Yes" "No")))))
|
||||||
|
(org-export-as 'check))))))
|
||||||
|
|
||||||
(ert-deftest test-org-export/parse-option-keyword ()
|
(ert-deftest test-org-export/parse-option-keyword ()
|
||||||
"Test reading all standard #+OPTIONS: items."
|
"Test reading all standard #+OPTIONS: items."
|
||||||
|
|
Loading…
Reference in New Issue