emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christophe Rhodes <csr21@cantab.net>
To: emacs-orgmode@gnu.org
Subject: Re: org-export-current-backend variable and org-mode 8
Date: Fri, 02 Aug 2013 11:01:28 +0100	[thread overview]
Message-ID: <87r4ecs96v.fsf@cantab.net> (raw)
In-Reply-To: 87li4mtohu.fsf@cantab.net

[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]

Christophe Rhodes <csr21@cantab.net> writes:

> The `by-backend' macro in Brett Viren's message upthread?  Personally I
> don't consider that sufficient, because it feels very fragile: a simple
> renaming of org-mode internal variables, or turning on lexical binding,
> and the macro will no longer work.  (If you mean some other
> `by-backend', I haven't seen it).
>
> In particular, I would like to have some kind of confidence that
> documents that I wrote last year will still be exportable next year with
> only minor modifications necessary, and to do that I think I need to
> convince you that this is valuable, enough that you are willing to
> commit to some stable way of accessing the information previously held
> in org-export-current-backend.

Attempting to put my money where my mouth is: find attached a patch to
restore org-export-current-backend.  I think this is a TINYCHANGE
despite the large diff -- it's almost all whitespace, and the docstring
is restored verbatim from org-mode 7.9 (I haven't updated it for the
removal of the docbook backend, for example, primarily so that it has
minimal novel information in it).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-restore-org-export-current-backend-variable.patch --]
[-- Type: text/x-diff, Size: 10636 bytes --]

From 29d11fdda3b8302d437fdb309c195aa9e806505d Mon Sep 17 00:00:00 2001
From: Christophe Rhodes <c.rhodes@gold.ac.uk>
Date: Fri, 2 Aug 2013 10:56:37 +0100
Subject: [PATCH] ox: restore org-export-current-backend variable

* lisp/ox.el (org-export-current-backend): new variable.
(org-export-as): bind it.

