emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] how to use :options-alist in org-export-define-derived-backend ?


From: Nicolas Goaziou
Subject: Re: [O] how to use :options-alist in org-export-define-derived-backend ?
Date: Sun, 15 Jun 2014 22:47:01 +0200

Completing myself,

Nicolas Goaziou <address@hidden> 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
>From 7e917e97f99bf9e9266b64f5066bfaa5f8ca98ee Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <address@hidden>
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
 
address@hidden
-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 address@hidden 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 via email to

[Prev in Thread] Current Thread [Next in Thread]