summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-05-08 13:34:53 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2013-05-08 14:00:18 (GMT)
commit16f12e0aef9fab4bdc575ebee8c463846377ef8b (patch)
tree19000a4f4b16a898f989f6133679e4414e062c37
parentbe794a2a308483c44968fdd6b09270224d073595 (diff)
downloadorg-mode-16f12e0aef9fab4bdc575ebee8c463846377ef8b.zip
org-mode-16f12e0aef9fab4bdc575ebee8c463846377ef8b.tar.gz
ox: Fix default title
* lisp/ox.el (org-export--get-global-options): Properly set default title, i.e. when to TITLE keyword is provided. * testing/lisp/test-ox.el: Add tests.
-rw-r--r--lisp/ox.el32
-rw-r--r--testing/lisp/test-ox.el50
2 files changed, 68 insertions, 14 deletions
diff --git a/lisp/ox.el b/lisp/ox.el
index bf14bfa..f28d969 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1731,20 +1731,24 @@ process."
(lambda (cell)
(let ((prop (car cell)))
(unless (plist-member plist prop)
- (setq plist
- (plist-put
- plist
- prop
- ;; Eval default value provided. If keyword is a member
- ;; of `org-element-document-properties', parse it as
- ;; a secondary string before storing it.
- (let ((value (eval (nth 3 cell))))
- (if (not (stringp value)) value
- (let ((keyword (nth 1 cell)))
- (if (not (member keyword org-element-document-properties))
- value
- (org-element-parse-secondary-string
- value (org-element-restriction 'keyword)))))))))))
+ (let ((value (eval (nth 3 cell))))
+ ;; Only set property if default value is non-nil.
+ (when value
+ (setq plist
+ (plist-put
+ plist
+ prop
+ ;; If keyword belongs to
+ ;; `org-element-document-properties', parse
+ ;; default value as a secondary string before
+ ;; storing it.
+ (if (not (stringp value)) value
+ (let ((keyword (nth 1 cell)))
+ (if (not (member keyword
+ org-element-document-properties))
+ value
+ (org-element-parse-secondary-string
+ value (org-element-restriction 'keyword))))))))))))
all)
;; Return value.
plist))
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 3ab24fb..a55ad53 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -268,6 +268,56 @@ Paragraph"
(progn (forward-line 2)
(plist-get (org-export-get-environment nil t) :title))))))
+(ert-deftest test-org-export/set-title ()
+ "Test title setting."
+ ;; If no title if specified, use file name.
+ (should
+ (apply
+ 'equal
+ (org-test-with-temp-text-in-file "Test"
+ (org-mode)
+ (let (org-export-registered-backends)
+ (org-export-define-backend 'test
+ '((template . (lambda (text info)
+ (org-export-data (plist-get info :title) info)))))
+ (list (org-export-as 'test)
+ (file-name-nondirectory
+ (file-name-sans-extension (buffer-file-name))))))))
+ ;; If no title is specified, and no file is associated to the
+ ;; buffer, use buffer's name.
+ (should
+ (apply
+ 'equal
+ (org-test-with-temp-text "Test"
+ (org-mode)
+ (let (org-export-registered-backends)
+ (org-export-define-backend 'test
+ '((template . (lambda (text info)
+ (org-export-data (plist-get info :title) info)))))
+ (list (org-export-as 'test) (buffer-name))))))
+ ;; If a title is specified, use it.
+ (should
+ (equal
+ "Title"
+ (org-test-with-temp-text-in-file "#+TITLE: Title\nTest"
+ (org-mode)
+ (let (org-export-registered-backends)
+ (org-export-define-backend 'test
+ '((template . (lambda (text info)
+ (org-export-data (plist-get info :title) info)))))
+ (org-export-as 'test)))))
+ ;; If an empty title is specified, do not set it.
+ (should
+ (equal
+ ""
+ (org-test-with-temp-text-in-file "#+TITLE:\nTest"
+ (org-mode)
+ (let (org-export-registered-backends)
+ (org-export-define-backend 'test
+ '((template . (lambda (text info)
+ (org-export-data (plist-get info :title) info)))))
+ (org-export-as 'test))))))
+
(ert-deftest test-org-export/handle-options ()
"Test if export options have an impact on output."
;; Test exclude tags for headlines and inlinetasks.