* Losing tabs when tangling or editing
@ 2012-05-23 21:18 Michael Hannon
2012-05-28 12:30 ` Thomas S. Dye
0 siblings, 1 reply; 7+ messages in thread
From: Michael Hannon @ 2012-05-23 21:18 UTC (permalink / raw
To: Org-Mode List
Greetings. I was trying to set up a little demo in which I included a
Makefile inside a "sh" source-code block in an Org-mode file, then tangled the
file and ran "make" on the tangled file (either in the actual shell or in
another sh block in Org).
It appears that Org is removing tabs when it tangles the file, and the lack of
tabs causes "make" to complain.
I've appended a toy example which exhibits the problem. BTW, if I edit the
source block via C-c ' I also lose the tabs, i.e., even before tangling.
Any thoughts about this?
Thanks,
-- Mike
$ cat Makefile.original
hw: hw.cpp
g++ -o hw hw.cpp
$ grep -P "\t" Makefile.original
hw: hw.cpp
g++ -o hw hw.cpp
$ make -f Makefile.original
g++ -o hw hw.cpp
$ ./hw
Hello, world!
$ \rm hw
$ cat hw.org
* test preservation of tabs when tangling
#+BEGIN_SRC sh :tangle Makefile.tangled
hw: hw.cpp
g++ -o hw hw.cpp
#+END_SRC
$ make -f Makefile.tangled
Makefile.tangled:3: *** missing separator (did you mean TAB instead of 8
spaces?). Stop.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Losing tabs when tangling or editing
2012-05-23 21:18 Losing tabs when tangling or editing Michael Hannon
@ 2012-05-28 12:30 ` Thomas S. Dye
2012-05-28 21:14 ` Michael Hannon
0 siblings, 1 reply; 7+ messages in thread
From: Thomas S. Dye @ 2012-05-28 12:30 UTC (permalink / raw
To: Michael Hannon; +Cc: Org-Mode List
Michael Hannon <jm_hannon@yahoo.com> writes:
> Greetings. I was trying to set up a little demo in which I included a
> Makefile inside a "sh" source-code block in an Org-mode file, then tangled the
> file and ran "make" on the tangled file (either in the actual shell or in
> another sh block in Org).
>
> It appears that Org is removing tabs when it tangles the file, and the lack of
> tabs causes "make" to complain.
>
> I've appended a toy example which exhibits the problem. BTW, if I edit the
> source block via C-c ' I also lose the tabs, i.e., even before tangling.
>
> Any thoughts about this?
>
> Thanks,
>
> -- Mike
Hi Mike,
I stumbled across this, too, in a somewhat different context. My
"solution" was to hard code the newlines and tabs with \n\t using an
emacs-lisp source block and (format), then evaluate to a file, rather
than tangle. I don't think it's a pretty solution, but it does work.
hth,
Tom
#+name: configure-makefile
#+header: :file Makefile
#+header: :var emacs="/Applications/Emacs-23-4.app/Contents/MacOS/Emacs"
#+header: :var init-file="init-new.el"
#+header: :var exporter="new"
#+header: :eval noexport
#+BEGIN_SRC emacs-lisp
(let ((f (file-name-sans-extension (file-name-nondirectory
(buffer-file-name))))
(g (if (string= exporter "old") "org-export-as-latex" "org-e-latex-export-to-latex")))
(format "CC=gcc
EMACS=%s
BATCH_EMACS=$(EMACS) --batch -Q -l %s %s
all: %s.pdf
%s.tex: %s.org\n\t$(BATCH_EMACS) -f %s
%s.pdf: %s.tex\n\trm -f %s.aux\n\tif pdflatex %s.tex </dev/null; then \\\n\t\ttrue; \\\n\telse \\\n\t\tstat=$$?; touch %s.pdf; exit $$stat; \\\n\tfi\n\tbibtex %s\n\twhile grep \"Rerun to get\" %s.log; do \\\n\t\tif pdflatex %s.tex </dev/null; then \\\n\t\t\ttrue; \\\n\t\telse \\\n\t\t\tstat=$$?; touch %s.pdf; exit $$stat; \\\n\t\tfi; \\\n\tdone
%s.ps: %s.pdf\n\tpdf2ps %s.pdf
clean:\n\trm -f *.aux *.log *.dvi *.blg *.bbl *.toc *.tex *~ *.out %s.pdf *.xml *.lot *.lof
" emacs init-file (file-name-nondirectory (buffer-file-name)) f f f g f f f f f f f f f f f f f))
#+END_SRC
>
>
> $ cat Makefile.original
> hw: hw.cpp
> g++ -o hw hw.cpp
>
> $ grep -P "\t" Makefile.original
> hw: hw.cpp
> g++ -o hw hw.cpp
>
> $ make -f Makefile.original
> g++ -o hw hw.cpp
>
> $ ./hw
> Hello, world!
>
> $ \rm hw
>
> $ cat hw.org
> * test preservation of tabs when tangling
>
> #+BEGIN_SRC sh :tangle Makefile.tangled
>
> hw: hw.cpp
> g++ -o hw hw.cpp
>
> #+END_SRC
>
> $ make -f Makefile.tangled
> Makefile.tangled:3: *** missing separator (did you mean TAB instead of 8
> spaces?). Stop.
>
>
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Losing tabs when tangling or editing
2012-05-28 12:30 ` Thomas S. Dye
@ 2012-05-28 21:14 ` Michael Hannon
2012-05-29 3:45 ` Michael Hannon
2012-05-30 1:05 ` Bernt Hansen
0 siblings, 2 replies; 7+ messages in thread
From: Michael Hannon @ 2012-05-28 21:14 UTC (permalink / raw
To: Thomas S. Dye; +Cc: Org-Mode List
Thomas S. Dye <tsd@tsdye.com> wrote:
>
>> Greetings. I was trying to set up a little demo in which I included a
>> Makefile inside a "sh" source-code block in an Org-mode file,
>> then tangled the file and ran "make" on the tangled file (either in the
>> actual shell or in another sh block in Org).
>>
>> It appears that Org is removing tabs when it tangles the file, and the lack
>> of tabs causes "make" to complain.
>>
>> I've appended a toy example which exhibits the problem. BTW, if I edit
>> the source block via C-c ' I also lose the tabs, i.e., even before
>> tangling.
>>
>> Any thoughts about this?
>>
> I stumbled across this, too, in a somewhat different context. My
> "solution" was to hard code the newlines and tabs with \n\t using an
> emacs-lisp source block and (format), then evaluate to a file, rather
> than tangle. I don't think it's a pretty solution, but it does work.
Thanks, Tom. I admire your ingenuity, but I think your work-around is too
complicated for my purposes. I was hoping to use this example to do a bit of
subliminal proselytizing for Org mode. If I tell people that to do this they
have to hand code a bunch of newlines and tabs, using Emacs lisp at that, I'm
not gonna win many converts.
I was hoping that there might be some kind of customization possible:
(setq leave-the-bleeping-tabs-alone t)
I looked through ob-tangle.el but didn't see anything obvious. (This is
neither surprising nor conclusive, given my limited lisp skills.)
-- Mike
> #+name: configure-makefile
> #+header: :file Makefile
> #+header: :var
> emacs="/Applications/Emacs-23-4.app/Contents/MacOS/Emacs"
> #+header: :var init-file="init-new.el"
> #+header: :var exporter="new"
> #+header: :eval noexport
> #+BEGIN_SRC emacs-lisp
> (let ((f (file-name-sans-extension (file-name-nondirectory
> (buffer-file-name))))
> (g (if (string= exporter "old")
> "org-export-as-latex" "org-e-latex-export-to-latex")))
> (format "CC=gcc
> EMACS=%s
> BATCH_EMACS=$(EMACS) --batch -Q -l %s %s
>
> all: %s.pdf
>
> %s.tex: %s.org\n\t$(BATCH_EMACS) -f %s
>
> %s.pdf: %s.tex\n\trm -f %s.aux\n\tif pdflatex %s.tex
> </dev/null; then \\\n\t\ttrue; \\\n\telse
> \\\n\t\tstat=$$?; touch %s.pdf; exit $$stat;
> \\\n\tfi\n\tbibtex %s\n\twhile grep
> \"Rerun to get\" %s.log; do \\\n\t\tif
> pdflatex %s.tex </dev/null; then \\\n\t\t\ttrue;
> \\\n\t\telse \\\n\t\t\tstat=$$?;
> touch %s.pdf; exit $$stat; \\\n\t\tfi;
> \\\n\tdone
>
> %s.ps: %s.pdf\n\tpdf2ps %s.pdf
>
> clean:\n\trm -f *.aux *.log *.dvi *.blg *.bbl *.toc *.tex *~ *.out
> %s.pdf *.xml *.lot *.lof
> " emacs init-file (file-name-nondirectory (buffer-file-name)) f f f g f
> f f f f f f f f f f f f))
> #+END_SRC
>
>
>>
>>
>> $ cat Makefile.original
>> hw: hw.cpp
>> g++ -o hw hw.cpp
>>
>> $ grep -P "\t" Makefile.original
>> hw: hw.cpp
>> g++ -o hw hw.cpp
>>
>> $ make -f Makefile.original
>> g++ -o hw hw.cpp
>>
>> $ ./hw
>> Hello, world!
>>
>> $ \rm hw
>>
>> $ cat hw.org
>> * test preservation of tabs when tangling
>>
>> #+BEGIN_SRC sh :tangle Makefile.tangled
>>
>> hw: hw.cpp
>> g++ -o hw hw.cpp
>>
>> #+END_SRC
>>
>> $ make -f Makefile.tangled
>> Makefile.tangled:3: *** missing separator (did you mean TAB instead of 8
>> spaces?). Stop.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Losing tabs when tangling or editing
2012-05-28 21:14 ` Michael Hannon
@ 2012-05-29 3:45 ` Michael Hannon
2012-05-30 1:05 ` Bernt Hansen
1 sibling, 0 replies; 7+ messages in thread
From: Michael Hannon @ 2012-05-29 3:45 UTC (permalink / raw
To: Thomas S. Dye; +Cc: Org-Mode List
Michael Hannon <jm_hannon@yahoo.com> wrote:
>
>Thomas S. Dye <tsd@tsdye.com> wrote:
>>
>>> Greetings. I was trying to set up a little demo in which I included a
>>> Makefile inside a "sh" source-code block in an Org-mode file, then tangled
>>> the file and ran "make" on the tangled file (either in the actual shell or
>>> in another sh block in Org).
>>>
>>> It appears that Org is removing tabs when it tangles the file, and the
>>> lack of tabs causes "make" to complain.
>>>
>>> I've appended a toy example which exhibits the problem. BTW, if I edit
>>> the source block via C-c ' I also lose the tabs, i.e., even before
>>> tangling.
>>>
>>> Any thoughts about this?
>>>
>
>> I stumbled across this, too, in a somewhat different context. My
>> "solution" was to hard code the newlines and tabs with \n\t using an
>> emacs-lisp source block and (format), then evaluate to a file, rather than
>> tangle. I don't think it's a pretty solution, but it does work.
>
> Thanks, Tom. I admire your ingenuity, but I think your work-around is too
> complicated for my purposes. I was hoping to use this example to do a bit
> of subliminal proselytizing for Org mode. If I tell people that to do this
> they have to hand code a bunch of newlines and tabs, using Emacs lisp at
> that, I'm not gonna win many converts.
>
> I was hoping that there might be some kind of customization possible:
>
> (setq leave-the-bleeping-tabs-alone t)
>
> I looked through ob-tangle.el but didn't see anything obvious. (This is
> neither surprising nor conclusive, given my limited lisp skills.)
I don't know if this is an improvement or not, but I wrote a tiny awk script
that looks for a space at the beginning of a line and prepends a tab if it
finds one; otherwise, it leaves the line alone. Please see the appended.
-- Mike
$ cat hw.org
* test preservation of tabs when tangling
#+BEGIN_SRC sh :tangle Makefile.tangled
hw: hw.cpp
g++ -o hw hw.cpp
#+END_SRC
$ cat Makefile.tangled
hw: hw.cpp
g++ -o hw hw.cpp
$ grep -P "\t" Makefile.tangled ## check for tabs
$ ## Nope, no tabs
$ cat hw.awk
{
if ( /^ /) {
print "\t" $0
} else {
print $0
}
}
$ awk -f hw.awk Makefile.tangled > Makefile.tangled.fixed
$ grep -P "\t" Makefile.tangled.fixed ## check again for tabs
g++ -o hw hw.cpp
$ make -f Makefile.tangled.fixed
g++ -o hw hw.cpp
$ ./hw
Hello, world!
>
>> #+name: configure-makefile #+header: :file Makefile #+header: :var
>> emacs="/Applications/Emacs-23-4.app/Contents/MacOS/Emacs" #+header: :var
>> init-file="init-new.el" #+header: :var exporter="new" #+header: :eval
>> noexport #+BEGIN_SRC emacs-lisp (let ((f (file-name-sans-extension
>> (file-name-nondirectory (buffer-file-name)))) (g (if (string= exporter
>> "old") "org-export-as-latex" "org-e-latex-export-to-latex"))) (format
>> "CC=gcc EMACS=%s BATCH_EMACS=$(EMACS) --batch -Q -l %s %s
>>
>> all: %s.pdf
>>
>> %s.tex: %s.org\n\t$(BATCH_EMACS) -f %s
>>
>> %s.pdf: %s.tex\n\trm -f %s.aux\n\tif pdflatex %s.tex </dev/null; then
>> \\\n\t\ttrue; \\\n\telse \\\n\t\tstat=$$?; touch %s.pdf; exit $$stat;
>> \\\n\tfi\n\tbibtex %s\n\twhile grep \"Rerun to get\" %s.log; do
>> \\\n\t\tif pdflatex %s.tex </dev/null; then \\\n\t\t\ttrue;
>> \\\n\t\telse \\\n\t\t\tstat=$$?; touch %s.pdf; exit $$stat; \\\n\t\tfi;
>> \\\n\tdone
>>
>> %s.ps: %s.pdf\n\tpdf2ps %s.pdf
>>
>> clean:\n\trm -f *.aux *.log *.dvi *.blg *.bbl *.toc *.tex *~ *.out
>> %s.pdf *.xml *.lot *.lof " emacs init-file (file-name-nondirectory
>> (buffer-file-name)) f f f g f f f f f f f f f f f f f)) #+END_SRC
>>
>>
>>>
>>>
>>> $ cat Makefile.original hw: hw.cpp g++ -o hw hw.cpp
>>>
>>> $ grep -P "\t" Makefile.original hw: hw.cpp g++ -o hw hw.cpp
>>>
>>> $ make -f Makefile.original g++ -o hw hw.cpp
>>>
>>> $ ./hw Hello, world!
>>>
>>> $ \rm hw
>>>
>>> $ cat hw.org * test preservation of tabs when tangling
>>>
>>> #+BEGIN_SRC sh :tangle Makefile.tangled
>>>
>>> hw: hw.cpp g++ -o hw hw.cpp
>>>
>>> #+END_SRC
>>>
>>> $ make -f Makefile.tangled Makefile.tangled:3: *** missing separator (did
>>> you mean TAB instead of 8 spaces?). Stop.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Losing tabs when tangling or editing
2012-05-28 21:14 ` Michael Hannon
2012-05-29 3:45 ` Michael Hannon
@ 2012-05-30 1:05 ` Bernt Hansen
2012-05-30 7:19 ` Michael Hannon
2012-05-30 18:53 ` Thomas S. Dye
1 sibling, 2 replies; 7+ messages in thread
From: Bernt Hansen @ 2012-05-30 1:05 UTC (permalink / raw
To: Michael Hannon; +Cc: Org-Mode List, Thomas S. Dye
Michael Hannon <jm_hannon@yahoo.com> writes:
>
> I was hoping that there might be some kind of customization possible:
>
> (setq leave-the-bleeping-tabs-alone t)
(setq org-src-preserve-indentation t)
maybe?
-Bernt
>
> I looked through ob-tangle.el but didn't see anything obvious. (This is
> neither surprising nor conclusive, given my limited lisp skills.)
>
> -- Mike
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Losing tabs when tangling or editing
2012-05-30 1:05 ` Bernt Hansen
@ 2012-05-30 7:19 ` Michael Hannon
2012-05-30 18:53 ` Thomas S. Dye
1 sibling, 0 replies; 7+ messages in thread
From: Michael Hannon @ 2012-05-30 7:19 UTC (permalink / raw
To: Bernt Hansen; +Cc: Org-Mode List, Thomas S. Dye
Bernt Hansen <bernt@norang.ca> wrote:
>Michael Hannon <jm_hannon@yahoo.com> writes:
>
>>
>> I was hoping that there might be some kind of customization possible:
>>
>> (setq leave-the-bleeping-tabs-alone t)
>
> (setq org-src-preserve-indentation t)
>
> maybe?
>
Woo hoo! Thanks, Bernt. This seems to work. See the appended for a
successful test run.
-- Mike
$ cat hw.org ######## Org-mode file with additional elisp statement
* test preservation of tabs when tangling
#+BEGIN_SRC emacs-lisp
(setq org-src-preserve-indentation t)
#+END_SRC
#+RESULTS:
: t
#+BEGIN_SRC sh :tangle Makefile.tangled
hw: hw.cpp
g++ -o hw hw.cpp
#+END_SRC
$ grep -P "\t" Makefile.tangled ######## found some tabs!
hw: hw.cpp
g++ -o hw hw.cpp
$ make -f Makefile.tangled ######## no complaints from make
g++ -o hw hw.cpp
$ ./hw ######## the newly-compiled program runs
Hello, world!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Losing tabs when tangling or editing
2012-05-30 1:05 ` Bernt Hansen
2012-05-30 7:19 ` Michael Hannon
@ 2012-05-30 18:53 ` Thomas S. Dye
1 sibling, 0 replies; 7+ messages in thread
From: Thomas S. Dye @ 2012-05-30 18:53 UTC (permalink / raw
To: Bernt Hansen; +Cc: Michael Hannon, Org-Mode List
Bernt Hansen <bernt@norang.ca> writes:
> Michael Hannon <jm_hannon@yahoo.com> writes:
>
>>
>> I was hoping that there might be some kind of customization possible:
>>
>> (setq leave-the-bleeping-tabs-alone t)
>
> (setq org-src-preserve-indentation t)
>
> maybe?
>
> -Bernt
>
>>
>> I looked through ob-tangle.el but didn't see anything obvious. (This is
>> neither surprising nor conclusive, given my limited lisp skills.)
>>
>> -- Mike
>
>
Thanks for pointing this out Bernt. Much nicer than \n\t!
All the best,
Tom
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-05-30 18:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-23 21:18 Losing tabs when tangling or editing Michael Hannon
2012-05-28 12:30 ` Thomas S. Dye
2012-05-28 21:14 ` Michael Hannon
2012-05-29 3:45 ` Michael Hannon
2012-05-30 1:05 ` Bernt Hansen
2012-05-30 7:19 ` Michael Hannon
2012-05-30 18:53 ` Thomas S. Dye
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.