From 2ac428a21d544b35831265cad0df9a1372b268f2 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Fri, 27 Jan 2012 12:50:19 +0530 Subject: [PATCH] org-odt.el: Honor "[TABLE-OF-CONTENTS]" directive * lisp/org-odt.el (org-odt-format-preamble): Don't insert TOC here. Delay it till the end of export. (org-odt-begin-document-body): Make a note of the default position of TOC in `org-lparse-dyn-first-heading-pos'. (org-odt-insert-toc): Insert TOC as directed by [TABLE-OF-CONTENTS] line or at the default position. (org-odt-end-export): Call `org-odt-insert-toc'. Fix for the following bug: http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00974.html --- lisp/org-odt.el | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lisp/org-odt.el b/lisp/org-odt.el index a21995b23..19c21d199 100644 --- a/lisp/org-odt.el +++ b/lisp/org-odt.el @@ -35,7 +35,20 @@ :tag "Org Export ODT" :group 'org-export) +(defun org-odt-insert-toc () + (goto-char (point-min)) + (cond + ((re-search-forward + "\\(]*>\\)?\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*\\(\\)?" + nil t) + (goto-char (match-beginning 0)) + (replace-match "")) + (t + (goto-char org-lparse-dyn-first-heading-pos)) + (insert (org-odt-format-toc)))) + (defun org-odt-end-export () + (org-odt-insert-toc) (org-odt-fixup-label-references) ;; remove empty paragraphs @@ -611,13 +624,12 @@ PUB-DIR is set, use this as the publishing directory." '("" . "") date "N75" iso-date)) ;; separator - "")) - ;; toc - (org-odt-format-toc)))) + ""))))) (defun org-odt-begin-document-body (opt-plist) (org-odt-begin-office-body) - (insert (org-odt-format-preamble opt-plist))) + (insert (org-odt-format-preamble opt-plist)) + (setq org-lparse-dyn-first-heading-pos (point))) (defvar org-lparse-body-only) ; let bound during org-do-lparse (defvar org-lparse-to-buffer) ; let bound during org-do-lparse