From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: how to use :options-alist in org-export-define-derived-backend ? Date: Sun, 15 Jun 2014 22:47:01 +0200 Message-ID: <87wqchnbne.fsf@nicolasgoaziou.fr> References: <87bnubhw04.fsf@geodiff-mac3.ulb.ac.be> <8761kiarf8.fsf@bzg.ath.cx> <87mwdtpx3s.fsf@gmail.com> <8738f96q03.fsf@bzg.ath.cx> <871tusge3t.fsf@selenimh.mobile.lan> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwHK5-0008M7-Uy for emacs-orgmode@gnu.org; Sun, 15 Jun 2014 16:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwHJy-0001aY-4j for emacs-orgmode@gnu.org; Sun, 15 Jun 2014 16:46:41 -0400 In-Reply-To: <871tusge3t.fsf@selenimh.mobile.lan> (Nicolas Goaziou's message of "Sat, 14 Jun 2014 09:11:18 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: Nicolas Richard , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Completing myself, Nicolas Goaziou writes: > Automatically set document's title to file name or buffer name when no > TITLE keyword is provided. Implemented in the following patch. WDYT? -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-Title-fallbacks-to-nil-instead-of-file-name.patch >From 7e917e97f99bf9e9266b64f5066bfaa5f8ca98ee Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 15 Jun 2014 22:39:29 +0200 Subject: [PATCH] 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. --- doc/org.texi | 7 +---- doc/orgguide.texi | 2 +- lisp/ox.el | 24 ++-------------- testing/lisp/test-ox.el | 76 +++++++++++++++++++++++++++---------------------- 4 files changed, 47 insertions(+), 62 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 441b08c..dcb5a9c 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -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 diff --git a/doc/orgguide.texi b/doc/orgguide.texi index ab856e9..6842592 100644 --- a/doc/orgguide.texi +++ b/doc/orgguide.texi @@ -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}) diff --git a/lisp/ox.el b/lisp/ox.el index 4bfef52..605c5a4 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -1343,10 +1343,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 @@ -1794,19 +1790,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. @@ -3098,14 +3088,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 diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 234032e..664891e 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -270,58 +270,66 @@ Paragraph" (ert-deftest test-org-export/set-title () "Test title setting." - ;; If no title if specified, use file name. + ;; Without TITLE keyword. (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 + (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. + (org-export-as + (org-export-create-backend + :transcoders + '((template . (lambda (text info) + (org-element-interpret-data + (plist-get info :title)))))))))) + ;; With a blank TITLE keyword. + (should + (equal + "" + (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)))))))))) + ;; With a non-empty TITLE keyword. (should (equal "Title" - (org-test-with-temp-text-in-file "#+TITLE: Title\nTest" - (org-mode) + (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)))))))))) - ;; If an empty title is specified, do not set it. + ;; When exporting a subtree, its heading becomes the headline of the + ;; document... (should (equal - "" - (org-test-with-temp-text-in-file "#+TITLE:\nTest" - (org-mode) + "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))))))))))) + (plist-get info :title)))))) + 'subtree))))) (ert-deftest test-org-export/handle-options () "Test if export options have an impact on output." -- 2.0.0 --=-=-=--