TINYCHANGE
---
 lisp/ox.el |  214 +++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 111 insertions(+), 103 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 5d28a81..8962428 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -290,6 +290,13 @@ and its CDR is a list of export options.")
 This marker will be used with `C-u C-c C-e' to make sure export repetition
 uses the same subtree if the previous command was restricted to a subtree.")
 
+(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.")
 \f
 ;;; User-configurable Variables
 ;;
@@ -2947,109 +2954,110 @@ still inferior to file-local settings.
 Return code as a string."
   (when (symbolp backend) (setq backend (org-export-get-backend backend)))
   (org-export-barf-if-invalid-backend backend)
-  (save-excursion
-    (save-restriction
-      ;; Narrow buffer to an appropriate region or subtree for
-      ;; parsing.  If parsing subtree, be sure to remove main headline
-      ;; too.
-      (cond ((org-region-active-p)
-	     (narrow-to-region (region-beginning) (region-end)))
-	    (subtreep
-	     (org-narrow-to-subtree)
-	     (goto-char (point-min))
-	     (forward-line)
-	     (narrow-to-region (point) (point-max))))
-      ;; Initialize communication channel with original buffer
-      ;; attributes, unavailable in its copy.
-      (let* ((info (org-combine-plists
-		    (list :export-options
-			  (delq nil
-				(list (and subtreep 'subtree)
-				      (and visible-only 'visible-only)
-				      (and body-only 'body-only))))
-		    (org-export--get-buffer-attributes)))
-	     tree)
-	;; Store default title in `org-export--default-title' so that
-	;; `org-export-get-environment' can access it from buffer's
-	;; copy and then add it properly to communication channel.
-	(org-export-store-default-title)
-	;; Update communication channel and get parse tree.  Buffer
-	;; isn't parsed directly.  Instead, a temporary copy is
-	;; created, where include keywords, macros are expanded and
-	;; code blocks are evaluated.
-	(org-export-with-buffer-copy
-	 ;; Run first hook with current back-end's name as argument.
-	 (run-hook-with-args 'org-export-before-processing-hook
-			     (org-export-backend-name backend))
-	 (org-export-expand-include-keyword)
-	 ;; Update macro templates since #+INCLUDE keywords might have
-	 ;; added some new ones.
-	 (org-macro-initialize-templates)
-	 (org-macro-replace-all org-macro-templates)
-	 (org-export-execute-babel-code)
-	 ;; Update radio targets since keyword inclusion might have
-	 ;; added some more.
-	 (org-update-radio-target-regexp)
-	 ;; Run last hook with current back-end's name as argument.
-	 (goto-char (point-min))
-	 (save-excursion
-	   (run-hook-with-args 'org-export-before-parsing-hook
-			       (org-export-backend-name backend)))
-	 ;; Update communication channel with environment.  Also
-	 ;; install user's and developer's filters.
-	 (setq info
-	       (org-export-install-filters
-		(org-combine-plists
-		 info (org-export-get-environment backend subtreep ext-plist))))
-	 ;; Expand export-specific set of macros: {{{author}}},
-	 ;; {{{date}}}, {{{email}}} and {{{title}}}.  It must be done
-	 ;; once regular macros have been expanded, since document
-	 ;; keywords may contain one of them.
-	 (org-macro-replace-all
-	  (list (cons "author"
-		      (org-element-interpret-data (plist-get info :author)))
-		(cons "date"
-		      (org-element-interpret-data (plist-get info :date)))
-		;; EMAIL is not a parsed keyword: store it as-is.
-		(cons "email" (or (plist-get info :email) ""))
-		(cons "title"
-		      (org-element-interpret-data (plist-get info :title)))))
-	 ;; Call options filters and update export options.  We do not
-	 ;; use `org-export-filter-apply-functions' here since the
-	 ;; arity of such filters is different.
-	 (let ((backend-name (org-export-backend-name backend)))
-	   (dolist (filter (plist-get info :filter-options))
-	     (let ((result (funcall filter info backend-name)))
-	       (when result (setq info result)))))
-	 ;; Parse buffer and call parse-tree filter on it.
-	 (setq tree
-	       (org-export-filter-apply-functions
-		(plist-get info :filter-parse-tree)
-		(org-element-parse-buffer nil visible-only) info))
-	 ;; Now tree is complete, compute its properties and add them
-	 ;; to communication channel.
-	 (setq info
-	       (org-combine-plists
-		info (org-export-collect-tree-properties tree info)))
-	 ;; Eventually transcode TREE.  Wrap the resulting string into
-	 ;; a template.
-	 (let* ((body (org-element-normalize-string
-		       (or (org-export-data tree info) "")))
-		(inner-template (cdr (assq 'inner-template
-					   (plist-get info :translate-alist))))
-		(full-body (if (not (functionp inner-template)) body
-			     (funcall inner-template body info)))
-		(template (cdr (assq 'template
-				     (plist-get info :translate-alist)))))
-	   ;; Remove all text properties since they cannot be
-	   ;; retrieved from an external process.  Finally call
-	   ;; final-output filter and return result.
-	   (org-no-properties
-	    (org-export-filter-apply-functions
-	     (plist-get info :filter-final-output)
-	     (if (or (not (functionp template)) body-only) full-body
-	       (funcall template full-body info))
-	     info))))))))
+  (let ((org-export-current-backend backend))
+    (save-excursion
+      (save-restriction
+	;; Narrow buffer to an appropriate region or subtree for
+	;; parsing.  If parsing subtree, be sure to remove main headline
+	;; too.
+	(cond ((org-region-active-p)
+	       (narrow-to-region (region-beginning) (region-end)))
+	      (subtreep
+	       (org-narrow-to-subtree)
+	       (goto-char (point-min))
+	       (forward-line)
+	       (narrow-to-region (point) (point-max))))
+	;; Initialize communication channel with original buffer
+	;; attributes, unavailable in its copy.
+	(let* ((info (org-combine-plists
+		      (list :export-options
+			    (delq nil
+				  (list (and subtreep 'subtree)
+					(and visible-only 'visible-only)
+					(and body-only 'body-only))))
+		      (org-export--get-buffer-attributes)))
+	       tree)
+	  ;; Store default title in `org-export--default-title' so that
+	  ;; `org-export-get-environment' can access it from buffer's
+	  ;; copy and then add it properly to communication channel.
+	  (org-export-store-default-title)
+	  ;; Update communication channel and get parse tree.  Buffer
+	  ;; isn't parsed directly.  Instead, a temporary copy is
+	  ;; created, where include keywords, macros are expanded and
+	  ;; code blocks are evaluated.
+	  (org-export-with-buffer-copy
+	   ;; Run first hook with current back-end's name as argument.
+	   (run-hook-with-args 'org-export-before-processing-hook
+			       (org-export-backend-name backend))
+	   (org-export-expand-include-keyword)
+	   ;; Update macro templates since #+INCLUDE keywords might have
+	   ;; added some new ones.
+	   (org-macro-initialize-templates)
+	   (org-macro-replace-all org-macro-templates)
+	   (org-export-execute-babel-code)
+	   ;; Update radio targets since keyword inclusion might have
+	   ;; added some more.
+	   (org-update-radio-target-regexp)
+	   ;; Run last hook with current back-end's name as argument.
+	   (goto-char (point-min))
+	   (save-excursion
+	     (run-hook-with-args 'org-export-before-parsing-hook
+				 (org-export-backend-name backend)))
+	   ;; Update communication channel with environment.  Also
+	   ;; install user's and developer's filters.
+	   (setq info
+		 (org-export-install-filters
+		  (org-combine-plists
+		   info (org-export-get-environment backend subtreep ext-plist))))
+	   ;; Expand export-specific set of macros: {{{author}}},
+	   ;; {{{date}}}, {{{email}}} and {{{title}}}.  It must be done
+	   ;; once regular macros have been expanded, since document
+	   ;; keywords may contain one of them.
+	   (org-macro-replace-all
+	    (list (cons "author"
+			(org-element-interpret-data (plist-get info :author)))
+		  (cons "date"
+			(org-element-interpret-data (plist-get info :date)))
+		  ;; EMAIL is not a parsed keyword: store it as-is.
+		  (cons "email" (or (plist-get info :email) ""))
+		  (cons "title"
+			(org-element-interpret-data (plist-get info :title)))))
+	   ;; Call options filters and update export options.  We do not
+	   ;; use `org-export-filter-apply-functions' here since the
+	   ;; arity of such filters is different.
+	   (let ((backend-name (org-export-backend-name backend)))
+	     (dolist (filter (plist-get info :filter-options))
+	       (let ((result (funcall filter info backend-name)))
+		 (when result (setq info result)))))
+	   ;; Parse buffer and call parse-tree filter on it.
+	   (setq tree
+		 (org-export-filter-apply-functions
+		  (plist-get info :filter-parse-tree)
+		  (org-element-parse-buffer nil visible-only) info))
+	   ;; Now tree is complete, compute its properties and add them
+	   ;; to communication channel.
+	   (setq info
+		 (org-combine-plists
+		  info (org-export-collect-tree-properties tree info)))
+	   ;; Eventually transcode TREE.  Wrap the resulting string into
+	   ;; a template.
+	   (let* ((body (org-element-normalize-string
+			 (or (org-export-data tree info) "")))
+		  (inner-template (cdr (assq 'inner-template
+					     (plist-get info :translate-alist))))
+		  (full-body (if (not (functionp inner-template)) body
+			       (funcall inner-template body info)))
+		  (template (cdr (assq 'template
+				       (plist-get info :translate-alist)))))
+	     ;; Remove all text properties since they cannot be
+	     ;; retrieved from an external process.  Finally call
+	     ;; final-output filter and return result.
+	     (org-no-properties
+	      (org-export-filter-apply-functions
+	       (plist-get info :filter-final-output)
+	       (if (or (not (functionp template)) body-only) full-body
+		 (funcall template full-body info))
+	       info)))))))))
 
 ;;;###autoload
 (defun org-export-to-buffer
-- 
1.7.10.4


[-- Attachment #3: Type: text/plain, Size: 26 bytes --]


Best wishes,

Christophe

  reply	other threads:[~2013-08-02 10:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-31 16:27 org-export-current-backend variable and org-mode 8 Christophe Rhodes
2013-07-31 18:41 ` Brett Viren
2013-07-31 19:09   ` Christophe Rhodes
2013-07-31 20:40     ` Nicolas Goaziou
2013-07-31 21:21       ` Christophe Rhodes
2013-08-02 10:01         ` Christophe Rhodes [this message]
2013-08-03  7:50           ` Nicolas Goaziou
2013-08-03 17:55             ` Achim Gratz
2013-08-03 19:08               ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r4ecs96v.fsf@cantab.net \
    --to=csr21@cantab.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).