emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Detect if export is running
@ 2013-09-22 12:08 Carsten Dominik
  2013-09-22 12:22 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Carsten Dominik @ 2013-09-22 12:08 UTC (permalink / raw)
  To: Org Mode; +Cc: Nicolas Goaziou, Eric Schulte

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

Hi Eric, hi Nicolas,

I am trying to write a function that will only run if it is called during
the evaluation of babel code during export, so basically during
`org-export-execute-babel code'.  Do you know if there is a way
to detect that this is the case, or should I introduce a flag that is set by
`org-export-execute-babel-code'?

Thank you

- Carsten

[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Detect if export is running
  2013-09-22 12:08 Detect if export is running Carsten Dominik
@ 2013-09-22 12:22 ` Nicolas Goaziou
  2013-09-22 12:26   ` Carsten Dominik
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2013-09-22 12:22 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Org Mode, Eric Schulte

Hello,

Carsten Dominik <carsten.dominik@gmail.com> writes:

> I am trying to write a function that will only run if it is called
> during the evaluation of babel code during export, so basically during
> `org-export-execute-babel code'. Do you know if there is a way to
> detect that this is the case,

There isn't.

> or should I introduce a flag that is set by
> `org-export-execute-babel-code'?

This may be dangerous. Introducing such a flag means that Babel results
may be different when exporting and when evaluating a block.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Detect if export is running
  2013-09-22 12:22 ` Nicolas Goaziou
@ 2013-09-22 12:26   ` Carsten Dominik
  2013-09-22 15:07     ` Patch: Allow installation of file-local export filters Carsten Dominik
  2013-09-22 16:57     ` Detect if export is running Eric Schulte
  0 siblings, 2 replies; 6+ messages in thread
From: Carsten Dominik @ 2013-09-22 12:26 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode, Eric Schulte

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


On 22.9.2013, at 14:22, Nicolas Goaziou <n.goaziou@gmail.com> wrote:

> Hello,
> 
> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
>> I am trying to write a function that will only run if it is called
>> during the evaluation of babel code during export, so basically during
>> `org-export-execute-babel code'. Do you know if there is a way to
>> detect that this is the case,
> 
> There isn't.
> 
>> or should I introduce a flag that is set by
>> `org-export-execute-babel-code'?
> 
> This may be dangerous. Introducing such a flag means that Babel results
> may be different when exporting and when evaluating a block.

This is exactly the point.  I want to be able to create local variables
and change filter lists during export, while interactive evaluation should
not create local variables in the Org mode buffer.  I do not plan to
advertise this flag, but to use it in one very specific function.

Regards

- Carsten
> 
> 
> Regards,
> 
> -- 
> Nicolas Goaziou


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Patch: Allow installation of file-local export filters
  2013-09-22 12:26   ` Carsten Dominik
@ 2013-09-22 15:07     ` Carsten Dominik
  2013-09-22 16:57     ` Detect if export is running Eric Schulte
  1 sibling, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2013-09-22 15:07 UTC (permalink / raw)
  To: Org Mode, Nicolas Goaziou


[-- Attachment #1.1: Type: text/plain, Size: 231 bytes --]

Hi Nicolas,

please take a look at the attached patch - it shows what I am trying to do.
I think is is a nice way to tweak export on a file-local scope,
in a self-contained way, so that the file carries it special filters.

WDYT?


[-- Attachment #1.2: patch-file-local-filters --]
[-- Type: application/octet-stream, Size: 3065 bytes --]

diff --git a/lisp/ox.el b/lisp/ox.el
index 10354b2..f68dc78 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2796,6 +2796,52 @@ Return the updated communication channel."
     ;; Return new communication channel.
     (org-combine-plists info plist)))
 
+(defun org-export-define-local-filters (filter-alist)
+  "Function to be used in an src block to install file-local export filters.
+The function takes an alist, where each element is a list of three items:
+
+1. The filter to be modified.  This should be a filter symbol like `XXX'
+   to indicate the filter variable `org-export-filter-XXX-functions'.
+
+2. The filter function to be installed in that variable.  This must be a
+   function or `lambda' form that accepts the usual three arguments for
+   filter function (string backend info).
+
+3. An optional REPLACE flag.  When t, the default value of the filter
+   variable will be discarded and the local filter will be the only
+   one in that filter variable.  When nil, the new filter will be added
+   to the existing ones.
+
+Here is an example that will install filters to remove brackets from
+time stamps, and to eliminate strike-through text.
+
+   #+begin_src emacs-lisp :exports results :results none
+     (org-export-define-local-filters
+      '((timestamp
+         (lambda (timestamp backend info)
+           \"Remove brackets from timestamp.\"
+           (when (org-export-derived-backend-p backend 'html)
+             (replace-regexp-in-string \"&[l]t;\\|[][]\" \"\" timestamp))))
+        (strike-through
+         (lambda (s backend info)
+           \"Remove strike-through text\"
+           \"\")
+         replace)))
+   #+end_src"
+  (let (next var filter replace)
+    (while (setq next (pop filter-alist))
+      (setq var (car next)
+	    filter (nth 1 next)
+	    replace (nth 2 next))
+      (setq var (intern (concat "org-export-filter-" (symbol-name var)
+				"-functions")))
+      (make-local-variable var)
+      (if replace
+	  (if filter
+	      (set var (list filter))
+	    (set var nil))
+	(if filter
+	    (add-to-list var filter))))))
 
 \f
 ;;; Core functions
@@ -3346,11 +3392,15 @@ file should have."
 			(insert (make-string offset ?*)))))))))))
     (org-element-normalize-string (buffer-string))))
 
