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,24 +529,25 @@ 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."
(let ((max-depth (plist-get info :headline-levels))) (when level
(when (> max-depth level) (let ((max-depth (plist-get info :headline-levels)))
(loop for headline in menu append (when (> max-depth level)
(let* ((title (org-e-texinfo--menu-headlines headline info)) (loop for headline in menu append
;; Create list of menu entries for the next level (let* ((title (org-e-texinfo--menu-headlines headline info))
(sublist (org-e-texinfo--generate-menu-list ;; Create list of menu entries for the next level
headline (1+ level) info)) (sublist (org-e-texinfo--generate-menu-list
;; Generate the menu items for that level. If headline (1+ level) info))
;; there are none omit that heading completely, ;; Generate the menu items for that level. If
;; otherwise join the title to it's related entries. ;; there are none omit that heading completely,
(submenu (if (org-e-texinfo--generate-menu-items sublist info) ;; otherwise join the title to it's related entries.
(append (list title) (submenu (if (org-e-texinfo--generate-menu-items sublist info)
(org-e-texinfo--generate-menu-items sublist info)) (append (list title)
'nil)) (org-e-texinfo--generate-menu-items sublist info))
;; Start the process over the next level down. 'nil))
(recursion (org-e-texinfo--generate-detailed sublist (1+ level) info))) ;; Start the process over the next level down.
(setq recursion (append submenu recursion)) (recursion (org-e-texinfo--generate-detailed sublist (1+ level) info)))
recursion))))) (setq recursion (append submenu 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"
;; Menu ;; Do not output menus if they are empty
"@menu\n" (if menu
(org-e-texinfo-make-menu info 'main) ;; Menu
"\n\n" (concat "@menu\n"
;; Detailed Menu menu
"@detailmenu\n" "\n\n"
" --- The Detailed Node Listing ---\n" ;; Detailed Menu
(org-e-texinfo-make-menu info 'detailed) (if detail-menu
"\n\n" (concat "@detailmenu\n"
"@end detailmenu\n" " --- The Detailed Node Listing ---\n"
"@end menu\n" detail-menu
"\n\n"
"@end detailmenu\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))))