mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 20:37:51 +00:00
ox-texinfo: Change Texinfo class definition
* lisp/ox-texinfo.el (org-texinfo-classes): Change default value and structure. (org-texinfo--structuring-command): New function. (org-texinfo-headline): Use new function. The new structure handles properly appendices at sub-levels.
This commit is contained in:
parent
a0d1ad325d
commit
20795aae27
|
@ -49,6 +49,10 @@ You can now find them here :
|
||||||
- https://github.com/sabof/org-bullets
|
- https://github.com/sabof/org-bullets
|
||||||
- https://github.com/org-mime/org-mime
|
- https://github.com/org-mime/org-mime
|
||||||
|
|
||||||
|
*** Change ~org-texinfo-classes~ value
|
||||||
|
The value cannot support functions to create sectionning commands
|
||||||
|
anymore. Also, the sectionning commands should include commands for
|
||||||
|
appendices. See the docstring for more information.
|
||||||
*** Removal of ~:sitemap-sans-extension~
|
*** Removal of ~:sitemap-sans-extension~
|
||||||
|
|
||||||
The publishing property is no longer recognized, as a consequence of
|
The publishing property is no longer recognized, as a consequence of
|
||||||
|
|
|
@ -146,17 +146,19 @@ If nil it will default to `buffer-file-coding-system'."
|
||||||
(defcustom org-texinfo-classes
|
(defcustom org-texinfo-classes
|
||||||
'(("info"
|
'(("info"
|
||||||
"@documentencoding AUTO\n@documentlanguage AUTO"
|
"@documentencoding AUTO\n@documentlanguage AUTO"
|
||||||
("@chapter %s" . "@unnumbered %s")
|
("@chapter %s" "@unnumbered %s" "@appendix %s")
|
||||||
("@section %s" . "@unnumberedsec %s")
|
("@section %s" "@unnumberedsec %s" "@appendixsec %s")
|
||||||
("@subsection %s" . "@unnumberedsubsec %s")
|
("@subsection %s" "@unnumberedsubsec %s" "@appendixsubsec %s")
|
||||||
("@subsubsection %s" . "@unnumberedsubsubsec %s")))
|
("@subsubsection %s" "@unnumberedsubsubsec %s" "@appendixsubsubsec %s")))
|
||||||
"Alist of Texinfo classes and associated header and structure.
|
"Alist of Texinfo classes and associated header and structure.
|
||||||
If #+TEXINFO_CLASS is set in the buffer, use its value and the
|
If #+TEXINFO_CLASS is set in the buffer, use its value and the
|
||||||
associated information. Here is the structure of each cell:
|
associated information. Here is the structure of a class
|
||||||
|
definition:
|
||||||
|
|
||||||
(class-name
|
(class-name
|
||||||
header-string
|
header-string
|
||||||
(numbered-section . unnumbered-section)
|
(numbered-1 unnumbered-1 appendix-1)
|
||||||
|
(numbered-2 unnumbered-2 appendix-2)
|
||||||
...)
|
...)
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,25 +190,19 @@ The sectioning structure
|
||||||
The sectioning structure of the class is given by the elements
|
The sectioning structure of the class is given by the elements
|
||||||
following the header string. For each sectioning level, a number
|
following the header string. For each sectioning level, a number
|
||||||
of strings is specified. A %s formatter is mandatory in each
|
of strings is specified. A %s formatter is mandatory in each
|
||||||
section string and will be replaced by the title of the section.
|
section string and will be replaced by the title of the section."
|
||||||
|
|
||||||
Instead of a list of sectioning commands, you can also specify
|
|
||||||
a function name. That function will be called with two
|
|
||||||
parameters, the reduced) level of the headline, and a predicate
|
|
||||||
non-nil when the headline should be numbered. It must return
|
|
||||||
a format string in which the section title will be added."
|
|
||||||
:group 'org-export-texinfo
|
:group 'org-export-texinfo
|
||||||
:version "24.4"
|
:version "26.1"
|
||||||
:package-version '(Org . "8.2")
|
:package-version '(Org . "9.1")
|
||||||
:type '(repeat
|
:type '(repeat
|
||||||
(list (string :tag "Texinfo class")
|
(list (string :tag "Texinfo class")
|
||||||
(string :tag "Texinfo header")
|
(string :tag "Texinfo header")
|
||||||
(repeat :tag "Levels" :inline t
|
(repeat :tag "Levels" :inline t
|
||||||
(choice
|
(choice
|
||||||
(cons :tag "Heading"
|
(list :tag "Heading"
|
||||||
(string :tag " numbered")
|
(string :tag " numbered")
|
||||||
(string :tag "unnumbered"))
|
(string :tag "unnumbered")
|
||||||
(function :tag "Hook computing sectioning"))))))
|
(string :tag " appendix")))))))
|
||||||
|
|
||||||
;;;; Headline
|
;;;; Headline
|
||||||
|
|
||||||
|
@ -833,82 +829,74 @@ plist holding contextual information."
|
||||||
|
|
||||||
;;;; Headline
|
;;;; Headline
|
||||||
|
|
||||||
|
(defun org-texinfo--structuring-command (headline info)
|
||||||
|
"Return Texinfo structuring command string for HEADLINE element.
|
||||||
|
Return nil if HEADLINE is to be ignored, `plain-list' if it
|
||||||
|
should be exported as a plain-list item. INFO is a plist holding
|
||||||
|
contextual information."
|
||||||
|
(cond
|
||||||
|
((org-element-property :footnote-section-p headline) nil)
|
||||||
|
((org-not-nil (org-export-get-node-property :COPYING headline t)) nil)
|
||||||
|
((org-export-low-level-p headline info) 'plain-list)
|
||||||
|
(t
|
||||||
|
(let ((class (plist-get info :texinfo-class)))
|
||||||
|
(pcase (assoc class (plist-get info :texinfo-classes))
|
||||||
|
(`(,_ ,_ . ,sections)
|
||||||
|
(pcase (nth (1- (org-export-get-relative-level headline info))
|
||||||
|
sections)
|
||||||
|
(`(,numbered ,unnumbered ,appendix)
|
||||||
|
(cond
|
||||||
|
((org-not-nil (org-export-get-node-property :APPENDIX headline t))
|
||||||
|
appendix)
|
||||||
|
((org-not-nil (org-export-get-node-property :INDEX headline t))
|
||||||
|
unnumbered)
|
||||||
|
((org-export-numbered-headline-p headline info) numbered)
|
||||||
|
(t unnumbered)))
|
||||||
|
(`nil 'plain-list)
|
||||||
|
(_ (user-error "Invalid Texinfo class specification: %S" class))))
|
||||||
|
(_ (user-error "Invalid Texinfo class specification: %S" class)))))))
|
||||||
|
|
||||||
(defun org-texinfo-headline (headline contents info)
|
(defun org-texinfo-headline (headline contents info)
|
||||||
"Transcode a HEADLINE element from Org to Texinfo.
|
"Transcode a HEADLINE element from Org to Texinfo.
|
||||||
CONTENTS holds the contents of the headline. INFO is a plist
|
CONTENTS holds the contents of the headline. INFO is a plist
|
||||||
holding contextual information."
|
holding contextual information."
|
||||||
(let* ((class (plist-get info :texinfo-class))
|
(let ((section-fmt (org-texinfo--structuring-command headline info)))
|
||||||
(level (org-export-get-relative-level headline info))
|
(when section-fmt
|
||||||
(numberedp (org-export-numbered-headline-p headline info))
|
(let* ((todo
|
||||||
(class-sectioning (assoc class (plist-get info :texinfo-classes)))
|
(and (plist-get info :with-todo-keywords)
|
||||||
;; Find the index type, if any.
|
(let ((todo (org-element-property :todo-keyword headline)))
|
||||||
(index (org-element-property :INDEX headline))
|
(and todo (org-export-data todo info)))))
|
||||||
;; Create node info, to insert it before section formatting.
|
(todo-type (and todo (org-element-property :todo-type headline)))
|
||||||
;; Use custom menu title if present.
|
(tags (and (plist-get info :with-tags)
|
||||||
(node (format "@node %s\n" (org-texinfo--get-node headline info)))
|
(org-export-get-tags headline info)))
|
||||||
;; Section formatting will set two placeholders: one for the
|
(priority (and (plist-get info :with-priority)
|
||||||
;; title and the other for the contents.
|
(org-element-property :priority headline)))
|
||||||
(section-fmt
|
(text (org-texinfo--sanitize-title
|
||||||
(if (org-not-nil (org-element-property :APPENDIX headline))
|
(org-element-property :title headline) info))
|
||||||
"@appendix %s\n%s"
|
(full-text
|
||||||
(let ((sec (if (and (symbolp (nth 2 class-sectioning))
|
(funcall (plist-get info :texinfo-format-headline-function)
|
||||||
(fboundp (nth 2 class-sectioning)))
|
todo todo-type priority text tags))
|
||||||
(funcall (nth 2 class-sectioning) level numberedp)
|
(contents
|
||||||
(nth (1+ level) class-sectioning))))
|
(concat (if (org-string-nw-p contents)
|
||||||
(cond
|
(concat "\n" contents)
|
||||||
;; No section available for that LEVEL.
|
"")
|
||||||
((not sec) nil)
|
(let ((index (org-element-property :INDEX headline)))
|
||||||
;; Section format directly returned by a function.
|
(and (member index '("cp" "fn" "ky" "pg" "tp" "vr"))
|
||||||
((stringp sec) sec)
|
(format "\n@printindex %s\n" index))))))
|
||||||
;; (numbered-section . unnumbered-section)
|
(cond
|
||||||
((not (consp (cdr sec)))
|
((eq section-fmt 'plain-list)
|
||||||
(concat (if (or index (not numberedp)) (cdr sec) (car sec))
|
(let ((numbered? (org-export-numbered-headline-p headline info)))
|
||||||
"\n%s"))))))
|
(concat (and (org-export-first-sibling-p headline info)
|
||||||
(todo
|
(format "@%s\n" (if numbered? 'enumerate 'itemize)))
|
||||||
(and (plist-get info :with-todo-keywords)
|
"@item\n" full-text "\n"
|
||||||
(let ((todo (org-element-property :todo-keyword headline)))
|
contents
|
||||||
(and todo (org-export-data todo info)))))
|
(if (org-export-last-sibling-p headline info)
|
||||||
(todo-type (and todo (org-element-property :todo-type headline)))
|
(format "@end %s" (if numbered? 'enumerate 'itemize))
|
||||||
(tags (and (plist-get info :with-tags)
|
"\n"))))
|
||||||
(org-export-get-tags headline info)))
|
(t
|
||||||
(priority (and (plist-get info :with-priority)
|
(concat (format "@node %s\n" (org-texinfo--get-node headline info))
|
||||||
(org-element-property :priority headline)))
|
(format section-fmt full-text)
|
||||||
(text (org-texinfo--sanitize-title
|
contents)))))))
|
||||||
(org-element-property :title headline) info))
|
|
||||||
(full-text (funcall (plist-get info :texinfo-format-headline-function)
|
|
||||||
todo todo-type priority text tags))
|
|
||||||
(contents (if (org-string-nw-p contents) (concat "\n" contents) "")))
|
|
||||||
(cond
|
|
||||||
;; Case 1: This is a footnote section: ignore it.
|
|
||||||
((org-element-property :footnote-section-p headline) nil)
|
|
||||||
;; Case 2: This is the `copying' section: ignore it
|
|
||||||
;; This is used elsewhere.
|
|
||||||
((org-not-nil (org-element-property :COPYING headline)) nil)
|
|
||||||
;; Case 3: An index. If it matches one of the known indexes,
|
|
||||||
;; print it as such following the contents, otherwise
|
|
||||||
;; print the contents and leave the index up to the user.
|
|
||||||
(index
|
|
||||||
(concat node
|
|
||||||
(format
|
|
||||||
section-fmt
|
|
||||||
full-text
|
|
||||||
(concat contents
|
|
||||||
(and (member index '("cp" "fn" "ky" "pg" "tp" "vr"))
|
|
||||||
(concat "\n@printindex " index))))))
|
|
||||||
;; Case 4: This is a deep sub-tree: export it as a list item.
|
|
||||||
;; Also export as items headlines for which no section
|
|
||||||
;; format has been found.
|
|
||||||
((or (not section-fmt) (org-export-low-level-p headline info))
|
|
||||||
;; Build the real contents of the sub-tree.
|
|
||||||
(concat (and (org-export-first-sibling-p headline info)
|
|
||||||
(format "@%s\n" (if numberedp 'enumerate 'itemize)))
|
|
||||||
"@item\n" full-text "\n"
|
|
||||||
contents
|
|
||||||
(if (org-export-last-sibling-p headline info)
|
|
||||||
(format "@end %s" (if numberedp 'enumerate 'itemize))
|
|
||||||
"\n")))
|
|
||||||
;; Case 5: Standard headline. Export it as a section.
|
|
||||||
(t (concat node (format section-fmt full-text contents))))))
|
|
||||||
|
|
||||||
(defun org-texinfo-format-headline-default-function
|
(defun org-texinfo-format-headline-default-function
|
||||||
(todo _todo-type priority text tags)
|
(todo _todo-type priority text tags)
|
||||||
|
|
Loading…
Reference in a new issue