contrib/lisp/org-e-texinfo.el: Fix export bugs

* contrib/lisp/org-e-texinfo.el (org-e-texinfo--generate-detailed): Do
  not run if there are no headlines in the file.
(org-e-texinfo-template): Generate menu and detailed menu in initial
let form.  Only insert them if non-empty.
(org-e-texinfo-headline): Ensure that %'s are properly escaped in
@node's to prevent parse errors.
(org-e-texinfo-make-menu): Do not insert "detailed" if menu is empty,
return empty entry instead.

Thanks to Bastien for reporting the failures with headline-less files
and simple "%" in the headline.
This commit is contained in:
Jonathan Leech-Pepin 2012-08-22 11:06:07 -04:00
parent 841d949d9c
commit 9e0f48db2f
1 changed files with 40 additions and 34 deletions

View File

@ -529,6 +529,7 @@ recurse into all children as well."
MENU is the parse-tree to work with. LEVEL is the starting level
for the menu headlines and from which recursion occurs. INFO is
a plist containing contextual information."
(when level
(let ((max-depth (plist-get info :headline-levels)))
(when (> max-depth level)
(loop for headline in menu append
@ -546,7 +547,7 @@ a plist containing contextual information."
;; Start the process over the next level down.
(recursion (org-e-texinfo--generate-detailed sublist (1+ level) info)))
(setq recursion (append submenu recursion))
recursion)))))
recursion))))))
(defun org-e-texinfo--generate-menu-list (tree level info)
"Generate the list of headlines that are within a given level
@ -656,7 +657,9 @@ holding export options."
(dirdesc (plist-get info :texinfo-dirdesc))
;; Spacing to align description (column 32 - 3 for `* ' and
;; `.' in text.
(dirspacing (- 29 (length dirtitle))))
(dirspacing (- 29 (length dirtitle)))
(menu (org-e-texinfo-make-menu info 'main))
(detail-menu (org-e-texinfo-make-menu info 'detailed)))
(concat
;; Header
header "\n"
@ -721,17 +724,20 @@ holding export options."
"@insertcopying\n"
"@end ifnottex\n\n"
;; Do not output menus if they are empty
(if menu
;; Menu
"@menu\n"
(org-e-texinfo-make-menu info 'main)
(concat "@menu\n"
menu
"\n\n"
;; Detailed Menu
"@detailmenu\n"
(if detail-menu
(concat "@detailmenu\n"
" --- The Detailed Node Listing ---\n"
(org-e-texinfo-make-menu info 'detailed)
detail-menu
"\n\n"
"@end detailmenu\n"
"@end menu\n"
"@end detailmenu\n"))
"@end menu\n"))
"\n\n"
;; Document's body.
@ -902,8 +908,9 @@ holding contextual information."
(index (org-element-property :index headline))
;; Create node info, to insert it before section formatting.
(node (format "@node %s\n"
(org-export-data
(org-element-property :title headline) info)))
(replace-regexp-in-string
"%" "%%"
(org-export-data (org-element-property :title headline) info))))
;; Menus must be generated with first child, otherwise they
;; will not nest properly
(menu (let* ((first (org-export-first-sibling-p headline info))
@ -1254,8 +1261,7 @@ are generated directly."
((eq level 'detailed)
;; Requires recursion
;;(org-e-texinfo--build-detailed-menu parse top info)
(or (org-e-texinfo--build-menu parse top info 'detailed)
"detailed"))
(org-e-texinfo--build-menu parse top info 'detailed))
;; Otherwise do nothing
(t))))