emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Babel] Coding system of tangled files?
@ 2010-11-18 12:59 Sébastien Vauban
  2010-11-18 14:07 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Sébastien Vauban @ 2010-11-18 12:59 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

#+TITLE:     Format for tangling files
#+DATE:      2010-11-18

#+BABEL: :comments yes

* Script

#+begin_src sh :tangle doit.sh
#!/bin/bash
# Example

ls
date
#+end_src

* Execute it in a Bash shell

The tangled file, when launched from withing a Bash shell, returns errors:

#+begin_src sh
sva@MEDIACENTER:.../Accounting/dev 127$ ./doit.sh 
./doit.sh: line 4: $'\r': command not found
./doit.sh: line 5: $'ls\r': command not found
./doit.sh: line 6: $'date\r': command not found
#+end_src

The reason is that the tangled file is saved as UTF-8-dos (being under
Windows). It should be saved in unix format. Is there a way to impose this?

Best regards,
  Seb

-- 
Sébastien Vauban


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Babel] Coding system of tangled files?
  2010-11-18 12:59 [Babel] Coding system of tangled files? Sébastien Vauban
@ 2010-11-18 14:07 ` Eric Schulte
  2010-11-22 12:41   ` Sébastien Vauban
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2010-11-18 14:07 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Hi Seb,

I think this should be possible using the `org-babel-post-tangle-hook'
to re-save the file with a specified encoding.  After looking into this
a little bit it appears that you should be able to add a function to
this hook which will update the `save-buffer-coding-system' variable and
then re-save the buffer.  This should allow you to save tangled files in
arbitrary code systems.  For information on coding systems following
this Org-mode link into the elisp documentation by calling M-x
org-open-at-point on the following line.

[[info:elisp:Coding%20Systems][info:elisp:Coding Systems]]

Best -- Eric

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

> #+TITLE:     Format for tangling files
> #+DATE:      2010-11-18
>
> #+BABEL: :comments yes
>
> * Script
>
> #+begin_src sh :tangle doit.sh
> #!/bin/bash
> # Example
>
> ls
> date
> #+end_src
>
> * Execute it in a Bash shell
>
> The tangled file, when launched from withing a Bash shell, returns errors:
>
> #+begin_src sh
> sva@MEDIACENTER:.../Accounting/dev 127$ ./doit.sh 
> ./doit.sh: line 4: $'\r': command not found
> ./doit.sh: line 5: $'ls\r': command not found
> ./doit.sh: line 6: $'date\r': command not found
> #+end_src
>
> The reason is that the tangled file is saved as UTF-8-dos (being under
> Windows). It should be saved in unix format. Is there a way to impose this?
>
> Best regards,
>   Seb

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Babel] Coding system of tangled files?
  2010-11-18 14:07 ` Eric Schulte
@ 2010-11-22 12:41   ` Sébastien Vauban
  2010-11-22 13:20     ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Sébastien Vauban @ 2010-11-22 12:41 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

"Eric Schulte" wrote:
> I think this should be possible using the `org-babel-post-tangle-hook' to
> re-save the file with a specified encoding. After looking into this a little
> bit it appears that you should be able to add a function to this hook which
> will update the `save-buffer-coding-system' variable and then re-save the
> buffer. This should allow you to save tangled files in arbitrary code
> systems.

#+TITLE:     Format for tangling files
#+DATE:      2010-11-22

#+BABEL: :comments yes

* Bug report

** Script

#+begin_src sh :tangle doit.sh
#!/bin/bash
# L'élève est là-bas...

ls
date
#+end_src

** Execute it in a Bash shell

The tangled file, when launched from withing a Bash shell, returns errors:

#+begin_src sh
sva@MEDIACENTER:.../Accounting/dev 0$ ./doit.sh 
./doit.sh: line 4: $'\r': command not found
./doit.sh: line 5: $'ls\r': command not found
./doit.sh: line 6: $'date\r': command not found
#+end_src

The reason is that the tangled file is saved as UTF-8-dos (being under
Windows). It should be saved in unix format. Is there a way to impose this?

* Answer from Eric

#+begin_example
I think this should be possible using the `org-babel-post-tangle-hook' to
re-save the file with a specified encoding. After looking into this a little
bit it appears that you should be able to add a function to this hook which
will update the `save-buffer-coding-system' variable and then re-save the
buffer.
#+end_example

* Tests

** One

Evaluate this:

#+begin_src emacs-lisp :results silent :tangle no
(add-hook 'org-babel-pre-tangle-hook
          (lambda ()
            (setq save-buffer-coding-system 'iso-latin-9-unix)))
#+end_src

Instead of setting the variable in *post* hook (and saving the tangled file --
for which I did not know how to procede: what's the argument to give to
save?), I wondered if it shouldn't be easier to set it in the *pre* hook...

Though, the above does not work as I would expect.

** Two

After different trials, I came up with the following which works for me...

Evaluate this:

#+begin_src emacs-lisp :results silent :tangle no
(add-hook 'org-babel-pre-tangle-hook
          (lambda ()
            (setq coding-system-for-write 'iso-latin-9-unix)))
#+end_src

It's not clear to me what's the exact difference between the 2 variables
(=save-buffer-coding-system= and =coding-system-for-write=). But that works:

#+begin_src sh
sva@MEDIACENTER:.../Accounting/dev 0$ doit.sh
accountlog.csv  csv2ledger.sh  doit.sh  ecm-tangle.txt  my-csv2ledger.html  my-csv2ledger.txt
Mon Nov 22 13:30:12     2010
#+end_src

Best regards,
  Seb

-- 
Sébastien Vauban


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [Babel] Coding system of tangled files?
  2010-11-22 12:41   ` Sébastien Vauban
@ 2010-11-22 13:20     ` Eric Schulte
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2010-11-22 13:20 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

> ** Two
>
> After different trials, I came up with the following which works for me...
>
> Evaluate this:
>
> #+begin_src emacs-lisp :results silent :tangle no
> (add-hook 'org-babel-pre-tangle-hook
>           (lambda ()
>             (setq coding-system-for-write 'iso-latin-9-unix)))
> #+end_src
>

That's great, I'm happy you found a solution.

>
> It's not clear to me what's the exact difference between the 2 variables
> (=save-buffer-coding-system= and =coding-system-for-write=). But that works:
>

I don't know myself, I've never had to dig too deeply into Emacs coding
system.

Cheers -- Eric

>
> #+begin_src sh
> sva@MEDIACENTER:.../Accounting/dev 0$ doit.sh
> accountlog.csv  csv2ledger.sh  doit.sh  ecm-tangle.txt  my-csv2ledger.html  my-csv2ledger.txt
> Mon Nov 22 13:30:12     2010
> #+end_src
>
>
> Best regards,
>   Seb

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-11-22 14:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-18 12:59 [Babel] Coding system of tangled files? Sébastien Vauban
2010-11-18 14:07 ` Eric Schulte
2010-11-22 12:41   ` Sébastien Vauban
2010-11-22 13:20     ` Eric Schulte

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).