From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Hannon Subject: Re: Losing tabs when tangling or editing Date: Mon, 28 May 2012 20:45:07 -0700 (PDT) Message-ID: <1338263107.63395.YahooMailNeo@web161902.mail.bf1.yahoo.com> References: <1337807919.11721.YahooMailNeo@web161904.mail.bf1.yahoo.com> <1338239656.10918.YahooMailNeo@web161905.mail.bf1.yahoo.com> Reply-To: Michael Hannon Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:39286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZDMv-000486-8r for emacs-orgmode@gnu.org; Mon, 28 May 2012 23:45:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SZDMs-0000rt-7e for emacs-orgmode@gnu.org; Mon, 28 May 2012 23:45:12 -0400 Received: from nm7-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.151]:37307) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SZDMr-0000rX-Uk for emacs-orgmode@gnu.org; Mon, 28 May 2012 23:45:10 -0400 In-Reply-To: <1338239656.10918.YahooMailNeo@web161905.mail.bf1.yahoo.com> 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: "Thomas S. Dye" Cc: Org-Mode List Michael Hannon wrote:=0A>=0A>Thomas S. Dye wrote:=0A>>=0A>>> Greetings.=A0 I was trying to set up a little demo = in which I included a=0A>>> Makefile inside a "sh" source-code block in an = Org-mode file, then tangled=0A>>> the file and ran "make" on the tangled fi= le (either in the actual shell or=0A>>> in another sh block in Org).=0A>>>= =0A>>> It appears that Org is removing tabs when it tangles the file, and t= he=0A>>> lack of tabs causes "make" to complain.=0A>>>=0A>>> I've appended = a toy example which exhibits the problem.=A0 BTW, if I edit=0A>>> the sourc= e block via C-c ' I also lose the tabs, i.e., even before=0A>>> tangling.= =0A>>>=0A>>> Any thoughts about this?=0A>>>=0A>=0A>> I stumbled across this= , too, in a somewhat different context.=A0 My=0A>> "solution" was to hard c= ode the newlines and tabs with \n\t using an=0A>> emacs-lisp source block a= nd (format), then evaluate to a file, rather than=0A>> tangle.=A0 I don't t= hink it's a pretty solution, but it does work.=0A>=0A> Thanks, Tom.=A0 I ad= mire your ingenuity, but I think your work-around is too=0A> complicated fo= r my purposes.=A0 I was hoping to use this example to do a bit=0A> of subli= minal proselytizing for Org mode.=A0 If I tell people that to do this=0A> t= hey have to hand code a bunch of newlines and tabs, using Emacs lisp at=0A>= that, I'm not gonna win many converts.=0A>=0A> I was hoping that there mig= ht be some kind of customization possible:=0A>=0A>=A0=A0=A0 (setq leave-the= -bleeping-tabs-alone t)=0A>=0A> I looked through ob-tangle.el but didn't se= e anything obvious.=A0 (This is=0A> neither surprising nor conclusive, give= n my limited lisp skills.)=0A=0AI don't know if this is an improvement or n= ot, but I wrote a tiny awk script=0Athat looks for a space at the beginning= of a line and prepends a tab if it=0Afinds one; otherwise, it leaves the l= ine alone.=A0 Please see the appended.=0A=0A-- Mike=0A=0A$ cat hw.org=0A* t= est preservation of tabs when tangling=0A=0A#+BEGIN_SRC sh :tangle Makefile= .tangled=0A=0Ahw:=A0=A0=A0 hw.cpp=0A=A0=A0=A0 g++ -o hw hw.cpp=0A=0A=A0 =0A= #+END_SRC=0A=0A=0A$ cat Makefile.tangled=0A=0Ahw:=A0=A0=A0=A0 hw.cpp=0A=A0= =A0=A0=A0=A0=A0=A0 g++ -o hw hw.cpp=0A=0A$ grep -P "\t" Makefile.tangled=A0= =A0=A0 ## check for tabs=0A$=A0=A0 ## Nope, no tabs=0A=0A$ cat hw.awk=0A{= =0A=A0 if ( /^ /) {=0A=A0=A0=A0 print "\t" $0=0A=A0=A0=A0=A0 } else {=0A=A0= =A0=A0 print $0=0A=A0=A0=A0=A0 }=0A}=0A=0A$ awk -f hw.awk Makefile.tangled = > Makefile.tangled.fixed=0A=0A$ grep -P "\t" Makefile.tangled.fixed=A0=A0 #= # check again for tabs=0A=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0 g++ -o hw hw.cpp= =0A=0A$ make -f Makefile.tangled.fixed =0Ag++ -o hw hw.cpp=0A=0A$ ./hw=0AHe= llo, world!=0A=0A>=0A>> #+name: configure-makefile #+header: :file Makefile= #+header: :var=0A>> emacs=3D"/Applications/Emacs-23-4.app/Contents/MacOS/E= macs" #+header: :var=0A>> init-file=3D"init-new.el" #+header: :var exporter= =3D"new" #+header: :eval=0A>> noexport #+BEGIN_SRC emacs-lisp (let ((f (fil= e-name-sans-extension=0A>> (file-name-nondirectory (buffer-file-name)))) (g= (if (string=3D exporter=0A>> "old") "org-export-as-latex" "org-e-latex-exp= ort-to-latex"))) (format=0A>> "CC=3Dgcc EMACS=3D%s BATCH_EMACS=3D$(EMACS) -= -batch -Q -l %s %s=0A>>=A0=A0=A0 =0A>>=A0=A0=A0=A0 all: %s.pdf=0A>>=A0=A0= =A0 =0A>>=A0=A0=A0=A0 %s.tex: %s.org\n\t$(BATCH_EMACS) -f %s=0A>>=A0=A0=A0 = =0A>>=A0=A0=A0=A0 %s.pdf: %s.tex\n\trm -f %s.aux\n\tif pdflatex %s.tex >=A0=A0=A0=A0 \\\n\t\ttrue; \\\n\telse \\\n\t\tstat=3D$$?; = touch %s.pdf; exit $$stat;=0A>>=A0=A0=A0=A0 \\\n\tfi\n\tbibtex %s\n\twhile = grep \"Rerun to get\" %s.log; do=0A>>=A0=A0=A0=A0 \\\n\t\tif pdflatex %s.te= x >=A0=A0=A0=A0 \\\n\t\telse \\\n\t\t\t= stat=3D$$?; touch %s.pdf; exit $$stat; \\\n\t\tfi;=0A>>=A0=A0=A0=A0 \\\n\td= one=0A>>=A0=A0=A0 =0A>>=A0=A0=A0=A0 %s.ps: %s.pdf\n\tpdf2ps %s.pdf=0A>>=A0= =A0=A0 =0A>>=A0=A0=A0=A0 clean:\n\trm -f *.aux *.log=A0 *.dvi *.blg *.bbl *= .toc *.tex *~ *.out=0A>>=A0=A0=A0=A0 %s.pdf *.xml *.lot *.lof " emacs init-= file (file-name-nondirectory=0A>>=A0=A0=A0=A0 (buffer-file-name)) f f f g f= f f f f f f f f f f f f)) #+END_SRC=0A>>=0A>>=0A>>>=0A>>>=0A>>> $ cat Make= file.original hw:=A0=A0=A0 hw.cpp g++ -o hw hw.cpp=0A>>>=0A>>> $ grep -P "\= t" Makefile.original hw:=A0=A0=A0 hw.cpp g++ -o hw hw.cpp=0A>>>=0A>>> $ mak= e -f Makefile.original g++ -o hw hw.cpp=0A>>>=0A>>> $ ./hw Hello, world!=0A= >>>=0A>>> $ \rm hw=0A>>>=0A>>> $ cat hw.org * test preservation of tabs whe= n tangling=0A>>>=0A>>> #+BEGIN_SRC sh :tangle Makefile.tangled=0A>>>=0A>>> = hw:=A0=A0=A0 hw.cpp g++ -o hw hw.cpp=0A>>>=0A>>> #+END_SRC=0A>>>=0A>>> $ ma= ke -f Makefile.tangled Makefile.tangled:3: *** missing separator (did=0A>>>= you mean TAB instead of 8 spaces?).=A0 Stop.