[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] ox-texinfo: Turn a description list item with "+" bullet int
From: |
Jonas Bernoulli |
Subject: |
[PATCH 1/2] ox-texinfo: Turn a description list item with "+" bullet into @itemx |
Date: |
Sat, 18 Dec 2021 22:40:37 +0100 |
* doc/org-manual.org (Plain lists in Texinfo export): Reorder and
document new functionality.
* lisp/ox-texinfo.el (org-texinfo--filter-parse-tree)
(org-texinfo--normalize-items): New functions.
* lisp/ox-texinfo.el (org-texinfo-item): Use @itemx or @item
depending on the used bullet.
---
doc/org-manual.org | 37 ++++++++++++++++++++++++++-----------
lisp/ox-texinfo.el | 39 +++++++++++++++++++++++++++++++++++----
2 files changed, 61 insertions(+), 15 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index b65e2f173..b8bb391c2 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 :sep , :indic asis
- foo, bar :: This is the common text for variables foo and bar.
#+end_example
@@ -15277,18 +15294,16 @@ 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
+In description lists the used bullet is significant when exporting to
+Texinfo; when in doubt, then use =-=. An item that uses =+= instead
+becomes a new entry in the first column of the table. The above
+output can also be produced with:
#+begin_example
-#+ATTR_TEXINFO: :enum A
-1. Alpha
-2. Bravo
-3. Charlie
+,#+attr_texinfo: :table-type vtable :indic asis
+- foo ::
++ bar ::
+ This is the common text for foo and bar.
#+end_example
*** Tables in Texinfo export
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index b0125894a..35862357d 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -418,6 +418,11 @@ (defun org-texinfo--filter-section-blank-lines (headline
_backend _info)
"Filter controlling number of blank lines after a section."
(replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" "\n\n" headline))
+(defun org-texinfo--filter-parse-tree (tree backend info)
+ "Normalize headlines and items."
+ (org-texinfo--normalize-headlines tree backend info)
+ (org-texinfo--normalize-items tree info))
+
(defun org-texinfo--normalize-headlines (tree _backend info)
"Normalize headlines in TREE.
@@ -443,6 +448,29 @@ (defun org-texinfo--normalize-headlines (tree _backend
info)
info)
tree)
+(defun org-texinfo--normalize-items (tree info)
+ "Normalize items in TREE.
+
+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 'plain-list
+ (lambda (plain-list)
+ (when (eq (org-element-property :type plain-list) 'descriptive)
+ (let ((contents (org-element-contents plain-list)))
+ (while (setq item (pop contents))
+ (let ((next-item (car contents)))
+ (when (and next-item
+ (equal (org-element-property :bullet next-item) "+ "))
+ (org-element-put-property item :post-blank 0)))))))
+ 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."
@@ -998,13 +1026,16 @@ (defun org-texinfo-item (item contents info)
(let ((tag (org-export-data tag info)))
(if split
(split-string tag (regexp-quote split) t "[ \t\n]+")
- (list tag))))))
+ (list tag)))))
+ (command (if (equal (org-element-property :bullet item) "+ ")
+ "@itemx"
+ "@item")))
(format "%s\n%s"
(pcase items
- (`nil "@item")
- (`(,item) (concat "@item " item))
+ (`nil command)
+ (`(,item) (concat command " " item))
(`(,item . ,items)
- (concat "@item " item "\n"
+ (concat command " " item "\n"
(mapconcat (lambda (i) (concat "@itemx " i))
items
"\n"))))
--
2.34.1