ox: Title fallbacks to nil instead of file name

* lisp/ox.el (org-export--get-inbuffer-options):
(org-export-as): Remove title default value handling.
(org-export--get-buffer-attributes): Remove unnecessary property.

* doc/org.texi (Document title):
(Export settings):
* doc/orgguide.texi (Export options): Update documentation.

* testing/lisp/test-ox.el (test-org-export/set-title): Update tests
  according to new specifications.
This commit is contained in:
Nicolas Goaziou 2014-06-15 22:39:29 +02:00
parent 6ba05e3200
commit 604b93892c
4 changed files with 49 additions and 64 deletions

View File

@ -9595,10 +9595,6 @@ The title of the exported document is taken from the special line
#+TITLE: This is the title of the document
@end example
@noindent
If this line does not exist, the title will be the name of the file
associated with the buffer, without extension, or the buffer name.
@cindex property, EXPORT_TITLE
If you are exporting only a subtree, its heading will become the title of the
document. If the subtree has a property @code{EXPORT_TITLE}, that will take
@ -10580,8 +10576,7 @@ be executed during export even though the subtree is not exported.
@item TITLE
@cindex #+TITLE
The title to be shown (otherwise derived from buffer's name). You can use
several such keywords for long titles.
The title to be shown. You can use several such keywords for long titles.
@end table
The @code{#+OPTIONS} keyword is a compact@footnote{If you want to configure

View File

@ -2324,7 +2324,7 @@ Insert template with export options, see example below.
@end table
@smallexample
#+TITLE: the title to be shown (default is the buffer name)
#+TITLE: the title to be shown
#+AUTHOR: the author (default taken from @code{user-full-name})
#+DATE: a date, fixed, or an Org timestamp
#+EMAIL: his/her email address (default from @code{user-mail-address})

View File

@ -1340,10 +1340,6 @@ The back-end could then be called with, for example:
;; - category :: tree
;; - type :: list of elements and objects
;;
;; + `:input-buffer' :: Original buffer name.
;; - category :: option
;; - type :: string
;;
;; + `:input-file' :: Full path to input file, if any.
;; - category :: option
;; - type :: string or nil
@ -1805,19 +1801,13 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
(when (stringp value)
(setq plist
(plist-put plist property
(or (org-element-parse-secondary-string
value (org-element-restriction 'keyword))
;; When TITLE keyword sets an empty
;; string, make sure it doesn't
;; appear as nil in the plist.
(and (eq property :title) ""))))))))))
(org-element-parse-secondary-string
value (org-element-restriction 'keyword))))))))))
(defun org-export--get-buffer-attributes ()
"Return properties related to buffer attributes, as a plist."
;; Store full path of input file name, or nil. For internal use.
(let ((visited-file (buffer-file-name (buffer-base-buffer))))
(list :input-file visited-file
:input-buffer (buffer-name (buffer-base-buffer)))))
(list :input-file (buffer-file-name (buffer-base-buffer))))
(defun org-export--get-global-options (&optional backend)
"Return global export options as a plist.
@ -3107,14 +3097,6 @@ Return code as a string."
(org-export-install-filters
(org-combine-plists
info (org-export-get-environment backend subtreep ext-plist))))
;; Special case: provide original file name or buffer name as
;; default value for :title property.
(unless (plist-get info :title)
(plist-put
info :title
(let ((file (plist-get info :input-file)))
(if file (file-name-sans-extension (file-name-nondirectory file))
(plist-get info :input-buffer)))))
;; Expand export-specific set of macros: {{{author}}},
;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
;; once regular macros have been expanded, since document

View File

@ -270,58 +270,66 @@ Paragraph"
(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)
(list (org-export-as
(org-export-create-backend
:transcoders
'((template . (lambda (text info)
(org-element-interpret-data
(plist-get info :title)))))))
(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)
(list (org-export-as
(org-export-create-backend
:transcoders
'((template . (lambda (text info)
(org-element-interpret-data
(plist-get info :title)))))))
(buffer-name)))))
;; If a title is specified, use it.
;; Without TITLE keyword.
(should
(equal
"Title"
(org-test-with-temp-text-in-file "#+TITLE: Title\nTest"
(org-mode)
""
(org-test-with-temp-text "Test"
(org-export-as
(org-export-create-backend
:transcoders
'((template . (lambda (text info)
(org-element-interpret-data
(plist-get info :title))))))))))
;; If an empty title is specified, do not set it.
;; With a blank TITLE keyword.
(should
(equal
""
(org-test-with-temp-text-in-file "#+TITLE:\nTest"
(org-mode)
(org-test-with-temp-text "#+TITLE:\nTest"
(org-export-as
(org-export-create-backend
:transcoders
'((template . (lambda (text info)
(org-element-interpret-data
(plist-get info :title)))))))))))
(plist-get info :title))))))))))
;; With a non-empty TITLE keyword.
(should
(equal
"Title"
(org-test-with-temp-text "#+TITLE: Title\nTest"
(org-export-as
(org-export-create-backend
:transcoders
'((template . (lambda (text info)
(org-element-interpret-data
(plist-get info :title))))))))))
;; When exporting a subtree, its heading becomes the headline of the
;; document...
(should
(equal
"Headline"
(org-test-with-temp-text "* Headline\nBody"
(org-export-as
(org-export-create-backend
:transcoders
'((template . (lambda (text info)
(org-element-interpret-data
(plist-get info :title))))))
'subtree))))
;; ... unless there is an EXPORT_TITLE property at the root of the
;; subtree.
(should
(equal
"B"
(org-test-with-temp-text
"* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
(org-export-as
(org-export-create-backend
:transcoders
'((template . (lambda (text info)
(org-element-interpret-data
(plist-get info :title))))))
'subtree)))))
(ert-deftest test-org-export/handle-options ()
"Test if export options have an impact on output."