summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Leech-Pepin <jonathan.leechpepin@gmail.com>2012-08-22 11:06:07 -0400
committerJonathan Leech-Pepin <jonathan.leechpepin@gmail.com>2012-08-22 13:51:46 -0400
commit9e0f48db2f504ebe1d23b94e06810668074f3a25 (patch)
treec3bcf051401c4ed7534820c9e28d7a8d424dc5c2
parent841d949d9c59bb165076f0f5890d97214e513528 (diff)
downloadorg-mode-9e0f48db2f504ebe1d23b94e06810668074f3a25.tar.gz
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.
-rw-r--r--contrib/lisp/org-e-texinfo.el74
1 files changed, 40 insertions, 34 deletions
diff --git a/contrib/lisp/org-e-texinfo.el b/contrib/lisp/org-e-texinfo.el
index da40758..ac893ea 100644
--- a/contrib/lisp/org-e-texinfo.el
+++ b/contrib/lisp/org-e-texinfo.el
@@ -529,24 +529,25 @@ 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."
- (let ((max-depth (plist-get info :headline-levels)))
- (when (> max-depth level)
- (loop for headline in menu append
- (let* ((title (org-e-texinfo--menu-headlines headline info))
- ;; Create list of menu entries for the next level
- (sublist (org-e-texinfo--generate-menu-list
- headline (1+ level) info))
- ;; Generate the menu items for that level. If
- ;; there are none omit that heading completely,
- ;; otherwise join the title to it's related entries.
- (submenu (if (org-e-texinfo--generate-menu-items sublist info)
- (append (list title)
- (org-e-texinfo--generate-menu-items sublist info))
- 'nil))
- ;; Start the process over the next level down.
- (recursion (org-e-texinfo--generate-detailed sublist (1+ level) info)))
- (setq recursion (append submenu recursion))
- recursion)))))
+ (when level
+ (let ((max-depth (plist-get info :headline-levels)))
+ (when (> max-depth level)
+ (loop for headline in menu append
+ (let* ((title (org-e-texinfo--menu-headlines headline info))
+ ;; Create list of menu entries for the next level
+ (sublist (org-e-texinfo--generate-menu-list
+ headline (1+ level) info))
+ ;; Generate the menu items for that level. If
+ ;; there are none omit that heading completely,
+ ;; otherwise join the title to it's related entries.
+ (submenu (if (org-e-texinfo--generate-menu-items sublist info)
+ (append (list title)
+ (org-e-texinfo--generate-menu-items sublist info))
+ 'nil))
+ ;; Start the process over the next level down.
+ (recursion (org-e-texinfo--generate-detailed sublist (1+ level) info)))
+ (setq recursion (append submenu 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"
- ;; Menu
- "@menu\n"
- (org-e-texinfo-make-menu info 'main)
- "\n\n"
- ;; Detailed Menu
- "@detailmenu\n"
- " --- The Detailed Node Listing ---\n"
- (org-e-texinfo-make-menu info 'detailed)
- "\n\n"
- "@end detailmenu\n"
- "@end menu\n"
+ ;; Do not output menus if they are empty
+ (if menu
+ ;; Menu
+ (concat "@menu\n"
+ menu
+ "\n\n"
+ ;; Detailed Menu
+ (if detail-menu
+ (concat "@detailmenu\n"
+ " --- The Detailed Node Listing ---\n"
+ detail-menu
+ "\n\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))))