From 99675ffead44e32f4959909a657b88831fe33703 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Tue, 1 Mar 2011 20:01:42 +0100 Subject: [PATCH] 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'. --- lisp/org-exp-blocks.el | 9 ++-- lisp/org-exp.el | 106 +++++++++++++++++++------------------ lisp/org-inlinetask.el | 5 +- lisp/org-publish.el | 3 +- lisp/org-special-blocks.el | 5 +- 5 files changed, 66 insertions(+), 62 deletions(-) diff --git a/lisp/org-exp-blocks.el b/lisp/org-exp-blocks.el index df41c4014..8b73ba6e7 100644 --- a/lisp/org-exp-blocks.el +++ b/lisp/org-exp-blocks.el @@ -76,8 +76,6 @@ (require 'cl)) (require 'org) -(defvar backend) ; dynamically scoped from caller - (defvar org-exp-blocks-block-regexp (concat "^\\([ \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))))))) "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) "DEPRECATED: use begin_src ditaa code blocks @@ -250,7 +249,7 @@ passed to the ditaa utility as command line arguments." "\n"))) (prog1 (cond - ((member backend '(html latex docbook)) + ((member org-export-current-backend '(html latex docbook)) (unless (file-exists-p out-file) (mapc ;; remove old hashed versions of this file (lambda (file) @@ -309,7 +308,7 @@ digraph data_relationships { (out-file (concat (car out-file-parts) "_" hash "." (cdr out-file-parts)))) (prog1 (cond - ((member backend '(html latex docbook)) + ((member org-export-current-backend '(html latex docbook)) (unless (file-exists-p out-file) (mapc ;; remove old hashed versions of this file (lambda (file) @@ -341,7 +340,7 @@ other backends, it converts the comment into an EXAMPLE segment." (let ((owner (if headers (car headers))) (title (if (cdr headers) (mapconcat 'identity (cdr headers) " ")))) (cond - ((eq backend 'html) ;; We are exporting to HTML + ((eq org-export-current-backend 'html) ;; We are exporting to HTML (concat "#+BEGIN_HTML\n" "
.*\n?") nil t) (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 (progn (add-text-properties @@ -1666,9 +1672,9 @@ These special cookies will later be interpreted by the backend." (delete-region beg end) (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." - (unless (eq backend 'ascii) + (unless (eq org-export-current-backend 'ascii) (mapc (lambda (e) ;; 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))))))) (cons nil org-list-export-context)))) -(defun org-export-mark-list-properties (backend) +(defun org-export-mark-list-properties () "Mark list with special properties. These special properties will later be interpreted by the backend." (let ((mark-list @@ -1750,7 +1756,7 @@ These special properties will later be interpreted by the backend." ;; Following property is used by LaTeX exporter. (add-text-properties top (point) (list 'list-context ctxt))))))) ;; 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")) (mapc (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)))) (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. 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." @@ -1769,7 +1775,7 @@ table line. If it is a link, add it to the line containing the link." (let ((case-fold-search t) (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)" "\\|" - "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)" + "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend) ":[ \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) -(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." (setq org-export-last-code-line-counter-value 0) (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)))) (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)))) (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 (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. If LANG is nil, do not add any fontification. 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)) fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" 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. (setq num nil cont nil lang nil)) (if keepp (setq rpllbl 'keep)) @@ -2410,15 +2416,15 @@ INDENT was the original indentation of the block." ;; Now backend-specific coding (setq rtn (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" (org-add-props (concat "\n") '(org-protected t org-example t)) "#+END_DOCBOOK\n")) - ((eq backend 'html) + ((eq org-export-current-backend 'html) ;; We are exporting to HTML (when lang (if (featurep 'xemacs) @@ -2482,13 +2488,12 @@ INDENT was the original indentation of the block." (setq rtn (buffer-string))) (setq rtn (concat "
\n" rtn "
\n")))) (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) (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")) - ((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 "#+BEGIN_LaTeX\n" (org-add-props @@ -2544,9 +2549,9 @@ INDENT was the original indentation of the block." rtn (cdr org-export-latex-verbatim-wrap)))) '(org-protected t org-example t)) "#+END_LaTeX\n")) - ((eq backend 'ascii) + ((eq org-export-current-backend 'ascii) ;; 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" "#+BEGIN_ASCII\n" (org-add-props @@ -2560,8 +2565,7 @@ INDENT was the original indentation of the block." "#+END_ASCII\n")))) (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) (setq skip1 (or skip1 0) skip2 (or skip2 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)))) (fm (cond - ((eq backend 'html) (format "%s" + ((eq org-export-current-backend 'html) (format "%s" 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 ""))) (label-format (or label-format org-coderef-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)) (insert "(" ref ")") (push (cons ref (concat "(" ref ")")) org-export-code-refs))) - (when (eq backend 'html) + (when (eq org-export-current-backend 'html) (save-excursion (beginning-of-line 1) (insert (format "" diff --git a/lisp/org-inlinetask.el b/lisp/org-inlinetask.el index 31a5dbef7..6bf38df3c 100644 --- a/lisp/org-inlinetask.el +++ b/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) (- (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 () "Handle headlines with level larger or equal to `org-inlinetask-min-level'. 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) "")) (heading (or (match-string 4 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) '(org-protected t))) (tokens (cadr (nth 2 backend-spec))) diff --git a/lisp/org-publish.el b/lisp/org-publish.el index 649e39a37..97fe956d7 100644 --- a/lisp/org-publish.el +++ b/lisp/org-publish.el @@ -931,7 +931,6 @@ the project." ;;; Index generation -(defvar backend) ; dynamically scoped (defun org-publish-aux-preprocess () "Find index entries and write them to an .orgx file." (let ((case-fold-search t) @@ -942,7 +941,7 @@ the project." (re-search-forward "^[ \t]*#\\+index:[ \t]*\\(.*?\\)[ \t]*$" nil t) (> (match-end 1) (match-beginning 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)) (save-excursion (ignore-errors (org-back-to-heading t)) diff --git a/lisp/org-special-blocks.el b/lisp/org-special-blocks.el index fa59657e6..dbdcd408f 100644 --- a/lisp/org-special-blocks.el +++ b/lisp/org-special-blocks.el @@ -47,11 +47,12 @@ by org-special-blocks. These blocks will presumably be 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 () "Adds special cookies when #+begin_foo and #+end_foo tokens are 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)) (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_\\(.*\\)$" nil t) (unless (org-string-match-p org-special-blocks-ignore-regexp (match-string 2))