+(defvar org-export-executing-babel-code-for-export nil
+  "Flag to be bound using `let'")
+
 (defun org-export-execute-babel-code ()
   "Execute every Babel code in the visible part of current buffer."
   ;; Get a pristine copy of current buffer so Babel references can be
   ;; properly resolved.
-  (let ((reference (org-export-copy-buffer)))
+  (let ((reference (org-export-copy-buffer))
+	(org-export-executing-babel-code-for-export t))
     (unwind-protect (let ((org-current-export-file reference))
 		      (org-babel-exp-process-buffer))
       (kill-buffer reference))))
@@ -6213,7 +6263,6 @@ options as CDR."
      (t (org-export--dispatch-ui options key expertp)))))
 
 
-
 (provide 'ox)
 
 ;; Local variables:

[-- Attachment #1.3: Type: text/plain, Size: 1106 bytes --]




On 22.9.2013, at 14:26, Carsten Dominik <carsten.dominik@gmail.com> wrote:

> 
> On 22.9.2013, at 14:22, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
> 
>> Hello,
>> 
>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>> 
>>> I am trying to write a function that will only run if it is called
>>> during the evaluation of babel code during export, so basically during
>>> `org-export-execute-babel code'. Do you know if there is a way to
>>> detect that this is the case,
>> 
>> There isn't.
>> 
>>> or should I introduce a flag that is set by
>>> `org-export-execute-babel-code'?
>> 
>> This may be dangerous. Introducing such a flag means that Babel results
>> may be different when exporting and when evaluating a block.
> 
> This is exactly the point.  I want to be able to create local variables
> and change filter lists during export, while interactive evaluation should
> not create local variables in the Org mode buffer.  I do not plan to
> advertise this flag, but to use it in one very specific function.
> 
> Regards
> 
> - Carsten
>> 
>> 
>> Regards,
>> 
>> -- 
>> Nicolas Goaziou
> 


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Detect if export is running
  2013-09-22 12:26   ` Carsten Dominik
  2013-09-22 15:07     ` Patch: Allow installation of file-local export filters Carsten Dominik
@ 2013-09-22 16:57     ` Eric Schulte
  2013-09-22 17:21       ` Carsten Dominik
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Schulte @ 2013-09-22 16:57 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Org Mode, Nicolas Goaziou

I've used the org-export-file (or somesuch) variable in the past which
is only set during export.

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On 22.9.2013, at 14:22, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
>
>> Hello,
>> 
>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>> 
>>> I am trying to write a function that will only run if it is called
>>> during the evaluation of babel code during export, so basically during
>>> `org-export-execute-babel code'. Do you know if there is a way to
>>> detect that this is the case,
>> 
>> There isn't.
>> 
>>> or should I introduce a flag that is set by
>>> `org-export-execute-babel-code'?
>> 
>> This may be dangerous. Introducing such a flag means that Babel results
>> may be different when exporting and when evaluating a block.
>
> This is exactly the point.  I want to be able to create local variables
> and change filter lists during export, while interactive evaluation should
> not create local variables in the Org mode buffer.  I do not plan to
> advertise this flag, but to use it in one very specific function.
>
> Regards
>
> - Carsten
>> 
>> 
>> Regards,
>> 
>> -- 
>> Nicolas Goaziou
>

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Detect if export is running
  2013-09-22 16:57     ` Detect if export is running Eric Schulte
@ 2013-09-22 17:21       ` Carsten Dominik
  0 siblings, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2013-09-22 17:21 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode, Nicolas Goaziou

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


On 22.9.2013, at 18:57, Eric Schulte <eschulte@cs.unm.edu> wrote:

> I've used the org-export-file (or somesuch) variable in the past which
> is only set during export.

Ah, OK, an even simpler way.  Thank you!

- Carsten

> 
> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
>> On 22.9.2013, at 14:22, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
>> 
>>> Hello,
>>> 
>>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>>> 
>>>> I am trying to write a function that will only run if it is called
>>>> during the evaluation of babel code during export, so basically during
>>>> `org-export-execute-babel code'. Do you know if there is a way to
>>>> detect that this is the case,
>>> 
>>> There isn't.
>>> 
>>>> or should I introduce a flag that is set by
>>>> `org-export-execute-babel-code'?
>>> 
>>> This may be dangerous. Introducing such a flag means that Babel results
>>> may be different when exporting and when evaluating a block.
>> 
>> This is exactly the point.  I want to be able to create local variables
>> and change filter lists during export, while interactive evaluation should
>> not create local variables in the Org mode buffer.  I do not plan to
>> advertise this flag, but to use it in one very specific function.
>> 
>> Regards
>> 
>> - Carsten
>>> 
>>> 
>>> Regards,
>>> 
>>> -- 
>>> Nicolas Goaziou
>> 
> 
> -- 
> Eric Schulte
> https://cs.unm.edu/~eschulte
> PGP: 0x614CA05D


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-09-22 17:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-22 12:08 Detect if export is running Carsten Dominik
2013-09-22 12:22 ` Nicolas Goaziou
2013-09-22 12:26   ` Carsten Dominik
2013-09-22 15:07     ` Patch: Allow installation of file-local export filters Carsten Dominik
2013-09-22 16:57     ` Detect if export is running Eric Schulte
2013-09-22 17:21       ` Carsten Dominik

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).