Browse Source

ox-publish: Correctly return document title

* lisp/ox-publish.el (org-publish-find-title): Fix title when no
  #+TITLE property is provided.
* lisp/ox.el (org-export-store-default-title): Remove-function.
(org-export--default-title): Remove variable.
(org-export-options-alist): Do not use a default value.
(org-export--get-buffer-attributes): Store a default title.
(org-export-as): Apply function removal.
(org-export--get-global-options): Do not set a property with an
explicitely nil value.
Nicolas Goaziou 4 years ago
2 changed files with 19 additions and 29 deletions
  1. 8 9
  2. 11 20

+ 8 - 9

@@ -805,17 +805,16 @@ Default for SITEMAP-FILENAME is ''."
    (and (not reset) (org-publish-cache-get-file-property file :title nil t))
    (let* ((org-inhibit-startup t)
 	  (visiting (find-buffer-visiting file))
-	  (buffer (or visiting (find-file-noselect file)))
-	  title)
+	  (buffer (or visiting (find-file-noselect file))))
      (with-current-buffer buffer
-       (setq title
-	     (or (org-element-interpret-data
-		  (plist-get (org-export-get-environment) :title))
-		 (file-name-nondirectory (file-name-sans-extension file)))))
-     (unless visiting (kill-buffer buffer))
-     (org-publish-cache-set-file-property file :title title)
-     title)))
+       (let ((title
+	      (let ((property (plist-get (org-export-get-environment) :title)))
+		(if property (org-element-interpret-data property)
+		  (file-name-nondirectory (file-name-sans-extension file))))))
+	 (unless visiting (kill-buffer buffer))
+	 (org-publish-cache-set-file-property file :title title)
+	 title)))))
 (defun org-publish-find-date (file)
   "Find the date of FILE in project.

+ 11 - 20

@@ -117,7 +117,7 @@
     (:section-numbers nil "num" org-export-with-section-numbers)
     (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
     (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
-    (:title "TITLE" nil org-export--default-title space)
+    (:title "TITLE" nil nil space)
     (:with-archived-trees nil "arch" org-export-with-archived-trees)
     (:with-author nil "author" org-export-with-author)
     (:with-clocks nil "c" org-export-with-clocks)
@@ -1701,7 +1701,9 @@ Assume buffer is in Org mode.  Narrowing, if any, is ignored."
 	     ;; Return final value.
     ;; Read options in the current buffer.
-    (setq plist (funcall get-options buffer-file-name nil))
+    (setq plist
+	  (funcall get-options
+		   (and buffer-file-name (list buffer-file-name)) nil))
     ;; Parse keywords specified in `org-element-document-properties'.
     (mapc (lambda (keyword)
 	    ;; Find the property associated to the keyword.
@@ -1719,19 +1721,11 @@ Assume buffer is in Org mode.  Narrowing, if any, is ignored."
 (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.
-  (list :input-file (buffer-file-name (buffer-base-buffer))))
-(defvar org-export--default-title nil)	; Dynamically scoped.
-(defun org-export-store-default-title ()
-  "Return default title for current document, as a string.
-Title is extracted from associated file name, if any, or buffer's
-  (setq org-export--default-title
-	(or (let ((visited-file (buffer-file-name (buffer-base-buffer))))
-	      (and visited-file
+  (let ((visited-file (buffer-file-name (buffer-base-buffer))))
+    (list :input-file visited-file
+	  :title (if (not visited-file) (buffer-name (buffer-base-buffer))
-		    (file-name-nondirectory visited-file))))
-	    (buffer-name (buffer-base-buffer)))))
+		    (file-name-nondirectory visited-file))))))
 (defun org-export--get-global-options (&optional backend)
   "Return global export options as a plist.
@@ -1743,8 +1737,9 @@ process."
 	(all (append (and backend (org-export-backend-options backend))
     (dolist (cell all plist)
-      (let ((prop (car cell)))
-	(unless (plist-member plist prop)
+      (let ((prop (car cell))
+	    (default-value (nth 3 cell)))
+	(unless (or (not default-value) (plist-member plist prop))
 	  (setq plist
@@ -2945,10 +2940,6 @@ Return code as a string."
 				      (and body-only 'body-only))))
-	;; Store default title in `org-export--default-title' so that
-	;; `org-export-get-environment' can access it from buffer's
-	;; copy and then add it properly to communication channel.
-	(org-export-store-default-title)
 	;; Update communication channel and get parse tree.  Buffer
 	;; isn't parsed directly.  Instead, a temporary copy is
 	;; created, where include keywords, macros are expanded and