summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-09-01 12:59:57 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-09-01 12:59:57 +0200
commit61ad50d75864dc73f7ddcbb6f7dbe3053dcf65a9 (patch)
tree98c7d42e3d897e42c3370a8a25af7133761c4e5b
parent06bffa9120d3084fe5fae25ab8892bdf09a58239 (diff)
downloadorg-mode-61ad50d75864dc73f7ddcbb6f7dbe3053dcf65a9.tar.gz
org-export: Fix #+BIND: keywords evaluation
* contrib/lisp/org-export.el (org-export--install-letbind-maybe): If a variable is bound two times in the buffer, be sure to set its value to the last bound. Use correct function to confirm binding. Allow keyword to start on any column. * testing/lisp/test-org-export.el: Add tests.
-rw-r--r--contrib/lisp/org-export.el13
-rw-r--r--testing/lisp/test-org-export.el33
2 files changed, 40 insertions, 6 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index e3a3716..357fef5 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -1548,11 +1548,14 @@ retrieved."
(let (letbind pair)
(org-with-wide-buffer
(goto-char (point-min))
- (while (re-search-forward (org-make-options-regexp '("BIND")) nil t)
- (when (org-export-confirm-letbind)
- (push (read (concat "(" (org-match-string-no-properties 2) ")"))
- letbind))))
- (while (setq pair (pop letbind))
+ (while (re-search-forward "^[ \t]*#\\+BIND:" nil t)
+ (let* ((element (org-element-at-point))
+ (value (org-element-property :value element)))
+ (when (and (eq (org-element-type element) 'keyword)
+ (not (equal value ""))
+ (org-export--confirm-letbind))
+ (push (read (format "(%s)" value)) letbind)))))
+ (dolist (pair (nreverse letbind))
(org-set-local (car pair) (nth 1 pair)))))
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index 6163f60..ed72577 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -57,7 +57,38 @@ already filled in `info'."
-;;; Tests
+;;; Internal Tests
+
+(ert-deftest test-org-export/bind-keyword ()
+ "Test reading #+BIND: keywords."
+ ;; Test with `org-export-all-BIND' set to t.
+ (should
+ (org-test-with-temp-text "#+BIND: variable value"
+ (let ((org-export-allow-BIND t))
+ (org-export--install-letbind-maybe)
+ (eq variable 'value))))
+ ;; Test with `org-export-all-BIND' set to nil.
+ (should-not
+ (org-test-with-temp-text "#+BIND: variable value"
+ (let ((org-export-allow-BIND nil))
+ (org-export--install-letbind-maybe)
+ (boundp 'variable))))
+ ;; Test with `org-export-all-BIND' set to 'confirm and
+ ;; `org-export--allow-BIND-local' to t .
+ (should
+ (org-test-with-temp-text "#+BIND: variable value"
+ (let ((org-export-allow-BIND 'confirm))
+ (org-set-local 'org-export--allow-BIND-local t)
+ (org-export--install-letbind-maybe)
+ (eq variable 'value))))
+ ;; Test with `org-export-all-BIND' set to 'confirm and
+ ;; `org-export--allow-BIND-local' to nil.
+ (should-not
+ (org-test-with-temp-text "#+BIND: variable value"
+ (let ((org-export-allow-BIND 'confirm))
+ (org-set-local 'org-export--allow-BIND-local nil)
+ (org-export--install-letbind-maybe)
+ (boundp 'variable)))))
(ert-deftest test-org-export/parse-option-keyword ()
"Test reading all standard #+OPTIONS: items."