Browse Source

Use `org-export-current-backend' whenever possible.

* org-special-blocks.el
(org-special-blocks-make-special-cookies): Use
`org-export-current-backend'.

* org-publish.el (org-publish-aux-preprocess): Use
`org-export-current-backend'.

* org-inlinetask.el (org-inlinetask-export-handler): Use
`org-export-current-backend'.

* org-exp.el (org-export-current-backend): New variable.
(org-export-preprocess-string)
(org-export-format-drawer-function)
(org-export-remove-or-extract-drawers)
(org-export-format-drawer)
(org-export-convert-protected-spaces)
(org-export-select-backend-specific-text)
(org-export-mark-list-end, org-export-mark-list-properties)
(org-export-attach-captions-and-attributes)
(org-export-replace-src-segments-and-examples)
(org-export-format-source-code-or-example)
(org-export-number-lines): Use the new global variable instead
of a local variable.

* org-exp-blocks.el (org-export-blocks-format-ditaa)
(org-export-blocks-format-dot)
(org-export-blocks-format-comment): Use
`org-export-current-backend'.
Bastien Guerry 14 years ago
parent
commit
99675ffead
5 changed files with 66 additions and 62 deletions
  1. 4 5
      lisp/org-exp-blocks.el
  2. 55 51
      lisp/org-exp.el
  3. 3 2
      lisp/org-inlinetask.el
  4. 1 2
      lisp/org-publish.el
  5. 3 2
      lisp/org-special-blocks.el

+ 4 - 5
lisp/org-exp-blocks.el

@@ -76,8 +76,6 @@
   (require 'cl))
   (require 'cl))
 (require 'org)
 (require 'org)
 
 
-(defvar backend) ; dynamically scoped from caller
-
 (defvar org-exp-blocks-block-regexp
 (defvar org-exp-blocks-block-regexp
   (concat
   (concat
    "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)"
    "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)"
@@ -222,6 +220,7 @@ which defaults to the value of `org-export-blocks-witheld'."
 				(file-name-directory (or load-file-name buffer-file-name)))))))
 				(file-name-directory (or load-file-name buffer-file-name)))))))
   "Path to the ditaa jar executable.")
   "Path to the ditaa jar executable.")
 
 
