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