From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Patch: Allow installation of file-local export filters Date: Sun, 22 Sep 2013 17:07:17 +0200 Message-ID: <0E284051-405E-4426-9A47-991E2C8E5AB2@gmail.com> References: <87txhd11wy.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Content-Type: multipart/signed; boundary="Apple-Mail=_83C2E83C-1B24-4F7F-993C-93833A7D649A"; protocol="application/pgp-signature"; micalg=pgp-sha1 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VNlG1-0006LN-EJ for emacs-orgmode@gnu.org; Sun, 22 Sep 2013 11:07:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VNlFs-0002wv-Sp for emacs-orgmode@gnu.org; Sun, 22 Sep 2013 11:07:33 -0400 Received: from mail-ea0-x229.google.com ([2a00:1450:4013:c01::229]:52508) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VNlFs-0002wp-HQ for emacs-orgmode@gnu.org; Sun, 22 Sep 2013 11:07:24 -0400 Received: by mail-ea0-f169.google.com with SMTP id k11so1214644eaj.14 for ; Sun, 22 Sep 2013 08:07:23 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode , Nicolas Goaziou --Apple-Mail=_83C2E83C-1B24-4F7F-993C-93833A7D649A Content-Type: multipart/mixed; boundary="Apple-Mail=_66796DD4-BFFE-46FD-88E0-F2DAD1859AF6" --Apple-Mail=_66796DD4-BFFE-46FD-88E0-F2DAD1859AF6 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii 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? --Apple-Mail=_66796DD4-BFFE-46FD-88E0-F2DAD1859AF6 Content-Disposition: attachment; filename=patch-file-local-filters Content-Type: application/octet-stream; name="patch-file-local-filters" Content-Transfer-Encoding: quoted-printable diff=20--git=20a/lisp/ox.el=20b/lisp/ox.el=0Aindex=2010354b2..f68dc78=20= 100644=0A---=20a/lisp/ox.el=0A+++=20b/lisp/ox.el=0A@@=20-2796,6=20= +2796,52=20@@=20Return=20the=20updated=20communication=20channel."=0A=20=20= =20=20=20;;=20Return=20new=20communication=20channel.=0A=20=20=20=20=20= (org-combine-plists=20info=20plist)))=0A=20=0A+(defun=20= org-export-define-local-filters=20(filter-alist)=0A+=20=20"Function=20to=20= be=20used=20in=20an=20src=20block=20to=20install=20file-local=20export=20= filters.=0A+The=20function=20takes=20an=20alist,=20where=20each=20= element=20is=20a=20list=20of=20three=20items:=0A+=0A+1.=20The=20filter=20= to=20be=20modified.=20=20This=20should=20be=20a=20filter=20symbol=20like=20= `XXX'=0A+=20=20=20to=20indicate=20the=20filter=20variable=20= `org-export-filter-XXX-functions'.=0A+=0A+2.=20The=20filter=20function=20= to=20be=20installed=20in=20that=20variable.=20=20This=20must=20be=20a=0A= +=20=20=20function=20or=20`lambda'=20form=20that=20accepts=20the=20usual=20= three=20arguments=20for=0A+=20=20=20filter=20function=20(string=20= backend=20info).=0A+=0A+3.=20An=20optional=20REPLACE=20flag.=20=20When=20= t,=20the=20default=20value=20of=20the=20filter=0A+=20=20=20variable=20= will=20be=20discarded=20and=20the=20local=20filter=20will=20be=20the=20= only=0A+=20=20=20one=20in=20that=20filter=20variable.=20=20When=20nil,=20= the=20new=20filter=20will=20be=20added=0A+=20=20=20to=20the=20existing=20= ones.=0A+=0A+Here=20is=20an=20example=20that=20will=20install=20filters=20= to=20remove=20brackets=20from=0A+time=20stamps,=20and=20to=20eliminate=20= strike-through=20text.=0A+=0A+=20=20=20#+begin_src=20emacs-lisp=20= :exports=20results=20:results=20none=0A+=20=20=20=20=20= (org-export-define-local-filters=0A+=20=20=20=20=20=20'((timestamp=0A+=20= =20=20=20=20=20=20=20=20(lambda=20(timestamp=20backend=20info)=0A+=20=20=20= =20=20=20=20=20=20=20=20\"Remove=20brackets=20from=20timestamp.\"=0A+=20=20= =20=20=20=20=20=20=20=20=20(when=20(org-export-derived-backend-p=20= backend=20'html)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= (replace-regexp-in-string=20\"&[l]t;\\|[][]\"=20\"\"=20timestamp))))=0A+=20= =20=20=20=20=20=20=20(strike-through=0A+=20=20=20=20=20=20=20=20=20= (lambda=20(s=20backend=20info)=0A+=20=20=20=20=20=20=20=20=20=20=20= \"Remove=20strike-through=20text\"=0A+=20=20=20=20=20=20=20=20=20=20=20= \"\")=0A+=20=20=20=20=20=20=20=20=20replace)))=0A+=20=20=20#+end_src"=0A= +=20=20(let=20(next=20var=20filter=20replace)=0A+=20=20=20=20(while=20= (setq=20next=20(pop=20filter-alist))=0A+=20=20=20=20=20=20(setq=20var=20= (car=20next)=0A+=09=20=20=20=20filter=20(nth=201=20next)=0A+=09=20=20=20=20= replace=20(nth=202=20next))=0A+=20=20=20=20=20=20(setq=20var=20(intern=20= (concat=20"org-export-filter-"=20(symbol-name=20var)=0A+=09=09=09=09= "-functions")))=0A+=20=20=20=20=20=20(make-local-variable=20var)=0A+=20=20= =20=20=20=20(if=20replace=0A+=09=20=20(if=20filter=0A+=09=20=20=20=20=20=20= (set=20var=20(list=20filter))=0A+=09=20=20=20=20(set=20var=20nil))=0A+=09= (if=20filter=0A+=09=20=20=20=20(add-to-list=20var=20filter))))))=0A=20=0A= =20=0C=0A=20;;;=20Core=20functions=0A@@=20-3346,11=20+3392,15=20@@=20= file=20should=20have."=0A=20=09=09=09(insert=20(make-string=20offset=20= ?*)))))))))))=0A=20=20=20=20=20(org-element-normalize-string=20= (buffer-string))))=0A=20=0A+(defvar=20= org-export-executing-babel-code-for-export=20nil=0A+=20=20"Flag=20to=20= be=20bound=20using=20`let'")=0A+=0A=20(defun=20= org-export-execute-babel-code=20()=0A=20=20=20"Execute=20every=20Babel=20= code=20in=20the=20visible=20part=20of=20current=20buffer."=0A=20=20=20;;=20= Get=20a=20pristine=20copy=20of=20current=20buffer=20so=20Babel=20= references=20can=20be=0A=20=20=20;;=20properly=20resolved.=0A-=20=20(let=20= ((reference=20(org-export-copy-buffer)))=0A+=20=20(let=20((reference=20= (org-export-copy-buffer))=0A+=09= (org-export-executing-babel-code-for-export=20t))=0A=20=20=20=20=20= (unwind-protect=20(let=20((org-current-export-file=20reference))=0A=20=09= =09=20=20=20=20=20=20(org-babel-exp-process-buffer))=0A=20=20=20=20=20=20= =20(kill-buffer=20reference))))=0A@@=20-6213,7=20+6263,6=20@@=20options=20= as=20CDR."=0A=20=20=20=20=20=20(t=20(org-export--dispatch-ui=20options=20= key=20expertp)))))=0A=20=0A=20=0A-=0A=20(provide=20'ox)=0A=20=0A=20;;=20= Local=20variables:=0A= --Apple-Mail=_66796DD4-BFFE-46FD-88E0-F2DAD1859AF6 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii On 22.9.2013, at 14:26, Carsten Dominik wrote: > > On 22.9.2013, at 14:22, Nicolas Goaziou wrote: > >> Hello, >> >> Carsten Dominik 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 > --Apple-Mail=_66796DD4-BFFE-46FD-88E0-F2DAD1859AF6-- --Apple-Mail=_83C2E83C-1B24-4F7F-993C-93833A7D649A Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJSPwelAAoJEO+gg/nAZuwMmKcH/RQQ+vwUo0aytHHoGxBRdoKD /fCcYnCWD+8bhtle6DI6eE12G6lE1ZuyUF1rs16XqZxnUj9K8eYwmVrfivZowMbj 0kpP6mXI5nxW59epWlBicL9hM34JUPYnBFqXwxXuLLnx+9gpkWAKPq5PlKRLZaW7 U7sEFpQcGes7aUXBIWhU2oleXqiQDV1GinaBpBIglK1jMD5P7R9JhlvxOHi/tG+N Z27dKCLSjnW7DC5VJfpeP4ybtsTqVfe5ehlT7ig865AV0/qx7fumQW8pRXs3Qfah 9/Ceki7pRvHSSycjnkjToL/vZDkvrtTMtShu7sY2mNYOsTyszvpJXtQ/WTzGEk8= =bwAX -----END PGP SIGNATURE----- --Apple-Mail=_83C2E83C-1B24-4F7F-993C-93833A7D649A--