emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [PATCH] Re: [BUG] htmlp and latexp


From: Dan Davison
Subject: [Orgmode] [PATCH] Re: [BUG] htmlp and latexp
Date: Tue, 22 Feb 2011 11:08:57 -0800
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (darwin)

Bastien <address@hidden> writes:

> Hi Dan,
>
> Dan Davison <address@hidden> writes:
>
>> I was thinking that if it were defvard in org.el, say as
>>
>> (defvar org-export-current-backend nil)
>>
>> then any code could use (null org-export-current-backend) to test
>> whether org is currently exporting or not. Otherwise, the code has to be
>> certain that it has been called during export if it is going to access
>> the variable.
>
> I agree this would be a good idea.  If you have time, please send a
> patch.  Otherwise, I just put it [somewhere] in my own todo list...

Here's a patch. I note that Eric S pointed out in a separate thread that
org-current-export-file can be used for a similar purpose.

Incidentally, I would suggest that org-current-export-file and
org-current-export-dir are renamed so that they are within the
org-export-* namespace. There are other areas of Org where I think the
naming should be standardised, notably in org-src.el: the distinction
between org-src-* and org-edit-src-* is unclear IMO. I think this is
kind of important, because in learning emacs one does makes use of these
namespace conventions, e.g. C-h v <initial-letters> TAB. How much change
would there be if we demanded that *all* variables defined in org-foo.el
are named within the org-foo-* namespace?

Dan

commit ac9baa44c7c0baeb8ed3133ed79bc22c4eb6acc7
Author: Dan Davison <address@hidden>
Date:   Sun Feb 20 08:55:39 2011 -0800

    New variable storing current export backend symbol, or nil.
    
    * lisp/org-exp.el (org-export-current-backend): Variable to
    hold current export backend symbol when export is in progress.
    (org-export-preprocess-string): Bind `org-export-current-backend' to
    backend symbols during export.
    
    * lisp/org-exp-blocks.el (org-export-blocks-format-ditaa): Dynamically
    scoped variable `backend' renamed as `org-export-current-backend'
    (org-export-blocks-format-dot): Dynamically scoped variable `backend'
    renamed as `org-export-current-backend'
    (org-export-blocks-format-comment): Dynamically scoped variable
    `backend' renamed as `org-export-current-backend'
    
    * lisp/org-exp.el (org-export-convert-protected-spaces): Dynamically
    scoped variable `backend' renamed as `org-export-current-backend'
    
    * lisp/org-publish.el (org-publish-project-alist): Dynamically scoped
    variable `backend' renamed as `org-export-current-backend'
    (org-export-current-backend): Dynamically scoped variable `backend'
    renamed as `org-export-current-backend'
    (org-publish-aux-preprocess): Dynamically scoped variable `backend'
    renamed as `org-export-current-backend'
    
    * lisp/org-special-blocks.el (org-export-current-backend): Dynamically
    scoped variable `backend' renamed as `org-export-current-backend'
    (org-special-blocks-make-special-cookies): Dynamically scoped variable
    `backend' renamed as `org-export-current-backend'

diff --git a/lisp/org-exp-blocks.el b/lisp/org-exp-blocks.el
index 1fac3bf..15549b8 100644
--- a/lisp/org-exp-blocks.el
+++ b/lisp/org-exp-blocks.el
@@ -242,7 +242,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)
@@ -301,7 +301,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)
@@ -333,7 +333,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"
              "<div class=\"org-comment\""
              (if owner (format " id=\"org-comment-%s\" " owner))
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 9a35b00..e239c25 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -584,6 +584,14 @@ table.el tables."
 
 (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-dir nil) ; dynamically scoped parameter
 (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
 on this string to produce the exported version."
   (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))
         (inhibit-read-only t)
         (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
       ;; lines and lists' structure could be altered.
-      (org-export-mark-list-end backend)
+      (org-export-mark-list-end org-export-current-backend)
 
       ;; Export code blocks
       (org-export-blocks-preprocess)
 
       ;; Mark lists with properties
-      (org-export-mark-list-properties backend)
+      (org-export-mark-list-properties org-export-current-backend)
 
       ;; Handle source code snippets
-      (org-export-replace-src-segments-and-examples backend)
+      (org-export-replace-src-segments-and-examples org-export-current-backend)
 
       ;; Protect short examples marked by a leading colon
       (org-export-protect-colon-examples)
 
       ;; Protected spaces
-      (org-export-convert-protected-spaces backend)
+      (org-export-convert-protected-spaces org-export-current-backend)
 
       ;; Normalize footnotes
       (when (plist-get parameters :footnotes)
@@ -1122,7 +1130,7 @@ on this string to produce the exported version."
 
       ;; Get rid of drawers
       (org-export-remove-or-extract-drawers
-       drawers (plist-get parameters :drawers) backend)
+       drawers (plist-get parameters :drawers) org-export-current-backend)
 
       ;; Get the correct stuff before the first headline
       (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
       ;; that is specific for other backends
       (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook)
-      (org-export-select-backend-specific-text backend)
+      (org-export-select-backend-specific-text org-export-current-backend)
 
       ;; Protect quoted subtrees
       (org-export-protect-quoted-subtrees)
@@ -1166,7 +1174,7 @@ on this string to produce the exported version."
 
       ;; Attach captions to the correct object
       (setq target-alist (org-export-attach-captions-and-attributes
-                         backend target-alist))
+                         org-export-current-backend target-alist))
 
       ;; Find matches for radio targets and turn them into internal links
       (org-export-mark-radio-links)
@@ -1198,20 +1206,20 @@ on this string to produce the exported version."
       (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
 
       ;; LaTeX-specific preprocessing
-      (when (eq backend 'latex)
+      (when (eq org-export-current-backend 'latex)
        (require 'org-latex nil)
        (org-export-latex-preprocess parameters))
 
       ;; ASCII-specific preprocessing
-      (when (eq backend 'ascii)
+      (when (eq org-export-current-backend 'ascii)
        (org-export-ascii-preprocess parameters))
 
       ;; HTML-specific preprocessing
-      (when (eq backend 'html)
+      (when (eq org-export-current-backend 'html)
        (org-export-html-preprocess parameters))
 
       ;; DocBook-specific preprocessing
-      (when (eq backend 'docbook)
+      (when (eq org-export-current-backend 'docbook)
        (require 'org-docbook nil)
        (org-export-docbook-preprocess parameters))
 
@@ -1567,13 +1575,13 @@ from the buffer."
      (replace-match
       (org-add-props
          (cond
-          ((eq backend 'latex)
+          ((eq org-export-current-backend 'latex)
            (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-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)))
           (t (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
          '(org-protected t))
diff --git a/lisp/org-publish.el b/lisp/org-publish.el
index 649e39a..5bc4f28 100644
--- a/lisp/org-publish.el
+++ b/lisp/org-publish.el
@@ -931,7 +931,7 @@ the project."
 
 ;;; Index generation
 
-(defvar backend) ; dynamically scoped
+(defvar org-export-current-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 +942,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 54fb6cb..f253787 100644
--- a/lisp/org-special-blocks.el
+++ b/lisp/org-special-blocks.el
@@ -45,11 +45,12 @@
 by org-special-blocks.  These blocks will presumably be
 interpreted by other mechanisms.")
 
-(defvar backend) ; dynamically scoped
+(defvar org-export-current-backend) ; dynamically scoped
 (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))




>
> Thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]