+(defvar org-export-current-backend) ; dynamically bound in org-exp.el
 (defun org-export-blocks-format-ditaa (body &rest headers)
 (defun org-export-blocks-format-ditaa (body &rest headers)
   "DEPRECATED: use begin_src ditaa code blocks
   "DEPRECATED: use begin_src ditaa code blocks
 
 
@@ -250,7 +249,7 @@ passed to the ditaa utility as command line arguments."
 			    "\n")))
 			    "\n")))
     (prog1
     (prog1
     (cond
     (cond
-     ((member backend '(html latex docbook))
+     ((member org-export-current-backend '(html latex docbook))
       (unless (file-exists-p out-file)
       (unless (file-exists-p out-file)
         (mapc ;; remove old hashed versions of this file
         (mapc ;; remove old hashed versions of this file
          (lambda (file)
          (lambda (file)
@@ -309,7 +308,7 @@ digraph data_relationships {
 	 (out-file (concat (car out-file-parts) "_" hash "." (cdr out-file-parts))))
 	 (out-file (concat (car out-file-parts) "_" hash "." (cdr out-file-parts))))
     (prog1
     (prog1
     (cond
     (cond
-     ((member backend '(html latex docbook))
+     ((member org-export-current-backend '(html latex docbook))
       (unless (file-exists-p out-file)
       (unless (file-exists-p out-file)
 	(mapc ;; remove old hashed versions of this file
 	(mapc ;; remove old hashed versions of this file
 	 (lambda (file)
 	 (lambda (file)
@@ -341,7 +340,7 @@ other backends, it converts the comment into an EXAMPLE segment."
   (let ((owner (if headers (car headers)))
   (let ((owner (if headers (car headers)))
 	(title (if (cdr headers) (mapconcat 'identity (cdr headers) " "))))
 	(title (if (cdr headers) (mapconcat 'identity (cdr headers) " "))))
     (cond
     (cond
-     ((eq backend 'html) ;; We are exporting to HTML
+     ((eq org-export-current-backend 'html) ;; We are exporting to HTML
       (concat "#+BEGIN_HTML\n"
       (concat "#+BEGIN_HTML\n"
 	      "<div class=\"org-comment\""
 	      "<div class=\"org-comment\""
 	      (if owner (format " id=\"org-comment-%s\" " owner))
 	      (if owner (format " id=\"org-comment-%s\" " owner))

+ 55 - 51
lisp/org-exp.el

@@ -584,6 +584,14 @@ table.el tables."
 
 
 (defconst org-level-max 20)
 (defconst org-level-max 20)
 
 
+(defvar org-export-current-backend nil
+  "During export, this will be bound to a symbol such as 'html,
+  'latex, 'docbook, 'ascii, etc, indicating which of the export
+  backends is in use. Otherwise it has the value nil. Users
+  should not attempt to change the value of this variable
+  directly, but it can be used in code to test whether export is
+  in progress, and if so, what the backend is.")
+
 (defvar org-current-export-file nil) ; dynamically scoped parameter
 (defvar org-current-export-file nil) ; dynamically scoped parameter
 (defvar org-current-export-dir nil) ; dynamically scoped parameter
 (defvar org-current-export-dir nil) ; dynamically scoped parameter
 (defvar org-export-opt-plist nil
 (defvar org-export-opt-plist nil
@@ -1033,7 +1041,7 @@ to export.  It then creates a temporary buffer where it does its job.
 The result is then again returned as a string, and the exporter works
 The result is then again returned as a string, and the exporter works
 on this string to produce the exported version."
 on this string to produce the exported version."
   (interactive)
   (interactive)
-  (let* ((backend (plist-get parameters :for-backend))
+  (let* ((org-export-current-backend (plist-get parameters :for-backend))
 	 (archived-trees (plist-get parameters :archived-trees))
 	 (archived-trees (plist-get parameters :archived-trees))
 	 (inhibit-read-only t)
 	 (inhibit-read-only t)
 	 (drawers org-drawers)
 	 (drawers org-drawers)
@@ -1091,22 +1099,22 @@ on this string to produce the exported version."
 
 
       ;; Change lists ending. Other parts of export may insert blank
       ;; Change lists ending. Other parts of export may insert blank
       ;; lines and lists' structure could be altered.
       ;; lines and lists' structure could be altered.
-      (org-export-mark-list-end backend)
+      (org-export-mark-list-end)
 
 
       ;; Export code blocks
       ;; Export code blocks
       (org-export-blocks-preprocess)
       (org-export-blocks-preprocess)
 
 
       ;; Mark lists with properties
       ;; Mark lists with properties
-      (org-export-mark-list-properties backend)
+      (org-export-mark-list-properties)
 
 
       ;; Handle source code snippets
       ;; Handle source code snippets
-      (org-export-replace-src-segments-and-examples backend)
+      (org-export-replace-src-segments-and-examples)
 
 
       ;; Protect short examples marked by a leading colon
       ;; Protect short examples marked by a leading colon
       (org-export-protect-colon-examples)
       (org-export-protect-colon-examples)
 
 
       ;; Protected spaces
       ;; Protected spaces
-      (org-export-convert-protected-spaces backend)
+      (org-export-convert-protected-spaces)
 
 
       ;; Normalize footnotes
       ;; Normalize footnotes
       (when (plist-get parameters :footnotes)
       (when (plist-get parameters :footnotes)
@@ -1122,7 +1130,7 @@ on this string to produce the exported version."
 
 
       ;; Get rid of drawers
       ;; Get rid of drawers
       (org-export-remove-or-extract-drawers
       (org-export-remove-or-extract-drawers
-       drawers (plist-get parameters :drawers) backend)
+       drawers (plist-get parameters :drawers))
 
 
       ;; Get the correct stuff before the first headline
       ;; Get the correct stuff before the first headline
       (when (plist-get parameters :skip-before-1st-heading)
       (when (plist-get parameters :skip-before-1st-heading)
@@ -1145,7 +1153,7 @@ on this string to produce the exported version."
       ;; Select and protect backend specific stuff, throw away stuff
       ;; Select and protect backend specific stuff, throw away stuff
       ;; that is specific for other backends
       ;; that is specific for other backends
       (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
       (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
-      (org-export-select-backend-specific-text backend)
+      (org-export-select-backend-specific-text)
 
 
       ;; Protect quoted subtrees
       ;; Protect quoted subtrees
       (org-export-protect-quoted-subtrees)
       (org-export-protect-quoted-subtrees)
@@ -1165,8 +1173,7 @@ on this string to produce the exported version."
 	(org-export-remove-timestamps))
 	(org-export-remove-timestamps))
 
 
       ;; Attach captions to the correct object
       ;; Attach captions to the correct object
-      (setq target-alist (org-export-attach-captions-and-attributes
-			  backend target-alist))
+      (setq target-alist (org-export-attach-captions-and-attributes target-alist))
 
 
       ;; Find matches for radio targets and turn them into internal links
       ;; Find matches for radio targets and turn them into internal links
       (org-export-mark-radio-links)
       (org-export-mark-radio-links)
@@ -1198,7 +1205,7 @@ on this string to produce the exported version."
       (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
       (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
 
 
       ;; Backend-specific preprocessing
       ;; Backend-specific preprocessing
-      (let* ((backend-name (symbol-name backend))
+      (let* ((backend-name (symbol-name org-export-current-backend))
 	     (f (intern (format "org-export-%s-preprocess" backend-name))))
 	     (f (intern (format "org-export-%s-preprocess" backend-name))))
 	(require (intern (concat "org-" backend-name)) nil)
 	(require (intern (concat "org-" backend-name)) nil)
 	(funcall f parameters))
 	(funcall f parameters))
@@ -1374,17 +1381,16 @@ the current file."
 The function must accept three parameters:
 The function must accept three parameters:
   NAME     the drawer name, like \"PROPERTIES\"
   NAME     the drawer name, like \"PROPERTIES\"
   CONTENT  the content of the drawer.
   CONTENT  the content of the drawer.
-  BACKEND  one of the symbols html, docbook, latex, ascii, xoxo
+You can check the export backend through `org-export-current-backend'.
 The function should return the text to be inserted into the buffer.
 The function should return the text to be inserted into the buffer.
 If this is nil, `org-export-format-drawer' is used as a default.")
 If this is nil, `org-export-format-drawer' is used as a default.")
 
 
-(defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend)
+(defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
   "Remove drawers, or extract and format the content.
   "Remove drawers, or extract and format the content.
 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
 whose content to keep.  Any drawers that are in ALL-DRAWERS but not in
 whose content to keep.  Any drawers that are in ALL-DRAWERS but not in
-EXP-DRAWERS will be removed.
-BACKEND is the current export backend."
+EXP-DRAWERS will be removed."
   (goto-char (point-min))
   (goto-char (point-min))
   (let ((re (concat "^[ \t]*:\\("
   (let ((re (concat "^[ \t]*:\\("
 		    (mapconcat 'identity all-drawers "\\|")
 		    (mapconcat 'identity all-drawers "\\|")
@@ -1408,10 +1414,10 @@ BACKEND is the current export backend."
 		   (member name exp-drawers))
 		   (member name exp-drawers))
 	   (setq content (funcall (or org-export-format-drawer-function
 	   (setq content (funcall (or org-export-format-drawer-function
 				      'org-export-format-drawer)
 				      'org-export-format-drawer)
-				  name content backend))
+				  name content))
 	   (insert content)))))))
 	   (insert content)))))))
 
 
-(defun org-export-format-drawer (name content backend)
+(defun org-export-format-drawer (name content)
   "Format the content of a drawer as a colon example."
   "Format the content of a drawer as a colon example."
   (if (string-match "[ \t]+\\'" content)
   (if (string-match "[ \t]+\\'" content)
       (setq content (substring content (match-beginning 0))))
       (setq content (substring content (match-beginning 0))))
@@ -1547,7 +1553,7 @@ from the buffer."
       (add-text-properties (point) (org-end-of-subtree t)
       (add-text-properties (point) (org-end-of-subtree t)
 			   '(org-protected t)))))
 			   '(org-protected t)))))
 
 
-(defun org-export-convert-protected-spaces (backend)
+(defun org-export-convert-protected-spaces ()
   "Convert strings like \\____ to protected spaces in all backends."
   "Convert strings like \\____ to protected spaces in all backends."
   (goto-char (point-min))
   (goto-char (point-min))
   (while (re-search-forward "\\\\__+" nil t)
   (while (re-search-forward "\\\\__+" nil t)
@@ -1555,13 +1561,13 @@ from the buffer."
      (replace-match
      (replace-match
       (org-add-props
       (org-add-props
 	  (cond
 	  (cond
-	   ((eq backend 'latex)
+	   ((eq org-export-current-backend 'latex)
 	    (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
 	    (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
-	   ((eq backend 'html)
+	   ((eq org-export-current-backend 'html)
 	    (org-add-props (match-string 0) nil
 	    (org-add-props (match-string 0) nil
 	      'org-whitespace (- (match-end 0) (match-beginning 0))))
 	      'org-whitespace (- (match-end 0) (match-beginning 0))))
-	   ;; ((eq backend 'docbook))
-	   ((eq backend 'ascii)
+	   ;; ((eq org-export-current-backend 'docbook))
+	   ((eq org-export-current-backend 'ascii)
 	    (org-add-props (match-string 0) '(org-whitespace t)))
 	    (org-add-props (match-string 0) '(org-whitespace t)))
 	   (t (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
 	   (t (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
 	  '(org-protected t))
 	  '(org-protected t))
@@ -1589,7 +1595,7 @@ from the buffer."
       (add-text-properties beg (if (bolp) (1- (point)) (point))
       (add-text-properties beg (if (bolp) (1- (point)) (point))
 			   '(org-protected t)))))
 			   '(org-protected t)))))
 
 
-(defun org-export-select-backend-specific-text (backend)
+(defun org-export-select-backend-specific-text ()
   (let ((formatters
   (let ((formatters
 	 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
 	 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
 	   (html "HTML" "BEGIN_HTML" "END_HTML")
 	   (html "HTML" "BEGIN_HTML" "END_HTML")
@@ -1605,7 +1611,7 @@ from the buffer."
       (goto-char (point-min))
       (goto-char (point-min))
       (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
       (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt)
 					":[ \t]*\\(.*\\)") nil t)
 					":[ \t]*\\(.*\\)") nil t)
-	(if (not (eq (car fmt) backend))
+	(if (not (eq (car fmt) org-export-current-backend))
 	    (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
 	    (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
 	  (replace-match "\\1\\2" t)
 	  (replace-match "\\1\\2" t)
 	  (add-text-properties
 	  (add-text-properties
@@ -1618,7 +1624,7 @@ from the buffer."
       (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt)
       (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt)
 					":[ \t]*\\(.*\\)") nil t)
 					":[ \t]*\\(.*\\)") nil t)
 	(setq ind (org-get-indentation))
 	(setq ind (org-get-indentation))
-	(when (not (eq (car fmt) backend))
+	(when (not (eq (car fmt) org-export-current-backend))
 	  (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
 	  (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
       ;; Handle #+begin_backend and #+end_backend stuff
       ;; Handle #+begin_backend and #+end_backend stuff
       (goto-char (point-min))
       (goto-char (point-min))
@@ -1629,7 +1635,7 @@ from the buffer."
 	(when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
 	(when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?")
 				 nil t)
 				 nil t)
 	  (setq end (match-end 0) end-content (match-beginning 0))
 	  (setq end (match-end 0) end-content (match-beginning 0))
-	  (if (eq (car fmt) backend)
+	  (if (eq (car fmt) org-export-current-backend)
 	      ;; yes, keep this
 	      ;; yes, keep this
 	      (progn
 	      (progn
 		(add-text-properties
 		(add-text-properties
@@ -1666,9 +1672,9 @@ These special cookies will later be interpreted by the backend."
 	(delete-region beg end)
 	(delete-region beg end)
 	(insert (org-add-props content nil 'original-indentation ind))))))
 	(insert (org-add-props content nil 'original-indentation ind))))))
 
 
-(defun org-export-mark-list-end (backend)
+(defun org-export-mark-list-end ()
   "Mark all list endings with a special string."
   "Mark all list endings with a special string."
-  (unless (eq backend 'ascii)
+  (unless (eq org-export-current-backend 'ascii)
     (mapc
     (mapc
      (lambda (e)
      (lambda (e)
        ;; For each type allowing list export, find every list, remove
        ;; For each type allowing list export, find every list, remove
@@ -1697,7 +1703,7 @@ These special cookies will later be interpreted by the backend."
 			 (list 'original-indentation top-ind)))))))
 			 (list 'original-indentation top-ind)))))))
      (cons nil org-list-export-context))))
      (cons nil org-list-export-context))))
 
 
-(defun org-export-mark-list-properties (backend)
+(defun org-export-mark-list-properties ()
   "Mark list with special properties.
   "Mark list with special properties.
 These special properties will later be interpreted by the backend."
 These special properties will later be interpreted by the backend."
   (let ((mark-list
   (let ((mark-list
@@ -1750,7 +1756,7 @@ These special properties will later be interpreted by the backend."
 	      ;; Following property is used by LaTeX exporter.
 	      ;; Following property is used by LaTeX exporter.
 	      (add-text-properties top (point) (list 'list-context ctxt)))))))
 	      (add-text-properties top (point) (list 'list-context ctxt)))))))
     ;; Mark lists except for backends not interpreting them.
     ;; Mark lists except for backends not interpreting them.
-    (unless (eq backend 'ascii)
+    (unless (eq org-export-current-backend 'ascii)
       (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
       (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
 	(mapc
 	(mapc
 	 (lambda (e)
 	 (lambda (e)
@@ -1759,7 +1765,7 @@ These special properties will later be interpreted by the backend."
 	     (when (eq (nth 2 (org-list-context)) e) (funcall mark-list e))))
 	     (when (eq (nth 2 (org-list-context)) e) (funcall mark-list e))))
 	 (cons nil org-list-export-context))))))
 	 (cons nil org-list-export-context))))))
 
 
-(defun org-export-attach-captions-and-attributes (backend target-alist)
+(defun org-export-attach-captions-and-attributes (target-alist)
   "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
   "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
 If the next thing following is a table, add the text properties to the first
 If the next thing following is a table, add the text properties to the first
 table line.  If it is a link, add it to the line containing the link."
 table line.  If it is a link, add it to the line containing the link."
@@ -1769,7 +1775,7 @@ table line.  If it is a link, add it to the line containing the link."
   (let ((case-fold-search t)
   (let ((case-fold-search t)
 	(re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
 	(re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
 		    "\\|"
 		    "\\|"
-		    "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
+		    "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend) ":[ \t]+\\(.*\\)"
 		    "\\|"
 		    "\\|"
 		    "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
 		    "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
 		    "\\|"
 		    "\\|"
@@ -2318,7 +2324,7 @@ in the list) and remove property and value from the list in LISTVAR."
 
 
 (defvar org-export-last-code-line-counter-value 0)
 (defvar org-export-last-code-line-counter-value 0)
 
 
-(defun org-export-replace-src-segments-and-examples (backend)
+(defun org-export-replace-src-segments-and-examples ()
   "Replace source code segments with special code for export."
   "Replace source code segments with special code for export."
   (setq org-export-last-code-line-counter-value 0)
   (setq org-export-last-code-line-counter-value 0)
   (let ((case-fold-search t)
   (let ((case-fold-search t)
@@ -2351,7 +2357,7 @@ in the list) and remove property and value from the list in LISTVAR."
               caption (get-text-property 0 'org-caption (match-string 0))))
               caption (get-text-property 0 'org-caption (match-string 0))))
 
 
       (setq trans (org-export-format-source-code-or-example
       (setq trans (org-export-format-source-code-or-example
-		   backend lang code opts indent caption))
+		   lang code opts indent caption))
       (replace-match trans t t))))
       (replace-match trans t t))))
 
 
 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
 (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el
@@ -2364,7 +2370,7 @@ in the list) and remove property and value from the list in LISTVAR."
 (defvar org-export-latex-minted-options) ;; defined in org-latex.el
 (defvar org-export-latex-minted-options) ;; defined in org-latex.el
 
 
 (defun org-export-format-source-code-or-example
 (defun org-export-format-source-code-or-example
-  (backend lang code &optional opts indent caption)
+  (lang code &optional opts indent caption)
   "Format CODE from language LANG and return it formatted for export.
   "Format CODE from language LANG and return it formatted for export.
 If LANG is nil, do not add any fontification.
 If LANG is nil, do not add any fontification.
 OPTS contains formatting options, like `-n' for triggering numbering lines,
 OPTS contains formatting options, like `-n' for triggering numbering lines,
@@ -2390,7 +2396,7 @@ INDENT was the original indentation of the block."
 		   (org-count-lines code))
 		   (org-count-lines code))
 	    fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
 	    fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
 		    (match-string 1 opts)))
 		    (match-string 1 opts)))
-      (when (and textareap (eq backend 'html))
+      (when (and textareap (eq org-export-current-backend 'html))
 	;; we cannot use numbering or highlighting.
 	;; we cannot use numbering or highlighting.
 	(setq num nil cont nil lang nil))
 	(setq num nil cont nil lang nil))
       (if keepp (setq rpllbl 'keep))
       (if keepp (setq rpllbl 'keep))
@@ -2410,15 +2416,15 @@ INDENT was the original indentation of the block."
       ;; Now backend-specific coding
       ;; Now backend-specific coding
       (setq rtn
       (setq rtn
 	    (cond
 	    (cond
-	     ((eq backend 'docbook)
-	      (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
+	     ((eq org-export-current-backend 'docbook)
+	      (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
 	      (concat "\n#+BEGIN_DOCBOOK\n"
 	      (concat "\n#+BEGIN_DOCBOOK\n"
 		      (org-add-props (concat "<programlisting><![CDATA["
 		      (org-add-props (concat "<programlisting><![CDATA["
 					     rtn
 					     rtn
 					     "]]></programlisting>\n")
 					     "]]></programlisting>\n")
 			  '(org-protected t org-example t))
 			  '(org-protected t org-example t))
 		      "#+END_DOCBOOK\n"))
 		      "#+END_DOCBOOK\n"))
-	     ((eq backend 'html)
+	     ((eq org-export-current-backend 'html)
 	      ;; We are exporting to HTML
 	      ;; We are exporting to HTML
 	      (when lang
 	      (when lang
 		(if (featurep 'xemacs)
 		(if (featurep 'xemacs)
@@ -2482,13 +2488,12 @@ INDENT was the original indentation of the block."
 		    (setq rtn (buffer-string)))
 		    (setq rtn (buffer-string)))
 		  (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
 		  (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
 	      (unless textareap
 	      (unless textareap
-		(setq rtn (org-export-number-lines rtn 'html 1 1 num
-						   cont rpllbl fmt)))
+		(setq rtn (org-export-number-lines rtn 1 1 num cont rpllbl fmt)))
 	      (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
 	      (if (string-match "\\(\\`<[^>]*>\\)\n" rtn)
 		  (setq rtn (replace-match "\\1" t nil rtn)))
 		  (setq rtn (replace-match "\\1" t nil rtn)))
 	      (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t org-example t)) "\n#+END_HTML\n\n"))
 	      (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t org-example t)) "\n#+END_HTML\n\n"))
-	     ((eq backend 'latex)
-	      (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
+	     ((eq org-export-current-backend 'latex)
+	      (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
 	      (concat
 	      (concat
 	       "#+BEGIN_LaTeX\n"
 	       "#+BEGIN_LaTeX\n"
 	       (org-add-props
 	       (org-add-props
@@ -2544,9 +2549,9 @@ INDENT was the original indentation of the block."
                                rtn (cdr org-export-latex-verbatim-wrap))))
                                rtn (cdr org-export-latex-verbatim-wrap))))
                    '(org-protected t org-example t))
                    '(org-protected t org-example t))
                "#+END_LaTeX\n"))
                "#+END_LaTeX\n"))
-             ((eq backend 'ascii)
+             ((eq org-export-current-backend 'ascii)
               ;; This is not HTML or LaTeX, so just make it an example.
               ;; This is not HTML or LaTeX, so just make it an example.
-              (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
+              (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
               (concat caption "\n"
               (concat caption "\n"
                       "#+BEGIN_ASCII\n"
                       "#+BEGIN_ASCII\n"
                       (org-add-props
                       (org-add-props
@@ -2560,8 +2565,7 @@ INDENT was the original indentation of the block."
                       "#+END_ASCII\n"))))
                       "#+END_ASCII\n"))))
       (org-add-props rtn nil 'original-indentation indent))))
       (org-add-props rtn nil 'original-indentation indent))))
 
 
-(defun org-export-number-lines (text backend
-				     &optional skip1 skip2 number cont
+(defun org-export-number-lines (text &optional skip1 skip2 number cont
 				     replace-labels label-format)
 				     replace-labels label-format)
   (setq skip1 (or skip1 0) skip2 (or skip2 0))
   (setq skip1 (or skip1 0) skip2 (or skip2 0))
   (if (not cont) (setq org-export-last-code-line-counter-value 0))
   (if (not cont) (setq org-export-last-code-line-counter-value 0))
@@ -2577,11 +2581,11 @@ INDENT was the original indentation of the block."
 	   (fmt (format "%%%dd:  " (length (number-to-string nmax))))
 	   (fmt (format "%%%dd:  " (length (number-to-string nmax))))
 	   (fm
 	   (fm
 	    (cond
 	    (cond
-	     ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
+	     ((eq org-export-current-backend 'html) (format "<span class=\"linenr\">%s</span>"
 					 fmt))
 					 fmt))
-	     ((eq backend 'ascii) fmt)
-	     ((eq backend 'latex) fmt)
-	     ((eq backend 'docbook) fmt)
+	     ((eq org-export-current-backend 'ascii) fmt)
+	     ((eq org-export-current-backend 'latex) fmt)
+	     ((eq org-export-current-backend 'docbook) fmt)
 	     (t "")))
 	     (t "")))
 	   (label-format (or label-format org-coderef-label-format))
 	   (label-format (or label-format org-coderef-label-format))
 	   (label-pre (if (string-match "%s" label-format)
 	   (label-pre (if (string-match "%s" label-format)
@@ -2626,7 +2630,7 @@ INDENT was the original indentation of the block."
 		 (delete-region (match-beginning 2) (match-end 2))
 		 (delete-region (match-beginning 2) (match-end 2))
 		 (insert "(" ref ")")
 		 (insert "(" ref ")")
 		 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
 		 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
-	  (when (eq backend 'html)
+	  (when (eq org-export-current-backend 'html)
 	    (save-excursion
 	    (save-excursion
 	      (beginning-of-line 1)
 	      (beginning-of-line 1)
 	      (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
 	      (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"

+ 3 - 2
lisp/org-inlinetask.el

@@ -252,7 +252,7 @@ This assumes the point is inside an inline task."
     (re-search-backward (org-inlinetask-outline-regexp) nil t)
     (re-search-backward (org-inlinetask-outline-regexp) nil t)
     (- (match-end 1) (match-beginning 1))))
     (- (match-end 1) (match-beginning 1))))
 
 
-(defvar backend) ; dynamically scoped into the next function
+(defvar org-export-current-backend) ; dynamically bound in org-exp.el
 (defun org-inlinetask-export-handler ()
 (defun org-inlinetask-export-handler ()
   "Handle headlines with level larger or equal to `org-inlinetask-min-level'.
   "Handle headlines with level larger or equal to `org-inlinetask-min-level'.
 Either remove headline and meta data, or do special formatting."
 Either remove headline and meta data, or do special formatting."
@@ -302,7 +302,8 @@ Either remove headline and meta data, or do special formatting."
 		 (priority (or (match-string 3 headline) ""))
 		 (priority (or (match-string 3 headline) ""))
 		 (heading (or (match-string 4 headline) ""))
 		 (heading (or (match-string 4 headline) ""))
 		 (tags (or (match-string 5 headline) ""))
 		 (tags (or (match-string 5 headline) ""))
-		 (backend-spec (assq backend org-inlinetask-export-templates))
+		 (backend-spec (assq org-export-current-backend 
+				     org-inlinetask-export-templates))
 		 (format-str (org-add-props (nth 1 backend-spec)
 		 (format-str (org-add-props (nth 1 backend-spec)
 				 '(org-protected t)))
 				 '(org-protected t)))
 		 (tokens (cadr (nth 2 backend-spec)))
 		 (tokens (cadr (nth 2 backend-spec)))

+ 1 - 2
lisp/org-publish.el

@@ -931,7 +931,6 @@ the project."
 
 
 ;;; Index generation
 ;;; Index generation
 
 
-(defvar backend) ; dynamically scoped
 (defun org-publish-aux-preprocess ()
 (defun org-publish-aux-preprocess ()
   "Find index entries and write them to an .orgx file."
   "Find index entries and write them to an .orgx file."
   (let ((case-fold-search t)
   (let ((case-fold-search t)
@@ -942,7 +941,7 @@ the project."
 	 (re-search-forward "^[ \t]*#\\+index:[ \t]*\\(.*?\\)[ \t]*$" nil t)
 	 (re-search-forward "^[ \t]*#\\+index:[ \t]*\\(.*?\\)[ \t]*$" nil t)
 	 (> (match-end 1) (match-beginning 1)))
 	 (> (match-end 1) (match-beginning 1)))
       (setq entry (match-string 1))
       (setq entry (match-string 1))
-      (when (eq backend 'latex)
+      (when (eq org-export-current-backend 'latex)
 	(replace-match (format "\\index{%s}" entry) t t))
 	(replace-match (format "\\index{%s}" entry) t t))
       (save-excursion
       (save-excursion
 	(ignore-errors (org-back-to-heading t))
 	(ignore-errors (org-back-to-heading t))

+ 3 - 2
lisp/org-special-blocks.el

@@ -47,11 +47,12 @@
 by org-special-blocks.  These blocks will presumably be
 by org-special-blocks.  These blocks will presumably be
 interpreted by other mechanisms.")
 interpreted by other mechanisms.")
 
 
-(defvar backend) ; dynamically scoped
+(defvar org-export-current-backend) ; dynamically bound in org-exp.el
 (defun org-special-blocks-make-special-cookies ()
 (defun org-special-blocks-make-special-cookies ()
   "Adds special cookies when #+begin_foo and #+end_foo tokens are
   "Adds special cookies when #+begin_foo and #+end_foo tokens are
 seen.  This is run after a few special cases are taken care of."
 seen.  This is run after a few special cases are taken care of."
-  (when (or (eq backend 'html) (eq backend 'latex))
+  (when (or (eq org-export-current-backend 'html) 
+	    (eq org-export-current-backend 'latex))
     (goto-char (point-min))
     (goto-char (point-min))
     (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_\\(.*\\)$" nil t)
     (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_\\(.*\\)$" nil t)
       (unless (org-string-match-p org-special-blocks-ignore-regexp (match-string 2))
       (unless (org-string-match-p org-special-blocks-ignore-regexp (match-string 2))