From: Carsten Dominik <carsten.dominik@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>, Nicolas Goaziou <n.goaziou@gmail.com>
Subject: Patch: Allow installation of file-local export filters
Date: Sun, 22 Sep 2013 17:07:17 +0200 [thread overview]
Message-ID: <0E284051-405E-4426-9A47-991E2C8E5AB2@gmail.com> (raw)
In-Reply-To: <CE012247-7273-4EC9-9978-7F28CCE2ED94@gmail.com>
[-- 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 --]
next prev parent reply other threads:[~2013-09-22 15:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Carsten Dominik [this message]
2013-09-22 16:57 ` Eric Schulte
2013-09-22 17:21 ` Carsten Dominik
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=0E284051-405E-4426-9A47-991E2C8E5AB2@gmail.com \
--to=carsten.dominik@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=n.goaziou@gmail.com \
/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).