ox: Fix priority bug in :title property

* lisp/ox.el (org-export--get-inbuffer-options): Return the empty
  string instead of nil when TITLE keywords has no value.
(org-export--get-buffer-attributes): Do not set :title property
early.
(org-export--get-global-options): Do not ignore anymore nil values.
Small refactoring.
(org-export-as): Correctly set :title here.

Thanks to Nicolas Richard for reporting it.
http://permalink.gmane.org/gmane.emacs.orgmode/87149
This commit is contained in:
Nicolas Goaziou 2014-06-03 22:07:35 +02:00
parent 045fd4ed62
commit 0fbc4893ed
1 changed files with 28 additions and 15 deletions

View File

@ -1317,6 +1317,10 @@ The back-end could then be called with, for example:
;; - category :: tree ;; - category :: tree
;; - type :: list of elements and objects ;; - type :: list of elements and objects
;; ;;
;; + `:input-buffer' :: Name of input buffer.
;; - category :: option
;; - type :: string
;;
;; + `:input-file' :: Full path to input file, if any. ;; + `:input-file' :: Full path to input file, if any.
;; - category :: option ;; - category :: option
;; - type :: string or nil ;; - type :: string or nil
@ -1765,17 +1769,19 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
(when (stringp value) (when (stringp value)
(setq plist (setq plist
(plist-put plist property (plist-put plist property
(org-element-parse-secondary-string (or (org-element-parse-secondary-string
value (org-element-restriction 'keyword)))))))))) 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) ""))))))))))
(defun org-export--get-buffer-attributes () (defun org-export--get-buffer-attributes ()
"Return properties related to buffer attributes, as a plist." "Return properties related to buffer attributes, as a plist."
;; Store full path of input file name, or nil. For internal use. ;; Store full path of input file name, or nil. For internal use.
(let ((visited-file (buffer-file-name (buffer-base-buffer)))) (let ((visited-file (buffer-file-name (buffer-base-buffer))))
(list :input-file visited-file (list :input-file visited-file
:title (if (not visited-file) (buffer-name (buffer-base-buffer)) :input-buffer (buffer-name (buffer-base-buffer)))))
(file-name-sans-extension
(file-name-nondirectory visited-file))))))
(defun org-export--get-global-options (&optional backend) (defun org-export--get-global-options (&optional backend)
"Return global export options as a plist. "Return global export options as a plist.
@ -1788,23 +1794,22 @@ process."
(all (append (and backend (org-export-get-all-options backend)) (all (append (and backend (org-export-get-all-options backend))
org-export-options-alist))) org-export-options-alist)))
(dolist (cell all plist) (dolist (cell all plist)
(let ((prop (car cell)) (let ((prop (car cell)))
(default-value (nth 3 cell))) (unless (plist-member plist prop)
(unless (or (not default-value) (plist-member plist prop))
(setq plist (setq plist
(plist-put (plist-put
plist plist
prop prop
;; Eval default value provided. If keyword is ;; Evaluate default value provided. If keyword is
;; a member of `org-element-document-properties', ;; a member of `org-element-document-properties',
;; parse it as a secondary string before storing it. ;; parse it as a secondary string before storing it.
(let ((value (eval (nth 3 cell)))) (let ((value (eval (nth 3 cell))))
(if (not (stringp value)) value (if (and (stringp value)
(let ((keyword (nth 1 cell))) (member (nth 1 cell)
(if (member keyword org-element-document-properties) org-element-document-properties))
(org-element-parse-secondary-string (org-element-parse-secondary-string
value (org-element-restriction 'keyword)) value (org-element-restriction 'keyword))
value))))))))))) value)))))))))
(defun org-export--list-bound-variables () (defun org-export--list-bound-variables ()
"Return variables bound from BIND keywords in current buffer. "Return variables bound from BIND keywords in current buffer.
@ -3017,6 +3022,14 @@ Return code as a string."
(org-export-install-filters (org-export-install-filters
(org-combine-plists (org-combine-plists
info (org-export-get-environment backend subtreep ext-plist)))) 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}}}, ;; Expand export-specific set of macros: {{{author}}},
;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done ;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
;; once regular macros have been expanded, since document ;; once regular macros have been expanded, since document