emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Bastien <bzg@gnu.org>
Cc: Nicolas Richard <theonewiththeevillook@yahoo.fr>, emacs-orgmode@gnu.org
Subject: Re: how to use :options-alist in org-export-define-derived-backend ?
Date: Sun, 15 Jun 2014 22:47:01 +0200	[thread overview]
Message-ID: <87wqchnbne.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <871tusge3t.fsf@selenimh.mobile.lan> (Nicolas Goaziou's message of "Sat, 14 Jun 2014 09:11:18 +0200")

[-- Attachment #1: Type: text/plain, Size: 236 bytes --]

Completing myself,

Nicolas Goaziou <mail@nicolasgoaziou.fr> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-Title-fallbacks-to-nil-instead-of-file-name.patch --]
[-- Type: text/x-diff, Size: 7704 bytes --]

From 7e917e97f99bf9e9266b64f5066bfaa5f8ca98ee Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
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


  reply	other threads:[~2014-06-15 20:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-02 20:55 how to use :options-alist in org-export-define-derived-backend ? Nicolas Richard
2014-06-03 16:28 ` Bastien
2014-06-03 20:16   ` Nicolas Goaziou
2014-06-13 10:52     ` Bastien
2014-06-14  7:11       ` Nicolas Goaziou
2014-06-15 20:47         ` Nicolas Goaziou [this message]
2014-06-15 20:54           ` Bastien
2014-06-16  6:05             ` Nicolas Goaziou
2014-07-28  8:53         ` Bastien
2014-07-28 19:30           ` Nicolas Goaziou
2014-07-29 13:07             ` Bastien
2014-07-29 14:08               ` Rasmus
2014-07-29 14:16               ` Nicolas Richard
2014-07-29 14:17               ` Nicolas Goaziou
2014-07-29 14:25                 ` Bastien
2014-08-02 19:21                   ` Nicolas Goaziou
2014-06-03 16:37 ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wqchnbne.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=theonewiththeevillook@yahoo.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).