From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bjarte Johansen Subject: Re: ob-sed Date: Fri, 29 May 2015 15:32:51 +0200 Message-ID: <11314228-BE27-4F10-B535-2EB7B920AB44@infomedia.uib.no> References: <3C35DA19-1BA3-4249-9128-99DDA0F4752D@infomedia.uib.no> <877frtd7wi.fsf@nicolasgoaziou.fr> <751618D6-4EE2-4803-A550-EECE21006ABA@infomedia.uib.no> <871thz3ghu.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_18F92B2B-FFAB-4A70-BE90-682EFD638CB6" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YyKPC-0004pZ-MK for emacs-orgmode@gnu.org; Fri, 29 May 2015 09:32:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YyKP8-0003iR-1c for emacs-orgmode@gnu.org; Fri, 29 May 2015 09:32:58 -0400 Received: from alfons.uib.no ([2001:700:200:30::141]:51299) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YyKP7-0003hR-Mk for emacs-orgmode@gnu.org; Fri, 29 May 2015 09:32:53 -0400 In-Reply-To: <871thz3ghu.fsf@nicolasgoaziou.fr> 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: Nicolas Goaziou Cc: emacs-orgmode --Apple-Mail=_18F92B2B-FFAB-4A70-BE90-682EFD638CB6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I think I have addressed all of your comments except I didn=E2=80=99t = understand the comment about the spaces. Are there two spaces extra or = do you want me to introduce two spaces somewhere? I have attached the updated patch. Regards, Bjarte --Apple-Mail=_18F92B2B-FFAB-4A70-BE90-682EFD638CB6 Content-Disposition: attachment; filename=0001-Org-Babel-now-supports-sed-scripts.patch Content-Type: application/octet-stream; name="0001-Org-Babel-now-supports-sed-scripts.patch" Content-Transfer-Encoding: quoted-printable =46rom=207d8460962dbc01b8c7c9004b662b203ad5328fd4=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Bjarte=20Johansen=20= =0ADate:=20Thu,=2028=20May=202015=2013:29:09=20= +0200=0ASubject:=20[PATCH]=20Org=20Babel=20now=20supports=20sed=20= scripts=0A=0A*=20doc/org.texi:=20Signal=20new=20babel=20language.=0A=0A*=20= lisp/ob-sed.el:=0A*=20testing/examples/ob-sed-test.org:=0A*=20= testing/lisp/test-ob-sed.el:=20New=20files.=0A---=0A=20doc/org.texi=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=20=205=20= +-=0A=20lisp/ob-sed.el=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20|=20108=20+++++++++++++++++++++++++++++++++++++++=0A=20= testing/examples/ob-sed-test.org=20|=20=2035=20+++++++++++++=0A=20= testing/lisp/test-ob-sed.el=20=20=20=20=20=20|=20=2060=20= ++++++++++++++++++++++=0A=204=20files=20changed,=20206=20insertions(+),=20= 2=20deletions(-)=0A=20create=20mode=20100644=20lisp/ob-sed.el=0A=20= create=20mode=20100644=20testing/examples/ob-sed-test.org=0A=20create=20= mode=20100644=20testing/lisp/test-ob-sed.el=0A=0Adiff=20--git=20= a/doc/org.texi=20b/doc/org.texi=0Aindex=20f10d4f5..05d8666=20100644=0A= ---=20a/doc/org.texi=0A+++=20b/doc/org.texi=0A@@=20-15056,8=20+15056,9=20= @@=20Code=20blocks=20in=20the=20following=20languages=20are=20supported.=0A= =20@item=20Processing.js=20@tab=20processing=20@tab=20Python=20@tab=20= python=20=0A=20@item=20R=20@tab=20R=20@tab=20Ruby=20@tab=20ruby=20=0A=20= @item=20Sass=20@tab=20sass=20@tab=20Scheme=20@tab=20scheme=20=0A-@item=20= GNU=20Screen=20@tab=20screen=20@tab=20shell=20@tab=20sh=20=0A-@item=20= SQL=20@tab=20sql=20@tab=20SQLite=20@tab=20sqlite=0A+@item=20GNU=20Screen=20= @tab=20screen=20@tab=20Sed=20@tab=20sed=0A+@item=20shell=20@tab=20sh=20= @tab=20SQL=20@tab=20sql=0A+@item=20SQLite=20@tab=20sqlite=20@tab=20@tab=0A= =20@end=20multitable=0A=20=0A=20Language-specific=20documentation=20is=20= available=20for=20some=20languages.=20=20If=0Adiff=20--git=20= a/lisp/ob-sed.el=20b/lisp/ob-sed.el=0Anew=20file=20mode=20100644=0Aindex=20= 0000000..a42336d=0A---=20/dev/null=0A+++=20b/lisp/ob-sed.el=0A@@=20-0,0=20= +1,108=20@@=0A+;;;=20ob-sed.el=20---=20org-babel=20functions=20for=20sed=20= scripts=0A+=0A+;;=20Copyright=20(C)=202015=20Free=20Software=20= Foundation=0A+=0A+;;=20Author:=20Bjarte=20Johansen=0A+;;=20Keywords:=20= literate=20programming,=20reproducible=20research=0A+;;=20Version:=20= 0.1.0=0A+=0A+;;=20This=20file=20is=20part=20of=20GNU=20Emacs.=0A+=0A+;;;=20= License:=0A+=0A+;;=20This=20program=20is=20free=20software;=20you=20can=20= redistribute=20it=20and/or=20modify=0A+;;=20it=20under=20the=20terms=20= of=20the=20GNU=20General=20Public=20License=20as=20published=20by=0A+;;=20= the=20Free=20Software=20Foundation;=20either=20version=203,=20or=20(at=20= your=20option)=0A+;;=20any=20later=20version.=0A+;;=0A+;;=20This=20= program=20is=20distributed=20in=20the=20hope=20that=20it=20will=20be=20= useful,=0A+;;=20but=20WITHOUT=20ANY=20WARRANTY;=20without=20even=20the=20= implied=20warranty=20of=0A+;;=20MERCHANTABILITY=20or=20FITNESS=20FOR=20A=20= PARTICULAR=20PURPOSE.=20=20See=20the=0A+;;=20GNU=20General=20Public=20= License=20for=20more=20details.=0A+;;=0A+;;=20You=20should=20have=20= received=20a=20copy=20of=20the=20GNU=20General=20Public=20License=0A+;;=20= along=20with=20GNU=20Emacs.=20If=20not,=20see=20= .=0A+=0A+;;;=20Commentary:=0A+=0A+;;=20= Provides=20a=20way=20to=20evaluate=20sed=20scripts=20in=20Org=20mode.=0A= +=0A+;;;=20Usage:=0A+=0A+;;=20Add=20to=20your=20Emacs=20config:=0A+=0A= +;;=20(org-babel-do-load-languages=0A+;;=20=20'org-babel-load-languages=0A= +;;=20=20'((sed=20.=20t)))=0A+=0A+;;=20In=20addition=20to=20the=20normal=20= header=20arguments,=20ob-sed=20also=20provides=0A+;;=20:cmd-line=20and=20= :in-file.=20:cmd-line=20allows=20one=20to=20pass=20other=20flags=20to=0A= +;;=20the=20sed=20command=20like=20the=20"--in-place"=20flag=20which=20= makes=20sed=20edit=20the=0A+;;=20file=20pass=20to=20it=20instead=20of=20= outputting=20to=20standard=20out=20or=20to=20a=0A+;;=20different=20file.=20= :in-file=20is=20a=20header=20arguments=20that=20allows=20one=20to=0A+;;=20= tell=20Org=20Babel=20which=20file=20the=20sed=20script=20to=20act=20on.=0A= +=0A+;;;=20Code:=0A+(require=20'ob)=0A+(require=20'sed-mode)=0A+=0A= +(defvar=20org-babel-sed-command=20"sed"=0A+=20=20"Name=20of=20the=20sed=20= executable=20command.")=0A+=0A+(defvar=20org-babel-tangle-lang-exts)=0A= +(add-to-list=20'org-babel-tangle-lang-exts=20'("sed"=20.=20"sed"))=0A+=0A= +(defconst=20org-babel-header-args:sed=0A+=20=20'((:cmd-line=20.=20:any=0A= +=20=20=20=20=20:in-file=20=20.=20:any))=0A+=20=20"Sed=20specific=20= header=20arguments.")=0A+=0A+(defvar=20org-babel-default-header-args:sed=20= '()=0A+=20=20"Default=20arguments=20for=20evaluating=20a=20sed=20source=20= block.")=0A+=0A+(defun=20org-babel-execute:sed=20(body=20params)=0A+=20=20= "Execute=20a=20block=20of=20sed=20code=20with=20Org=20Babel.=0A+BODY=20= is=20the=20source=20inside=20a=20sed=20source=20block=20and=20PARAMS=20= is=20an=0A+association=20list=20over=20the=20source=20block=20= configurations.=20This=0A+function=20is=20called=20by=20= `org-babel-execute-src-block'."=0A+=20=20(message=20"executing=20sed=20= source=20code=20block")=0A+=20=20(let*=20((result-params=20(cdr=20(assq=20= :result-params=20params)))=0A+=20=20=20=20=20=20=20=20=20(cmd-line=20= (cdr=20(assq=20:cmd-line=20params)))=0A+=20=20=20=20=20=20=20=20=20= (in-file=20(cdr=20(assq=20:in-file=20params)))=0A+=09=20(code-file=20= (let=20((file=20(org-babel-temp-file=20"sed-")))=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(with-temp-file=20file=0A+=09= =09=09(insert=20body))=20file))=0A+=09=20(stdin=20(let=20((stdin=20(cdr=20= (assq=20:stdin=20params))))=0A+=09=09=20=20=20(when=20stdin=0A+=09=09=20=20= =20=20=20(let=20((tmp=20(org-babel-temp-file=20"sed-stdin-"))=0A+=09=09=09= =20=20=20(res=20(org-babel-ref-resolve=20stdin)))=0A+=09=09=20=20=20=20=20= =20=20(with-temp-file=20tmp=0A+=09=09=09=20(insert=20res))=0A+=09=09=20=20= =20=20=20=20=20tmp))))=0A+=20=20=20=20=20=20=20=20=20(cmd=20(mapconcat=20= #'identity=0A+=09=09=09=20(remq=20nil=0A+=09=09=09=20=20=20=20=20=20=20= (list=20org-babel-sed-command=0A+=09=09=09=09=20=20=20=20=20(format=20= "--file=3D\"%s\""=20code-file)=0A+=09=09=09=09=20=20=20=20=20cmd-line=0A= +=09=09=09=09=20=20=20=20=20in-file))=0A+=09=09=09=20"=20")))=0A+=20=20=20= =20(org-babel-reassemble-table=0A+=20=20=20=20=20(let=20((results=0A+=20=20= =20=20=20=20=20=20=20=20=20=20(cond=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20(stdin=20(with-temp-buffer=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(call-process-shell-command=20cmd=20stdin=20= (current-buffer))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(buffer-string)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= (t=20(org-babel-eval=20cmd=20"")))))=0A+=20=20=20=20=20=20=20(when=20= results=0A+=20=20=20=20=20=20=20=20=20(org-babel-result-cond=20= result-params=0A+=09=20=20=20results=0A+=09=20=20=20(let=20((tmp=20= (org-babel-temp-file=20"sed-results-")))=0A+=09=20=20=20=20=20= (with-temp-file=20tmp=20(insert=20results))=0A+=09=20=20=20=20=20= (org-babel-import-elisp-from-file=20tmp)))))=0A+=20=20=20=20=20= (org-babel-pick-name=0A+=20=20=20=20=20=20(cdr=20(assq=20:colname-names=20= params))=20(cdr=20(assq=20:colnames=20params)))=0A+=20=20=20=20=20= (org-babel-pick-name=0A+=20=20=20=20=20=20(cdr=20(assq=20:rowname-names=20= params))=20(cdr=20(assq=20:rownames=20params))))))=0A+=0A+(provide=20= 'ob-sed)=0A+;;;=20ob-sed.el=20ends=20here=0Adiff=20--git=20= a/testing/examples/ob-sed-test.org=20b/testing/examples/ob-sed-test.org=0A= new=20file=20mode=20100644=0Aindex=200000000..aae1323=0A---=20/dev/null=0A= +++=20b/testing/examples/ob-sed-test.org=0A@@=20-0,0=20+1,35=20@@=0A= +#+PROPERTY:=20results=20silent=20scalar=0A+#+Title:=20a=20collection=20= of=20examples=20for=20ob-sed=20tests=0A+=0A+*=20Test=20simple=20= execution=20of=20sed=20script=0A+=20=20:PROPERTIES:=0A+=20=20:ID:=20=20=20= =20=20=20=20C7E7CA6A-2601-42C9-B534-4102D62E458D=0A+=20=20:END:=0A+=0A+=20= =20#+NAME:=20ex1=0A+=20=20#+BEGIN_EXAMPLE=0A+=20=20=20=20An=20example=20= sentence.=0A+=20=20#+END_EXAMPLE=0A+=0A+=20=20#+BEGIN_SRC=20sed=20:stdin=20= ex1=0A+=20=20=20=20s/n=20example/=20processed/=0A+=20=20=20=202=20d=0A+=20= =20#+END_SRC=0A+=0A+*=20Test=20:in-file=20header=20argument=0A+=20=20= :PROPERTIES:=0A+=20=20:ID:=20=20=20=20=20=20=20= 54EC49AA-FE9F-4D58-812E-00FC87FAF562=0A+=20=20:END:=0A+=0A+=20=20= #+BEGIN_SRC=20sed=20:in-file=20test1.txt=0A+=20=20s/test/tested/=0A+=20=20= #+END_SRC=0A+=0A+*=20Test=20:cmd-line=20header=20argument=0A+=20=20= :PROPERTIES:=0A+=20=20:ID:=20=20=20=20=20=20=20= E3C6A8BA-39FF-4840-BA8E-90D5C4365AB1=0A+=20=20:END:=0A+=0A+=20=20= #+BEGIN_SRC=20sed=20:in-file=20test2.txt=20:cmd-line=20"-i"=0A+=20=20=20=20= s/test/tested=20again/=0A+=20=20#+END_SRC=0Adiff=20--git=20= a/testing/lisp/test-ob-sed.el=20b/testing/lisp/test-ob-sed.el=0Anew=20= file=20mode=20100644=0Aindex=200000000..c108240=0A---=20/dev/null=0A+++=20= b/testing/lisp/test-ob-sed.el=0A@@=20-0,0=20+1,60=20@@=0A+;;;=20= test-ob-sed.el=20---=20tests=20for=20ob-sed.el=0A+=0A+;;=20Copyright=20= (c)=202015=20Bjarte=20Johansen=0A+;;=20Authors:=20Bjarte=20Johansen=0A+=0A= +;;=20This=20file=20is=20not=20part=20of=20GNU=20Emacs.=0A+=0A+;;=20This=20= program=20is=20free=20software;=20you=20can=20redistribute=20it=20and/or=20= modify=0A+;;=20it=20under=20the=20terms=20of=20the=20GNU=20General=20= Public=20License=20as=20published=20by=0A+;;=20the=20Free=20Software=20= Foundation,=20either=20version=203=20of=20the=20License,=20or=0A+;;=20= (at=20your=20option)=20any=20later=20version.=0A+=0A+;;=20This=20program=20= is=20distributed=20in=20the=20hope=20that=20it=20will=20be=20useful,=0A= +;;=20but=20WITHOUT=20ANY=20WARRANTY;=20without=20even=20the=20implied=20= warranty=20of=0A+;;=20MERCHANTABILITY=20or=20FITNESS=20FOR=20A=20= PARTICULAR=20PURPOSE.=20=20See=20the=0A+;;=20GNU=20General=20Public=20= License=20for=20more=20details.=0A+=0A+;;=20You=20should=20have=20= received=20a=20copy=20of=20the=20GNU=20General=20Public=20License=0A+;;=20= along=20with=20this=20program.=20=20If=20not,=20see=20= .=0A+=0A+;;;=20Code:=0A= +(org-test-for-executable=20"sed")=0A+(unless=20(featurep=20'ob-sed)=0A+=20= =20(signal=20'missing-test-dependency=20"Support=20for=20Sed=20code=20= blocks"))=0A+=0A+(ert-deftest=20ob-sed-test/simple-execution-of-script=20= ()=0A+=20=20"Test=20simple=20execution=20of=20script."=0A+=20=20= (org-test-at-id=20"C7E7CA6A-2601-42C9-B534-4102D62E458D"=0A+=20=20=20=20= (org-babel-next-src-block)=0A+=20=20=20=20(should=20(string=3D=20"A=20= processed=20sentence.\n"=0A+=09=09=20=20=20=20=20= (org-babel-execute-src-block)))))=0A+=0A+(ert-deftest=20= ob-sed-test/in-file-header-argument=20()=0A+=20=20"Test=20:in-file=20= header=20argument."=0A+=20=20(org-test-at-id=20= "54EC49AA-FE9F-4D58-812E-00FC87FAF562"=0A+=20=20=20=20(let=20= ((default-directory=20temporary-file-directory))=0A+=20=20=20=20=20=20= (with-temp-buffer=0A+=09(insert=20"A=20test=20file.")=0A+=09(write-file=20= "test1.txt"))=0A+=20=20=20=20=20=20(org-babel-next-src-block)=0A+=20=20=20= =20=20=20(should=20(string=3D=20"A=20tested=20file.\n"=0A+=09=09=20=20=20= =20=20=20=20(org-babel-execute-src-block))))))=0A+=0A+(ert-deftest=20= ob-sed-test/cmd-line-header-argument=20()=0A+=20=20"Test=20:cmd-line=20= header=20argument."=0A+=20=20(org-test-at-id=20= "E3C6A8BA-39FF-4840-BA8E-90D5C4365AB1"=0A+=20=20=20=20(let=20= ((default-directory=20temporary-file-directory))=0A+=20=20=20=20=20=20= (with-temp-buffer=0A+=09(insert=20"A=20test=20file.")=0A+=09(write-file=20= "test2.txt"))=0A+=20=20=20=20=20=20(org-babel-next-src-block)=0A+=20=20=20= =20=20=20(org-babel-execute-src-block)=0A+=20=20=20=20=20=20(should=20= (string=3D=20"A=20tested=20again=20file.\n"=0A+=09=09=20=20=20=20=20=20=20= (with-temp-buffer=0A+=09=09=09=20(insert-file-contents=20"test2.txt")=0A= +=09=09=09=20(buffer-string)))))))=0A+=0A+=0A+=0A+;;;=20test-ob-sed=20= ends=20here=0A--=20=0A2.3.2=20(Apple=20Git-55)=0A=0A= --Apple-Mail=_18F92B2B-FFAB-4A70-BE90-682EFD638CB6 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii > On 29 May 2015, at 11:00, Nicolas Goaziou wrote: > > Bjarte Johansen writes: > >> I think I have addressed all your comments in the attached patch. > > Thank you. Some more comments follow. > >> Subject: [PATCH] Org Babel now supports sed scripts > > You should add something like the following to your commit message: > > * doc/org.texi: Signal new Babel language > > * lisp/ob-sed.el: > * testing/examples/ob-sed-test.org: > * testing/lisp/test-ob-sed.el: New files. > >> -@item GNU Screen @tab screen @tab shell @tab sh >> -@item SQL @tab sql @tab SQLite @tab sqlite >> +@item GNU Screen @tab screen Sed @tab sed >> +@item @tab shell @tab sh @item SQL @tab sql >> +@item @tab SQLite @tab sqlite @tab @tab > > This looks wrong. I think it should be: > > @item GNU Screen @tab screen @tab Sed @tab sed > @item shell @tab sh @tab SQL @tab sql > @item SQLite @tab sqlite @tab @tab > >> +;;; Usage: >> + >> +;; Add to your Emacs config: >> + >> +;; (org-babel-do-load-languages >> +;; 'org-babel-load-languages >> +;; '((sed . t))) > > You may want to introduce usage for :cmd-line and :in-file arguments in > "Usage" section. > >> +(defconst org-babel-header-args:sed >> + '((:cmd-line :any >> + :in-file :any)) >> + "Sed specific header arguments.") > > It should be > > '((:cmd-line . :any) > (:in-file . :any)) > > See, for example `org-babel-header-args:R' > >> +(defun org-babel-execute:sed (body params) >> + "Execute a block of sed code with Org Babel. >> +BODY is the source inside a sed source block and PARAMS is an >> +association list over the source block configurations. This > ^^^ > two spaces > > > Regards, --Apple-Mail=_18F92B2B-FFAB-4A70-BE90-682EFD638CB6--