Browse Source

Introduced org-lparse-begin-collect and org-lparse-end-collect

* contrib/lisp/org-lparse.el (org-lparse-footnote-buffer):
Deleted.  Genericized as `org-lparse-collect-buffer'.
(org-lparse-output-buffer): Added docstring.
(org-lparse-collect-buffer): New variable.  Was
`org-lparse-footnote-buffer' till now.
(org-lparse-collect-count): New variable to aid in asserting
implicit assumptions made by the export engine.
(org-lparse-begin-collect): New function.  Factored out from
`org-lparse-begin-footnote-definition'.
(org-lparse-end-collect): New function.  Factored out from
`org-lparse-end-footnote-definition'.
(org-lparse-begin-footnote-definition)
(org-lparse-end-footnote-definition): Use above functions.
(org-do-lparse): Reset `org-lparse-collect-buffer' and
`org-lparse-collect-count' at the beginning of export.
Cleanup `org-lparse-collect-buffer'.

* contrib/lisp/org-xhtml.el (org-xhtml-end-export): Removed
references to `org-lparse-footnote-buffer'.
Jambunathan K 13 years ago
parent
commit
219e7d60db
2 changed files with 49 additions and 15 deletions
  1. 49 10
      contrib/lisp/org-lparse.el
  2. 0 5
      contrib/lisp/org-xhtml.el

+ 49 - 10
contrib/lisp/org-lparse.el

@@ -884,7 +884,12 @@ version."
 	 org-lparse-output-buffer
 	 org-lparse-footnote-definitions
 	 org-lparse-footnote-number
-	 org-lparse-footnote-buffer
+	 ;; collection
+	 org-lparse-collect-buffer
+	 (org-lparse-collect-count 0)	; things will get haywire if
+					; collections are chained. Use
+					; this variable to assert this
+					; pre-requisite
 	 org-lparse-toc
 	 href
 	 )
@@ -1259,6 +1264,10 @@ version."
 
       (org-lparse-end 'EXPORT)
 
+      ;; kill collection buffer
+      (when org-lparse-collect-buffer
+	(kill-buffer org-lparse-collect-buffer))
+      
       (goto-char (point-min))
       (or (org-export-push-to-kill-ring
 	   (upcase (symbol-name org-lparse-backend)))
@@ -1769,8 +1778,10 @@ the alist of previous items."
 (defvar org-lparse-table-cur-rowgrp-is-hdr)
 (defvar org-lparse-footnote-number)
 (defvar org-lparse-footnote-definitions)
-(defvar org-lparse-footnote-buffer)
-(defvar org-lparse-output-buffer)
+(defvar org-lparse-output-buffer nil
+  "Buffer to which `org-do-lparse' writes to.
+This buffer contains the contents of the to-be-created exported
+document.")
 
 (defcustom org-lparse-debug nil
   "Enable or Disable logging of `org-lparse' callbacks.
@@ -1892,19 +1903,47 @@ See `org-lparse-list-table-enable'.")
   (eq org-lparse-dyn-current-environment style))
 
 (defun org-lparse-begin-footnote-definition (n)
-  (unless org-lparse-footnote-buffer
-    (setq org-lparse-footnote-buffer
-	  (get-buffer-create "*Org HTML Export Footnotes*")))
-  (set-buffer org-lparse-footnote-buffer)
-  (erase-buffer)
+  (org-lparse-begin-collect)
   (setq org-lparse-insert-tag-with-newlines nil)
   (org-lparse-begin 'FOOTNOTE-DEFINITION n))
 
 (defun org-lparse-end-footnote-definition (n)
   (org-lparse-end 'FOOTNOTE-DEFINITION n)
   (setq org-lparse-insert-tag-with-newlines 'both)
-  (push (cons n (buffer-string)) org-lparse-footnote-definitions)
-  (set-buffer org-lparse-output-buffer))
+  (let ((footnote-def (org-lparse-end-collect)))
+    (push (cons n footnote-def) org-lparse-footnote-definitions)))
+
+(defvar org-lparse-collect-buffer nil
+  "An auxiliary buffer named \"*Org Lparse Collect*\".
+`org-do-lparse' uses this as output buffer while collecting
+footnote definitions and table-cell contents of list-tables.  See
+`org-lparse-begin-collect' and `org-lparse-end-collect'.")
+
+(defvar org-lparse-collect-count nil
+  "Count number of calls to `org-lparse-begin-collect'.
+Use this counter to catch chained collections if they ever
+happen.")
+
+(defun org-lparse-begin-collect ()
+  "Temporarily switch to `org-lparse-collect-buffer'.
+Also erase it's contents."
+  (unless (zerop org-lparse-collect-count)
+    (error "FIXME (org-lparse.el): Encountered chained collections"))
+  (incf org-lparse-collect-count)
+  (unless org-lparse-collect-buffer
+    (setq org-lparse-collect-buffer
+	  (get-buffer-create "*Org Lparse Collect*")))
+  (set-buffer org-lparse-collect-buffer)
+  (erase-buffer))
+
+(defun org-lparse-end-collect ()
+  "Switch to `org-lparse-output-buffer'.
+Return contents of `org-lparse-collect-buffer' as a `string'."
+  (assert (> org-lparse-collect-count 0))
+  (decf org-lparse-collect-count)
+  (prog1 (buffer-string)
+    (erase-buffer)
+    (set-buffer org-lparse-output-buffer)))
 
 (defun org-lparse-format (entity &rest args)
   "Format ENTITY in backend-specific way and return it.

+ 0 - 5
contrib/lisp/org-xhtml.el

@@ -983,7 +983,6 @@ that uses these same face definitions."
 
 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
 (defvar org-lparse-toc)
-(defvar org-lparse-footnote-buffer)
 (defvar org-lparse-footnote-definitions)
 (defvar org-lparse-dyn-first-heading-pos)
 
@@ -1015,10 +1014,6 @@ that uses these same face definitions."
   ;; Remove display properties
   (remove-text-properties (point-min) (point-max) '(display t))
 
-  ;; kill temporary buffers
-  (when org-lparse-footnote-buffer
-    (kill-buffer org-lparse-footnote-buffer))
-
   ;; Run the hook
   (run-hooks 'org-export-xhtml-final-hook))