emacs-orgmode
[Top][All Lists]
Advanced

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

[PATCH v2 2/3] ox-texinfo: Optionally use @itemx for certain description


From: Jonas Bernoulli
Subject: [PATCH v2 2/3] ox-texinfo: Optionally use @itemx for certain description list items
Date: Wed, 5 Jan 2022 14:30:24 +0100

* doc/org-manual.org (Plain lists in Texinfo export): Reorder and
document new functionality.
* lisp/ox-texinfo.el: Add org-texinfo--combine-items to the list of
:filter-parse-tree functions of the texinfo backend.
* lisp/ox-texinfo.el (org-texinfo--combine-items) New function.
* lisp/ox-texinfo.el (org-texinfo-item) Transcode combined items to
one @item and one or more @itemx.
---
 doc/org-manual.org | 38 +++++++++++++++++++++++++++-----------
 lisp/ox-texinfo.el | 45 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 68 insertions(+), 15 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index a5aac7d61..b3c4a9bef 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -15236,6 +15236,23 @@ This paragraph is preceded by...
 :DESCRIPTION: List attributes.
 :END:
 
+#+cindex: lettered lists, in Texinfo export
+#+cindex: enum, Texinfo attribute
+The Texinfo export back-end converts unordered and ordered lists in
+the Org file using the default command =@itemize=.
+
+Ordered lists are numbered when exported to Texinfo format.  Such
+numbering obeys any counter (see [[*Plain Lists]]) in the first item of
+the list.  The =:enum= attribute also let you start the list at a
+specific number, or switch to a lettered list, as illustrated here:
+
+#+begin_example
+#+ATTR_TEXINFO: :enum A
+1. Alpha
+2. Bravo
+3. Charlie
+#+end_example
+
 #+cindex: @samp{ATTR_TEXINFO}, keyword
 #+cindex: two-column tables, in Texinfo export
 #+cindex: table-type, Texinfo attribute
@@ -15262,7 +15279,7 @@ entry in the first column of the table.
 The following example illustrates all the attributes above:
 
 #+begin_example
-,#+ATTR_TEXINFO: :table-type vtable :sep , :indic asis
+,#+attr_texinfo: :table-type vtable :indic asis :sep ,
 - foo, bar :: This is the common text for variables foo and bar.
 #+end_example
 
@@ -15277,18 +15294,17 @@ This is the common text for variables foo and bar.
 @end table
 #+end_example
 
-#+cindex: lettered lists, in Texinfo export
-#+cindex: enum, Texinfo attribute
-Ordered lists are numbered when exported to Texinfo format.  Such
-numbering obeys any counter (see [[*Plain Lists]]) in the first item of
-the list.  The =:enum= attribute also let you start the list at
-a specific number, or switch to a lettered list, as illustrated here
+The =:combine= attribute is an alternative to the =:sep= attribute,
+which allows writing each entry on its own line.  If this attribute is
+non-nil and an item in a description list has no body but is followed
+by another item, then the second item is transcoded to =@itemx=.  This
+example is transcoded to the same output as above.
 
 #+begin_example
-#+ATTR_TEXINFO: :enum A
-1. Alpha
-2. Bravo
-3. Charlie
+,#+attr_texinfo: :table-type vtable :indic asis :combine t
+- foo ::
+- bar ::
+  This is the common text for variables foo and bar.
 #+end_example
 
 *** Tables in Texinfo export
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index 57cbcf6ad..8f671ea13 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -83,7 +83,8 @@ (org-export-define-backend 'texinfo
     (verse-block . org-texinfo-verse-block))
   :filters-alist
   '((:filter-headline . org-texinfo--filter-section-blank-lines)
-    (:filter-parse-tree . org-texinfo--normalize-headlines)
+    (:filter-parse-tree . (org-texinfo--normalize-headlines
+                          org-texinfo--combine-items))
     (:filter-section . org-texinfo--filter-section-blank-lines)
     (:filter-final-output . org-texinfo--untabify))
   :menu-entry
@@ -421,7 +422,7 @@ (defun org-texinfo--filter-section-blank-lines (headline 
_backend _info)
 (defun org-texinfo--normalize-headlines (tree _backend info)
   "Normalize headlines in TREE.
 
-BACK-END is the symbol specifying back-end used for export.
+_BACKEND is the symbol `texinfo'; the back-end used for export.
 INFO is a plist used as a communication channel.
 
 Make sure every headline in TREE contains a section, since those
@@ -443,6 +444,37 @@ (defun org-texinfo--normalize-headlines (tree _backend 
info)
     info)
   tree)
 
+(defun org-texinfo--combine-items (tree _backend info)
+  "Normalize items in TREE.
+
+_BACKEND is the symbol `texinfo'; the back-end used for export.
+INFO is a plist used as a communication channel.
+
+Items in description lists that use the \"+\" bullet are
+converted to `@itemx'.  If another item is followed by such an
+item, then the first item should not be followed by a space,
+which this function takes care of.
+
+Return new tree."
+  (org-element-map tree 'item
+    (lambda (item)
+      (let ((plain-list (org-element-property :parent item)))
+       (when (and (org-not-nil (org-export-read-attribute
+                                :attr_texinfo plain-list :compact))
+                  (eq (org-element-property :type plain-list) 'descriptive))
+         (let ((next-item
+                (cadr (memq item (org-element-contents plain-list)))))
+           (when (and next-item
+                      (not (org-element-contents item))
+                      (= (org-element-property :post-blank item) 1))
+             (org-element-put-property
+              next-item :itemx
+              (nconc (org-element-property :itemx item)
+                     (list (org-element-property :tag item))))
+             (org-element-extract-element item))))))
+    info)
+  tree)
+
 (defun org-texinfo--find-verb-separator (s)
   "Return a character not used in string S.
 This is used to choose a separator for constructs like \\verb."
@@ -994,8 +1026,13 @@ (defun org-texinfo-item (item contents info)
                 (org-export-read-attribute :attr_texinfo
                                            (org-element-property :parent item)
                                            :sep)))
-        (items (and tag
-                    (let ((tag (org-export-data tag info)))
+        (items (org-element-property :itemx item))
+        (items (cond (items
+                      (mapcar (lambda (tag) (org-export-data tag info))
+                              (nconc items (list tag))))
+                     ((not tag) nil)
+                     (t
+                      (setq tag (org-export-data tag info))
                       (if split
                           (split-string tag (regexp-quote split) t "[ \t\n]+")
                         (list tag))))))
-- 
2.34.1




reply via email to

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