1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-03 08:30:03 +00:00

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:
Nicolas Goaziou 2013-04-01 15:18:47 +02:00
parent fa3b4830b8
commit 55db57dc0a
2 changed files with 52 additions and 40 deletions

View File

@ -1429,7 +1429,8 @@ external parameters overriding Org default settings, but still
inferior to file-local settings."
;; First install #+BIND variables since these must be set before
;; 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...
(org-combine-plists
;; ... from global variables...
@ -1713,8 +1714,10 @@ process."
;; Return value.
plist))
(defun org-export--install-letbind-maybe ()
"Install the values from #+BIND lines as local variables."
(defun org-export--list-bound-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
(let* (collect-bind ; For byte-compiler.
(collect-bind
@ -1745,9 +1748,8 @@ process."
(cons file files)
alist))))))))))
alist)))))
;; Install each variable in current buffer.
(dolist (pair (nreverse (funcall collect-bind nil nil)))
(org-set-local (car pair) (nth 1 pair))))))
;; Return value in appropriate order of appearance.
(nreverse (funcall collect-bind nil nil)))))
;;;; 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
;; already in BUFFER.
(let ((org-mode-hook nil)) (org-mode))
;; Buffer local variables.
,@(let (local-vars)
(mapc
(lambda (entry)
(when (consp entry)
(let ((var (car entry))
(val (cdr entry)))
(and (not (eq var 'org-font-lock-keywords))
(or (memq var
'(default-directory
;; Copy specific buffer local variables and variables set
;; through BIND keywords.
,@(let ((bound-variables (org-export--list-bound-variables))
vars)
(dolist (entry (buffer-local-variables (buffer-base-buffer)) vars)
(when (consp entry)
(let ((var (car entry))
(val (cdr entry)))
(and (not (eq var 'org-font-lock-keywords))
(or (memq var
'(default-directory
buffer-file-name
buffer-file-coding-system))
(string-match "^\\(org-\\|orgtbl-\\)"
(symbol-name var)))
;; Skip unreadable values, as they cannot be
;; sent to external process.
(or (not val) (ignore-errors (read (format "%S" val))))
(push `(set (make-local-variable (quote ,var))
(quote ,val))
local-vars)))))
(buffer-local-variables (buffer-base-buffer)))
local-vars)
(assq var bound-variables)
(string-match "^\\(org-\\|orgtbl-\\)"
(symbol-name var)))
;; Skip unreadable values, as they cannot be
;; sent to external process.
(or (not val) (ignore-errors (read (format "%S" val))))
(push `(set (make-local-variable (quote ,var))
(quote ,val))
vars))))))
;; Whole buffer contents.
(insert
,(org-with-wide-buffer

View File

@ -75,35 +75,45 @@ already filled in `info'."
"Test reading #+BIND: keywords."
;; Test with `org-export-allow-bind-keywords' set to t.
(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))
(org-export--install-letbind-maybe)
(eq variable 'value))))
(org-export-get-environment)
(eq test-ox-var 'value))))
;; Test with `org-export-allow-bind-keywords' set to nil.
(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))
(org-export--install-letbind-maybe)
(boundp 'variable))))
(org-export-get-environment)
(boundp 'test-ox-var))))
;; BIND keywords are case-insensitive.
(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))
(org-export--install-letbind-maybe)
(eq variable 'value))))
(org-export-get-environment)
(eq test-ox-var 'value))))
;; Preserve order of BIND keywords.
(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))
(org-export--install-letbind-maybe)
(eq variable 2))))
(org-export-get-environment)
(eq test-ox-var 2))))
;; Read BIND keywords in setup files.
(should
(org-test-with-temp-text
(format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
(let ((org-export-allow-bind-keywords t))
(org-export--install-letbind-maybe)
(eq variable 'value)))))
(org-export-get-environment)
(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 ()
"Test reading all standard #+OPTIONS: items."