emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] Executing sh-code
@ 2009-11-25 14:22 Sébastien Vauban
  2009-11-27  9:15 ` Sébastien Vauban
  2009-11-27 10:00 ` Torsten Wagner
  0 siblings, 2 replies; 24+ messages in thread
From: Sébastien Vauban @ 2009-11-25 14:22 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi,

I'm trying to execute code through babel, for the first time -- I did use it
for small examples of LP, but not yet for enhanced work.

This is my first file:

--8<---------------cut here---------------start------------->8---
* Prerequisites

#+begin_src sh :session ecm
    cd ~/Personal
#+end_src
--8<---------------cut here---------------end--------------->8---

If I C-c on the command, Emacs hangs -- just doing nothing (like waiting for
something that never comes).

C-g gives this:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (quit)
  accept-process-output(#<process shell>)
  (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process buffer)))
  (progn (unless (org-babel-comint-buffer-livep buffer) (error ...)) (set-buffer buffer) (while (progn ... ...) (accept-process-output ...)))
  (unwind-protect (progn (unless ... ...) (set-buffer buffer) (while ... ...)) (set-match-data save-match-data-internal (quote evaporate)))
  (let ((save-match-data-internal ...)) (unwind-protect (progn ... ... ...) (set-match-data save-match-data-internal ...)))
  (save-match-data (unless (org-babel-comint-buffer-livep buffer) (error ...)) (set-buffer buffer) (while (progn ... ...) (accept-process-output ...)))
  (save-window-excursion (save-match-data (unless ... ...) (set-buffer buffer) (while ... ...)))
  (org-babel-comint-in-buffer buffer (while (progn ... ...) (accept-process-output ...)))
  org-babel-comint-wait-for-output(#<buffer *shell*>)
  (progn (setq sh-buffer (current-buffer)) (org-babel-comint-wait-for-output sh-buffer))
  (if newp (progn (setq sh-buffer ...) (org-babel-comint-wait-for-output sh-buffer)))
  (when newp (setq sh-buffer (current-buffer)) (org-babel-comint-wait-for-output sh-buffer))
  (let* ((session ...) (sh-buffer ...) (newp ...)) (if (and sh-buffer ... ...) (setq sh-buffer nil)) (shell sh-buffer) (when newp (setq sh-buffer ...) (org-babel-comint-wait-for-output sh-buffer)) (setq org-babel-sh-buffers (cons ... ...)) session)
  (save-window-excursion (let* (... ... ...) (if ... ...) (shell sh-buffer) (when newp ... ...) (setq org-babel-sh-buffers ...) session))
  org-babel-sh-initiate-session-by-key("ecm")
  (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session))
  (if (string= session "none") nil (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session)))
  (unless (string= session "none") (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session)))
  org-babel-sh-initiate-session("ecm")
  (let* ((processed-params ...) (session ...) (vars ...) (result-type ...) (full-body ...)) (org-babel-sh-evaluate session full-body result-type))
  org-babel-execute:sh("cd ~/Personal\n" ((:exports . "code") (:nocache) (:results . "replace") (:session . "ecm") (:tangle . "")))
  funcall(org-babel-execute:sh "cd ~/Personal\n" ((:exports . "code") (:nocache) (:results . "replace") (:session . "ecm") (:tangle . "")))
  (setq result (funcall cmd body params))
  (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char ...) (move-end-of-line 1) (forward-char 1) (setq result ...) (message ...) result) (setq result (funcall cmd body params)) (if (eq result-type ...) (setq result ...)) (org-babel-insert-result result result-params info new-hash) result)
  (let* ((info ...) (lang ...) (params ...) (new-hash ...) (old-hash ...) (body ...) (result-params ...) (result-type ...) (cmd ...) result) (unless (member lang org-babel-interpreters) (error "Language is not in `org-babel-interpreters': %s" lang)) (if (and ... new-hash ...) (save-excursion ... ... ... ... ... result) (setq result ...) (if ... ...) (org-babel-insert-result result result-params info new-hash) result))
  org-babel-execute-src-block(nil ("sh" "cd ~/Personal\n" ((:exports . "code") (:nocache) (:results . "replace") (:session . "ecm") (:tangle . "")) ""))
  (progn (org-babel-execute-src-block current-prefix-arg info) t)
  (if info (progn (org-babel-execute-src-block current-prefix-arg info) t) nil)
  (let ((info ...)) (if info (progn ... t) nil))
  org-babel-execute-src-block-maybe()
  run-hook-with-args-until-success(org-babel-execute-src-block-maybe)
  org-ctrl-c-ctrl-c(nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
--8<---------------cut here---------------end--------------->8---

and I have an empty Shell buffer:

--8<---------------cut here---------------start------------->8---

[Wed Nov 25 15:13:10]
[sva@mundaneum] ~>
--8<---------------cut here---------------end--------------->8---

What am I doing wrong?  Or have I set something wrong (or missing) in my
.emacs file?

--8<---------------cut here---------------start------------->8---
(require 'org-babel-init)

;; activate a subset of languages
(require 'org-babel-R)
(require 'org-babel-sh)

;; make pre-built helper functions available
(org-babel-load-library-of-babel)
--8<---------------cut here---------------end--------------->8---

Anything interesting in there?

BTW, my next question will be: can we have an SSH session?  Or, I guess that
it's the difficult part: is there a way to ask the password and go on with my
commands?

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] 24+ messages in thread

* Re: [babel] Executing sh-code
  2009-11-25 14:22 [babel] Executing sh-code Sébastien Vauban
@ 2009-11-27  9:15 ` Sébastien Vauban
  2009-11-27 10:46   ` Eric S Fraga
  2009-11-27 10:00 ` Torsten Wagner
  1 sibling, 1 reply; 24+ messages in thread
From: Sébastien Vauban @ 2009-11-27  9:15 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi,

Can I bump up this thread?


> I'm trying to execute code through babel, for the first time -- I did use it
> for small examples of LP, but not yet for enhanced work.
>
> This is my first file:
>
> * Prerequisites
>
> #+begin_src sh :session ecm
>     cd ~/Personal
> #+end_src
>
> If I C-c on the command, Emacs hangs -- just doing nothing (like waiting for
> something that never comes).
>
> C-g gives this:
>
> Debugger entered--Lisp error: (quit)
>   accept-process-output(#<process shell>)
>   (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process buffer)))
>   (progn (unless (org-babel-comint-buffer-livep buffer) (error ...)) (set-buffer buffer) (while (progn ... ...) (accept-process-output ...)))
>   (unwind-protect (progn (unless ... ...) (set-buffer buffer) (while ... ...)) (set-match-data save-match-data-internal (quote evaporate)))
>   (let ((save-match-data-internal ...)) (unwind-protect (progn ... ... ...) (set-match-data save-match-data-internal ...)))
>   (save-match-data (unless (org-babel-comint-buffer-livep buffer) (error ...)) (set-buffer buffer) (while (progn ... ...) (accept-process-output ...)))
>   (save-window-excursion (save-match-data (unless ... ...) (set-buffer buffer) (while ... ...)))
>   (org-babel-comint-in-buffer buffer (while (progn ... ...) (accept-process-output ...)))
>   org-babel-comint-wait-for-output(#<buffer *shell*>)
>   (progn (setq sh-buffer (current-buffer)) (org-babel-comint-wait-for-output sh-buffer))
>   (if newp (progn (setq sh-buffer ...) (org-babel-comint-wait-for-output sh-buffer)))
>   (when newp (setq sh-buffer (current-buffer)) (org-babel-comint-wait-for-output sh-buffer))
>   (let* ((session ...) (sh-buffer ...) (newp ...)) (if (and sh-buffer ... ...) (setq sh-buffer nil)) (shell sh-buffer) (when newp (setq sh-buffer ...) (org-babel-comint-wait-for-output sh-buffer)) (setq org-babel-sh-buffers (cons ... ...)) session)
>   (save-window-excursion (let* (... ... ...) (if ... ...) (shell sh-buffer) (when newp ... ...) (setq org-babel-sh-buffers ...) session))
>   org-babel-sh-initiate-session-by-key("ecm")
>   (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session))
>   (if (string= session "none") nil (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session)))
>   (unless (string= session "none") (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session)))
>   org-babel-sh-initiate-session("ecm")
>   (let* ((processed-params ...) (session ...) (vars ...) (result-type ...) (full-body ...)) (org-babel-sh-evaluate session full-body result-type))
>   org-babel-execute:sh("cd ~/Personal\n" ((:exports . "code") (:nocache) (:results . "replace") (:session . "ecm") (:tangle . "")))
>   funcall(org-babel-execute:sh "cd ~/Personal\n" ((:exports . "code") (:nocache) (:results . "replace") (:session . "ecm") (:tangle . "")))
>   (setq result (funcall cmd body params))
>   (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char ...) (move-end-of-line 1) (forward-char 1) (setq result ...) (message ...) result) (setq result (funcall cmd body params)) (if (eq result-type ...) (setq result ...)) (org-babel-insert-result result result-params info new-hash) result)
>   (let* ((info ...) (lang ...) (params ...) (new-hash ...) (old-hash ...) (body ...) (result-params ...) (result-type ...) (cmd ...) result) (unless (member lang org-babel-interpreters) (error "Language is not in `org-babel-interpreters': %s" lang)) (if (and ... new-hash ...) (save-excursion ... ... ... ... ... result) (setq result ...) (if ... ...) (org-babel-insert-result result result-params info new-hash) result))
>   org-babel-execute-src-block(nil ("sh" "cd ~/Personal\n" ((:exports . "code") (:nocache) (:results . "replace") (:session . "ecm") (:tangle . "")) ""))
>   (progn (org-babel-execute-src-block current-prefix-arg info) t)
>   (if info (progn (org-babel-execute-src-block current-prefix-arg info) t) nil)
>   (let ((info ...)) (if info (progn ... t) nil))
>   org-babel-execute-src-block-maybe()
>   run-hook-with-args-until-success(org-babel-execute-src-block-maybe)
>   org-ctrl-c-ctrl-c(nil)
>   call-interactively(org-ctrl-c-ctrl-c nil nil)
>
> and I have an empty Shell buffer:
>
>
> [Wed Nov 25 15:13:10]
> [sva@mundaneum] ~>
>
> What am I doing wrong?  Or have I set something wrong (or missing) in my
> .emacs file?
>
> (require 'org-babel-init)
>
> ;; activate a subset of languages
> (require 'org-babel-R)
> (require 'org-babel-sh)
>
> ;; make pre-built helper functions available
> (org-babel-load-library-of-babel)
>
> Anything interesting in there?

Is this Emacs config wrong?  Anybody can give me some extract of a working
Babel config (for shell code execution)?


> BTW, my next question will be: can we have an SSH session?  Or, I guess that
> it's the difficult part: is there a way to ask the password and go on with my
> commands?

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] 24+ messages in thread

* Re: [babel] Executing sh-code
  2009-11-25 14:22 [babel] Executing sh-code Sébastien Vauban
  2009-11-27  9:15 ` Sébastien Vauban
@ 2009-11-27 10:00 ` Torsten Wagner
  2009-11-27 10:43   ` Sébastien Vauban
  1 sibling, 1 reply; 24+ messages in thread
From: Torsten Wagner @ 2009-11-27 10:00 UTC (permalink / raw)
  To: emacs-orgmode

Hi Sébastien,

I just tried quickly. I use org-babel with python, up to now never with shell 
scripting.

> 
> --8<---------------cut here---------------start------------->8---
> * Prerequisites
> 
> #+begin_src sh :session ecm
>     cd ~/Personal
> #+end_src
> --8<---------------cut here---------------end--------------->8---


This works for me (I changed the folder name). There is a error line in my 
message buffer
--8<---------------cut here---------------start------------->8---
executing Shell source code block
~/babel 
save-current-buffer: Wrong type argument: char-or-string-p, nil
--8<---------------cut here---------------end------------->8---


but the relevent part runs ok. My shell buffer depict to the new folder after 
execution.


--8<---------------cut here---------------start------------->8---
torsten@gaijin ~ % 
cd ~/babel
echo 'org_babel_sh_eoe'
torsten@gaijin ~ % cd ~/babel
torsten@gaijin ~/babel (git)-[master] %
--8<---------------cut here---------------end------------->8---


I used the same init like you

> What am I doing wrong?  Or have I set something wrong (or missing) in my
> .emacs file?
> 
> --8<---------------cut here---------------start------------->8---
> (require 'org-babel-init)
> 
> ;; activate a subset of languages
> (require 'org-babel-R)
> (require 'org-babel-sh)
> 
> ;; make pre-built helper functions available
> (org-babel-load-library-of-babel)
> --8<---------------cut here---------------end--------------->8---

However I didn't use the (org-babel-load-library-of-babel) function.

Which version of org-mode di you use ? org-babel is young and change still 
heavily. I guess you have to use the latest git-version of org-mode.
Furthermore, does the shell iteself (M-x shell) work in emacs as desired ?

Sorry not a big help at least a pointer that it should work...

Bye

Torsten

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

* Re: [babel] Executing sh-code
  2009-11-27 10:00 ` Torsten Wagner
@ 2009-11-27 10:43   ` Sébastien Vauban
  2009-11-27 19:32     ` Eric Schulte
  2009-11-27 19:46     ` Dan Davison
  0 siblings, 2 replies; 24+ messages in thread
From: Sébastien Vauban @ 2009-11-27 10:43 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Torsten,

Torsten Wagner wrote:
> I just tried quickly. I use org-babel with python, up to now never with
> shell scripting.
>
>> --8<---------------cut here---------------start------------->8---
>> * Prerequisites
>> 
>> #+begin_src sh :session ecm
>>     cd ~/Personal
>> #+end_src
>> --8<---------------cut here---------------end--------------->8---
>
> This works for me (I changed the folder name). There is a error line in my
> message buffer:
>
> executing Shell source code block
> ~/babel 
> save-current-buffer: Wrong type argument: char-or-string-p, nil
>
> but the relevent part runs ok. My shell buffer depict to the new folder
> after execution:
>
> torsten@gaijin ~ % 
> cd ~/babel
> echo 'org_babel_sh_eoe'
> torsten@gaijin ~ % cd ~/babel
> torsten@gaijin ~/babel (git)-[master] %
>
>
> I used the same init like you
>
>> What am I doing wrong? Or have I set something wrong (or missing) in my
>> .emacs file?
>> 
>> --8<---------------cut here---------------start------------->8---
>> (require 'org-babel-init)
>> 
>> ;; activate a subset of languages
>> (require 'org-babel-R)
>> (require 'org-babel-sh)
>> 
>> ;; make pre-built helper functions available
>> (org-babel-load-library-of-babel)
>> --8<---------------cut here---------------end--------------->8---
>
> However I didn't use the (org-babel-load-library-of-babel) function.

I removed it. No change.


> Which version of org-mode di you use ?

A version of somewhere last week.


> org-babel is young and change still heavily. I guess you have to use the
> latest git-version of org-mode.

Just did:

--8<---------------cut here---------------start------------->8---
git pull
make clean
make
--8<---------------cut here---------------end--------------->8---

No change (after Emacs restart).


> Furthermore, does the shell iteself (M-x shell) work in emacs as desired ?

Yep.

Though, there is one blank line in front:

--8<---------------cut here---------------start------------->8---

[sva@mundaneum] ~>
                  ^ cursor blinking here
--8<---------------cut here---------------end--------------->8---

I don't know if that's worth mentionning...

Tried as well this change:

--8<---------------cut here---------------start------------->8---
;; for single shell commands
(setq shell-file-name "zsh")
--8<---------------cut here---------------end--------------->8---

Same problem (after Emacs restart).


> Sorry not a big help at least a pointer that it should work...

Thanks anyway. It's helpful to know someone gets it working the same way (at
least, from a first observation).

Just note that the following works well:

--8<---------------cut here---------------start------------->8---
#+begin_src sh
cd ~/Personal
ls *.org
#+end_src

#+results:
| "Bookmarks.org"                       |
| "Home.org"                            |
| "refile.org"                          |
| "Scorpios.org"                        |
| "Succession.org"                      |
| "Tickler.org"                         |
| "Using-startx-for-Remote-Display.org" |
| "Voice-over-IP.org"                   |
--8<---------------cut here---------------end--------------->8---

It stops working only when I add `:session "whatever"' after the `sh'
specification.

That's the only difference between when it works and when it doesn't.

Maybe this can help?

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] 24+ messages in thread

* Re: Re: [babel] Executing sh-code
  2009-11-27  9:15 ` Sébastien Vauban
@ 2009-11-27 10:46   ` Eric S Fraga
  0 siblings, 0 replies; 24+ messages in thread
From: Eric S Fraga @ 2009-11-27 10:46 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

At Fri, 27 Nov 2009 10:15:41 +0100,
Sébastien Vauban wrote:
> 
> Hi,
> 
> Can I bump up this thread?
> 
> 
> > I'm trying to execute code through babel, for the first time -- I did use it
> > for small examples of LP, but not yet for enhanced work.
> >
> > This is my first file:
> >
> > * Prerequisites
> >
> > #+begin_src sh :session ecm
> >     cd ~/Personal
> > #+end_src

I have the same problem (emacs hangs) but this works just fine without
the session option so I would suggest that the error relates to this
aspect?

Sorry I can't be of any direct help, however. :(

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

* Re: Re: [babel] Executing sh-code
  2009-11-27 10:43   ` Sébastien Vauban
@ 2009-11-27 19:32     ` Eric Schulte
  2009-11-27 19:46     ` Dan Davison
  1 sibling, 0 replies; 24+ messages in thread
From: Eric Schulte @ 2009-11-27 19:32 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

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

>
> It stops working only when I add `:session "whatever"' after the `sh'
> specification.
>
> That's the only difference between when it works and when it doesn't.
>

Hi Sébastien,

You discovered a tricky bug in the session-based evaluation of shell
blocks.  I've just pushed up a fix which fixes this bug and generally
cleans up the code executing sh blocks inside of interactive sessions.
Please try the latest and see if the problem persists.

>
> Maybe this can help?
>

Very much so.

Thanks -- Eric

>
> Best regards,
>   Seb

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

* Re: Re: [babel] Executing sh-code
  2009-11-27 10:43   ` Sébastien Vauban
  2009-11-27 19:32     ` Eric Schulte
@ 2009-11-27 19:46     ` Dan Davison
  2009-11-29 21:03       ` Sébastien Vauban
  1 sibling, 1 reply; 24+ messages in thread
From: Dan Davison @ 2009-11-27 19:46 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

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

> Hi Torsten,
>
> Torsten Wagner wrote:
>> I just tried quickly. I use org-babel with python, up to now never with
>> shell scripting.
>>
>>> --8<---------------cut here---------------start------------->8---
>>> * Prerequisites
>>> 
>>> #+begin_src sh :session ecm
>>>     cd ~/Personal
>>> #+end_src
>>> --8<---------------cut here---------------end--------------->8---
>>
>> This works for me (I changed the folder name). There is a error line in my
>> message buffer:
>>
>> executing Shell source code block
>> ~/babel 
>> save-current-buffer: Wrong type argument: char-or-string-p, nil
>>
>> but the relevent part runs ok. My shell buffer depict to the new folder
>> after execution:
>>
>> torsten@gaijin ~ % 
>> cd ~/babel
>> echo 'org_babel_sh_eoe'
>> torsten@gaijin ~ % cd ~/babel
>> torsten@gaijin ~/babel (git)-[master] %

Hi Seb,

I'm also seeing problems with shell session evaluation but having
trouble debugging. My current suspicion is that the prompt characters
are the problem here (something which differs between you and Torsten)
Could you try using a prompt that ends in '% '? E.g. on ubuntu at least
I can set the prompt in emacs shell sessions with a line like

PS1='\w % '

in ~/.emacs_bash.

Also, please pull latest git as we have just fixed an unrelated bug in
 shell session-based evaluation.

Dan





>>
>>
>> I used the same init like you
>>
>>> What am I doing wrong? Or have I set something wrong (or missing) in my
>>> .emacs file?
>>> 
>>> --8<---------------cut here---------------start------------->8---
>>> (require 'org-babel-init)
>>> 
>>> ;; activate a subset of languages
>>> (require 'org-babel-R)
>>> (require 'org-babel-sh)
>>> 
>>> ;; make pre-built helper functions available
>>> (org-babel-load-library-of-babel)
>>> --8<---------------cut here---------------end--------------->8---
>>
>> However I didn't use the (org-babel-load-library-of-babel) function.
>
> I removed it. No change.
>
>
>> Which version of org-mode di you use ?
>
> A version of somewhere last week.
>
>
>> org-babel is young and change still heavily. I guess you have to use the
>> latest git-version of org-mode.
>
> Just did:
>
> git pull
> make clean
> make
>
> No change (after Emacs restart).
>
>
>> Furthermore, does the shell iteself (M-x shell) work in emacs as desired ?
>
> Yep.
>
> Though, there is one blank line in front:
>
>
> [sva@mundaneum] ~>
>                   ^ cursor blinking here
>
> I don't know if that's worth mentionning...
>
> Tried as well this change:
>
> ;; for single shell commands
> (setq shell-file-name "zsh")
>
> Same problem (after Emacs restart).
>
>
>> Sorry not a big help at least a pointer that it should work...
>
> Thanks anyway. It's helpful to know someone gets it working the same way (at
> least, from a first observation).
>
> Just note that the following works well:
>
> #+begin_src sh
> cd ~/Personal
> ls *.org
> #+end_src
>
> #+results:
> | "Bookmarks.org"                       |
> | "Home.org"                            |
> | "refile.org"                          |
> | "Scorpios.org"                        |
> | "Succession.org"                      |
> | "Tickler.org"                         |
> | "Using-startx-for-Remote-Display.org" |
> | "Voice-over-IP.org"                   |
>
> It stops working only when I add `:session "whatever"' after the `sh'
> specification.
>
> That's the only difference between when it works and when it doesn't.
>
> Maybe this can help?
>
> Best regards,
>   Seb

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

* Re: [babel] Executing sh-code
  2009-11-27 19:46     ` Dan Davison
@ 2009-11-29 21:03       ` Sébastien Vauban
  2009-11-30 15:44         ` Eric Schulte
  0 siblings, 1 reply; 24+ messages in thread
From: Sébastien Vauban @ 2009-11-29 21:03 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric and Dan,

Dan Davison wrote:
> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>> Torsten Wagner wrote:
>>> This works for me (I changed the folder name). There is a error line in my
>>> message buffer:
>>>
>>> executing Shell source code block
>>> ~/babel 
>>> save-current-buffer: Wrong type argument: char-or-string-p, nil
>>>
>>> but the relevent part runs ok. My shell buffer depict to the new folder
>>> after execution:
>>>
>>> torsten@gaijin ~ % 
>>> cd ~/babel
>>> echo 'org_babel_sh_eoe'
>>> torsten@gaijin ~ % cd ~/babel
>>> torsten@gaijin ~/babel (git)-[master] %
>
>> It stops working only when I add `:session "whatever"' after the `sh'
>> specification.
>>
>> That's the only difference between when it works and when it doesn't.
>
> You discovered a tricky bug in the session-based evaluation of shell blocks.

Just for my information (maybe being able to be more accurate next time, or
even finding a solution myself), how do you debug such a problem?

With which debugger, with tracing/stepping?  With stack trace?


> I've just pushed up a fix which fixes this bug and generally cleans up the
> code executing sh blocks inside of interactive sessions. Please try the
> latest and see if the problem persists.

Just did: git pull && make clean && make.


> I'm also seeing problems with shell session evaluation but having
> trouble debugging. My current suspicion is that the prompt characters
> are the problem here (something which differs between you and Torsten)
> Could you try using a prompt that ends in '% '? E.g. on ubuntu at least
> I can set the prompt in emacs shell sessions with a line like
>
> PS1='\w % '
>
> in ~/.emacs_bash.

I did this in my .bashrc:

--8<---------------cut here---------------start------------->8---
# my format of the prompt
function my_prompt_command ()
{
    # colorful prompt, based on whether the previous command succeeded or not
    if [[ $? -eq 0 ]]; then
        HILIT=${GREEN}
    else
        HILIT=${RED}
    fi

    # replace the $HOME prefix by ~ in the current directory
    if [[ $HOME == ${PWD:0:${#HOME}} ]]; then
        NEWPWD="~${PWD:${#HOME}}"
    else
        NEWPWD=$PWD
    fi

    # how many characters of the $PWD should be kept
    local pwd_max_length=15

    if [[ ${#NEWPWD} -gt $pwd_max_length ]]; then
        local pwd_offset=$(( ${#NEWPWD} - $pwd_max_length ))
        NEWPWD="...${NEWPWD:$pwd_offset:$pwd_max_length}"
    fi

    # prompt character
    if [[ $(whoami) = "root" ]]; then
        local PROMPTCHAR="#"
    else
        local PROMPTCHAR=">"
    fi

    case $TERM in
        # TODO use `date' instead of escape characters...
        dumb)
            # Emacs shell mode and Tramp among others
            setenv PS1 "[\u@\h] ${NEWPWD}${PROMPTCHAR}"
            ;;
        emacs | *)
            # Emacs is handled in the same way as other terminals, if it's
            # configured to use `ansi-color' to translate ANSI escape
            # sequences into colored faces
            setenv PS1 "\w % "  ;; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ;;
    esac
}
--8<---------------cut here---------------end--------------->8---


> Also, please pull latest git as we have just fixed an unrelated bug in
> shell session-based evaluation.

Now, with the new version and the prompt change, what's the result?

Let's assume the following Org file:

--8<---------------cut here---------------start------------->8---
#+begin_src sh :session "ecm"
cd ~/Personal
#+end_src

#+begin_src sh :session "ecm"
ls *.org
#+end_src
--8<---------------cut here---------------end--------------->8---

I C-c C-c the first snippet. Nothing special, except it doesn't hang anymore.
So, it already looks much better.

Second snippet. C-c C-c. There, it still hangs ;-((

Though, C-x C-b shows me the contents of the "ecm" buffer:

--8<---------------cut here---------------start------------->8---
cd ~/Personal

~ % ~/Personal % ls *.org
echo 'org_babel_sh_eoe'
Bookmarks.org  Scorpios.org    Tickler.org                          Voice-over-IP.org*
Home.org*      Succession.org  Using-startx-for-Remote-Display.org  refile.org
~/Personal % org_babel_sh_eoe
~/Personal % 
--8<---------------cut here---------------end--------------->8---

Looks closer to what it should...

Still a little problem, though, as explained above.

BTW, what's the impact of specifying "sh" or "bash" for the snippet?

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] 24+ messages in thread

* Re: Re: [babel] Executing sh-code
  2009-11-29 21:03       ` Sébastien Vauban
@ 2009-11-30 15:44         ` Eric Schulte
  2009-11-30 16:02           ` Nick Dokos
                             ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Eric Schulte @ 2009-11-30 15:44 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Hi Sébastien,

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

[...]
>
> Just for my information (maybe being able to be more accurate next time, or
> even finding a solution myself), how do you debug such a problem?
>
> With which debugger, with tracing/stepping?  With stack trace?
>

I'm almost embarrassed to admit that I do most of my elisp debugging
with the `message' function.  I embed `message' debug statements to
print the values of key variables at key points, and I run through
problems looking at the output.

I'd be interested to hear if anyone can recommend a better elisp
debugging solution.

>
> Let's assume the following Org file:
>
> #+begin_src sh :session "ecm"
> cd ~/Personal
> #+end_src
>
> #+begin_src sh :session "ecm"
> ls *.org
> #+end_src
>
> I C-c C-c the first snippet. Nothing special, except it doesn't hang anymore.
> So, it already looks much better.
>
> Second snippet. C-c C-c. There, it still hangs ;-((
>
> Though, C-x C-b shows me the contents of the "ecm" buffer:
>
> cd ~/Personal
>
> ~ % ~/Personal % ls *.org
> echo 'org_babel_sh_eoe'
> Bookmarks.org  Scorpios.org    Tickler.org                          Voice-over-IP.org*
> Home.org*      Succession.org  Using-startx-for-Remote-Display.org  refile.org
> ~/Personal % org_babel_sh_eoe
> ~/Personal % 
>
> Looks closer to what it should...
>
> Still a little problem, though, as explained above.
>

So the fix here is to fix the value of the `comint-prompt-regexp'
variable in your shell.  Org-babel uses this variable to digest output
from the shell.  I have mine set with the following

--8<---------------cut here---------------start------------->8---
(defun schulte/set-shell-prompt-regexp ()
  (setq comint-prompt-regexp "^\(.+\)"))
(add-hook 'shell-mode-hook 'schulte/set-shell-prompt-regexp)
--8<---------------cut here---------------end--------------->8---

You'll have to change the regexp ("^\(.+\)" in my example) to match your
prompt.  I was unable to create your prompt locally.  I find the
`regexp-builder' function to be very handy for these situations.  If you
are unable to build a working regexp please send me a string of your
prompt and I'd be happy to return an appropriate regexp.

on a related topic:

I've also noticed that org-babel has difficulty digesting shell output
when it is ansi-colorized.  I'm not sure what the best fix here would
be.  We could probably start piping all org-babel session results
through something like `ansi-color-filter-region' but that feels a
little bit too heavy.  I'd be interested to hear other peoples
thoughts/suggestions.

>
> BTW, what's the impact of specifying "sh" or "bash" for the snippet?
>

While "sh" blocks should work "bash" blocks will not be recognized.  In
org-babel "sh" doesn't explicitly mean the "sh" command, but rather
means 'run shell' which will default to whatever shell you have
configured.

Thanks -- Eric

>
> Best regards,
>   Seb

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

* Re: Re: [babel] Executing sh-code
  2009-11-30 15:44         ` Eric Schulte
@ 2009-11-30 16:02           ` Nick Dokos
  2009-11-30 16:16             ` Eric Schulte
  2009-12-01 10:01           ` Sébastien Vauban
  2009-12-02 14:55           ` Sébastien Vauban
  2 siblings, 1 reply; 24+ messages in thread
From: Nick Dokos @ 2009-11-30 16:02 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Sébastien Vauban, emacs-orgmode

Eric Schulte <schulte.eric@gmail.com> wrote:

> Hi S=C3=A9bastien,
> 
> S=C3=A9bastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
> 
> [...]
> >
> > Just for my information (maybe being able to be more accurate next time, =
> or
> > even finding a solution myself), how do you debug such a problem?
> >
> > With which debugger, with tracing/stepping?  With stack trace?
> >
> 
> I'm almost embarrassed to admit that I do most of my elisp debugging
> with the `message' function.  I embed `message' debug statements to
> print the values of key variables at key points, and I run through
> problems looking at the output.
> 
> I'd be interested to hear if anyone can recommend a better elisp
> debugging solution.
> 

There are two methods that I use that I think are much more effective
than sprinkling message calls all over the place:

     o edebug-defun: (in emacs-lisp mode, C-u C-M-x) will mark the
     function so that when it is called, the interpreter stops and you can then
     single-step through it with <SPACE>. At each point, you can
     press "e" and evaluate variables (actually arbitrary expressions).

     o Insert a strategically placed (debug) call and then call the function.
     If/when the debug call is executed, you are dropped into the debugger
     and you can then evaluate arbitrary expressions.

HTH,
Nick

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

* Re: Re: [babel] Executing sh-code
  2009-11-30 16:02           ` Nick Dokos
@ 2009-11-30 16:16             ` Eric Schulte
  2009-12-01  8:37               ` Sébastien Vauban
  0 siblings, 1 reply; 24+ messages in thread
From: Eric Schulte @ 2009-11-30 16:16 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Org Mode

Nick Dokos <nicholas.dokos@hp.com> writes:

>
> There are two methods that I use that I think are much more effective
> than sprinkling message calls all over the place:
>
>      o edebug-defun: (in emacs-lisp mode, C-u C-M-x) will mark the
>      function so that when it is called, the interpreter stops and you can then
>      single-step through it with <SPACE>. At each point, you can
>      press "e" and evaluate variables (actually arbitrary expressions).
>
>      o Insert a strategically placed (debug) call and then call the function.
>      If/when the debug call is executed, you are dropped into the debugger
>      and you can then evaluate arbitrary expressions.
>

Excellent.  Thanks Nick, I look forward to the next bug so I can try
these out. -- Eric

>
> HTH,
> Nick

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

* Re: [babel] Executing sh-code
  2009-11-30 16:16             ` Eric Schulte
@ 2009-12-01  8:37               ` Sébastien Vauban
  0 siblings, 0 replies; 24+ messages in thread
From: Sébastien Vauban @ 2009-12-01  8:37 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Nick and Eric,

"Eric Schulte" wrote:
> Nick Dokos <nicholas.dokos-VXdhtT5mjnY@public.gmane.org> writes:
>>
>> There are two methods that I use that I think are much more effective than
>> sprinkling message calls all over the place:
>>
>>      o edebug-defun: (in emacs-lisp mode, C-u C-M-x) will mark the function
>>        so that when it is called, the interpreter stops and you can then
>>        single-step through it with <SPACE>. At each point, you can press
>>        "e" and evaluate variables (actually arbitrary expressions).
>>
>>      o Insert a strategically placed (debug) call and then call the
>>        function. If/when the debug call is executed, you are dropped into
>>        the debugger and you can then evaluate arbitrary expressions.
>
> Excellent.  Thanks Nick, I look forward to the next bug so I can try
> these out. -- Eric

I'd like to be able to enter one level more inside Emacs and its satellites.
But, when I tried to use debuggers, I've always been confused by the multiple
solutions, as there are already 2 different debuggers (with similar names):
debug and edebug.

Plus, I wondered if there wasn't something existing around CEDET or Slime but
for ELisp...

Thanks for your answer,
  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] 24+ messages in thread

* Re: [babel] Executing sh-code
  2009-11-30 15:44         ` Eric Schulte
  2009-11-30 16:02           ` Nick Dokos
@ 2009-12-01 10:01           ` Sébastien Vauban
  2009-12-02 19:09             ` Eric Schulte
  2009-12-02 14:55           ` Sébastien Vauban
  2 siblings, 1 reply; 24+ messages in thread
From: Sébastien Vauban @ 2009-12-01 10:01 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

FYI, I just re-did a git pull && make clean && make, before writing this post
(5 min ago). I also launched a new Emacs.

"Eric Schulte" wrote:
> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>>
>> Let's assume the following Org file:
>>
>> #+begin_src sh :session "ecm"
>> cd ~/Personal
>> #+end_src
>>
>> #+begin_src sh :session "ecm"
>> ls *.org
>> #+end_src
>>
>> I C-c C-c the first snippet. Nothing special, except it doesn't hang anymore.
>> So, it already looks much better.
>>
>> Second snippet. C-c C-c. There, it still hangs ;-((
>>
>> Though, C-x C-b shows me the contents of the "ecm" buffer:
>>
>> cd ~/Personal
>>
>> ~ % ~/Personal % ls *.org
>> echo 'org_babel_sh_eoe'
>> Bookmarks.org  Scorpios.org    Tickler.org                          Voice-over-IP.org*
>> Home.org*      Succession.org  Using-startx-for-Remote-Display.org  refile.org
>> ~/Personal % org_babel_sh_eoe
>> ~/Personal % 

I am still puzzled by the order the commands are mixed with their output:

1. ls command
2. echo command
3. ls output
4. echo output

It's like if everything was sent at once, instead of waiting for the prompt to
appear.

Would I write see in Expect (I love it), I would write something like:

1. expect prompt
2. send ls command
3. expect result followed by prompt
4. send echo command
5. expect result followed by prompt

But, maybe, my observation has nothing to do with my problem...


> So the fix here is to fix the value of the `comint-prompt-regexp'
> variable in your shell.  Org-babel uses this variable to digest output
> from the shell.  I have mine set with the following
>
> (defun schulte/set-shell-prompt-regexp ()
>   (setq comint-prompt-regexp "^\(.+\)"))
> (add-hook 'shell-mode-hook 'schulte/set-shell-prompt-regexp)

I've put that in my .emacs file, as you can see (when asking for its value in
the shell buffer):

--8<---------------cut here---------------start------------->8---
comint-prompt-regexp's value is "^(.+)"
Local in buffer "ecm"; global value is "^"

Documentation:
Regexp to recognize prompts in the inferior process.
Defaults to "^", the null string at BOL.

This variable is only used if the variable
`comint-use-prompt-regexp' is non-nil.

Good choices:
  Canonical Lisp: "^[^> \n]*>+:? *" (Lucid, franz, kcl, T, cscheme, oaklisp)
  Lucid Common Lisp: "^\\(>\\|\\(->\\)+\\) *"
  franz: "^\\(->\\|<[0-9]*>:\\) *"
  kcl: "^>+ *"
  shell: "^[^#$%>\n]*[#$%>] *"
  T: "^>+ *"

This is a good thing to set in mode hooks.
--8<---------------cut here---------------end--------------->8---


> You'll have to change the regexp ("^\(.+\)" in my example) to match your
> prompt.

Nope. Because I'm using your prompt, as you can see in the above shell
session.


> I was unable to create your prompt locally. I find the `regexp-builder'
> function to be very handy for these situations. If you are unable to build a
> working regexp please send me a string of your prompt and I'd be happy to
> return an appropriate regexp.

N/A, if I understand you correctly, as I'm using your prompt within Emacs
shells:

--8<---------------cut here---------------start------------->8---
PS1="\w % "
--8<---------------cut here---------------end--------------->8---


> on a related topic:
>
> I've also noticed that org-babel has difficulty digesting shell output
> when it is ansi-colorized.  I'm not sure what the best fix here would
> be.  We could probably start piping all org-babel session results
> through something like `ansi-color-filter-region' but that feels a
> little bit too heavy.  I'd be interested to hear other peoples
> thoughts/suggestions.

Good you talk of that. Of course, I was using color in my prompt (but not
anymore, see above), but I was coloring ls output as well...

Disabled yesterday...

--8<---------------cut here---------------start------------->8---
# alias ls="ls --color=yes --classify"  # `--color=auto' tells ls to use color
#                                       # iff output is a tty
--8<---------------cut here---------------end--------------->8---

Though, even while I'm using your prompt definition, your prompt regexp
definition, bash as shell, and no color in the ls command, I still have the
same problem: "Emacs" hangs when C-c C-c on the `ls *.org' code block.

Not sure to understand what I can do to go further...

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] 24+ messages in thread

* Re: [babel] Executing sh-code
  2009-11-30 15:44         ` Eric Schulte
  2009-11-30 16:02           ` Nick Dokos
  2009-12-01 10:01           ` Sébastien Vauban
@ 2009-12-02 14:55           ` Sébastien Vauban
  2009-12-02 20:16             ` Eric Schulte
  2 siblings, 1 reply; 24+ messages in thread
From: Sébastien Vauban @ 2009-12-02 14:55 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

"Eric Schulte" wrote:
> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>>
>> What's the impact of specifying "sh" or "bash" for the snippet?
>
> While "sh" blocks should work "bash" blocks will not be recognized. In
> org-babel "sh" doesn't explicitly mean the "sh" command, but rather means
> 'run shell' which will default to whatever shell you have configured.

I wonder if it wouldn't be beneficial to make such a feature explicit. I think
the right shell environment cannot be guessed at runtime. Am I right?

Let's imagine two use cases:

1. I only have zsh on my machine, and I'm writing a document with bash code
   blocks. What if the user executing them is using zsh as his default shell?

2. I have both bash and zsh installed on my machine. I want to write some code
   blocks in bash, and other in zsh. How can I make the difference explicit?

BTW, a "needed" feature is the executable flag for shell scripts. I found a
reference to it ("PROPOSED make tangled files executable? At least if using
shebang line") on http://orgmode.org/worg/org-contrib/babel/development.php.

Thanks anyway for your marvelous tool (replacing my need for Nuweb, and giving
me much more opportunities),
  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] 24+ messages in thread

* Re: Re: [babel] Executing sh-code
  2009-12-01 10:01           ` Sébastien Vauban
@ 2009-12-02 19:09             ` Eric Schulte
  2009-12-04 13:25               ` Sébastien Vauban
  0 siblings, 1 reply; 24+ messages in thread
From: Eric Schulte @ 2009-12-02 19:09 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Hi Sébastien,

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

> Hi Eric,
>
> FYI, I just re-did a git pull && make clean && make, before writing this post
> (5 min ago). I also launched a new Emacs.
>
> "Eric Schulte" wrote:
>> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
>>>
>>> Let's assume the following Org file:
>>>
>>> #+begin_src sh :session "ecm"
>>> cd ~/Personal
>>> #+end_src
>>>
>>> #+begin_src sh :session "ecm"
>>> ls *.org
>>> #+end_src
>>>
>>> I C-c C-c the first snippet. Nothing special, except it doesn't hang anymore.
>>> So, it already looks much better.
>>>
>>> Second snippet. C-c C-c. There, it still hangs ;-((
>>>
>>> Though, C-x C-b shows me the contents of the "ecm" buffer:
>>>
>>> cd ~/Personal
>>>
>>> ~ % ~/Personal % ls *.org
>>> echo 'org_babel_sh_eoe'
>>> Bookmarks.org  Scorpios.org    Tickler.org                          Voice-over-IP.org*
>>> Home.org*      Succession.org  Using-startx-for-Remote-Display.org  refile.org
>>> ~/Personal % org_babel_sh_eoe
 ~/Personal % 
>
> I am still puzzled by the order the commands are mixed with their output:
>
> 1. ls command
> 2. echo command
> 3. ls output
> 4. echo output
>
> It's like if everything was sent at once, instead of waiting for the prompt to
> appear.
>

Yes, there is no easy way that I know of to wait until a command returns
w/o adding some sort of sleep command or complicated filter, so all
commands are inserted before the shell has a chance to respond.

exactly

>
> Would I write see in Expect (I love it), I would write something like:
>

sadly there is no comparable elisp library that I am aware of.  Luckily
it shouldn't matter as the commands are still input to the shell in the
same order, and the output is still collected directly form the shell
with a filter.

>
> 1. expect prompt
> 2. send ls command
> 3. expect result followed by prompt
> 4. send echo command
> 5. expect result followed by prompt
>
> But, maybe, my observation has nothing to do with my problem...
>

Correct, I don't believe this is related to the problem.

> >
>> So the fix here is to fix the value of the `comint-prompt-regexp'
>> variable in your shell.  Org-babel uses this variable to digest output
>> from the shell.  I have mine set with the following
>>
>> (defun schulte/set-shell-prompt-regexp ()
>>   (setq comint-prompt-regexp "^\(.+\)"))
>> (add-hook 'shell-mode-hook 'schulte/set-shell-prompt-regexp)
>
> I've put that in my .emacs file, as you can see (when asking for its value in
> the shell buffer):
>

I'm sorry I wasn't clear in my earlier email.  You will need to craft
your own regexp to replace "^\(.+\)" in the above code.  This is because
you will need to match your own prompt as it appears in your *shell*
buffers locally.  This would be the product of your personal .bashrc or
.zshrc prompt configuration.  The example I pasted above matches my own
prompt which has a non-standard

( ~ )

style.

>
>> You'll have to change the regexp ("^\(.+\)" in my example) to match your
>> prompt.
>
> Nope. Because I'm using your prompt, as you can see in the above shell
> session.
>

Nope, I use a different prompt.  To match a prompt like what you have
above you'd want to use something like closer to the default value of
"^[^#$%>\n]*[#$%>] *".  Sorry for the confusion here.

>> on a related topic:
>>
>> I've also noticed that org-babel has difficulty digesting shell output
>> when it is ansi-colorized.  I'm not sure what the best fix here would
>> be.  We could probably start piping all org-babel session results
>> through something like `ansi-color-filter-region' but that feels a
>> little bit too heavy.  I'd be interested to hear other peoples
>> thoughts/suggestions.
>
> Good you talk of that. Of course, I was using color in my prompt (but not
> anymore, see above), but I was coloring ls output as well...
>
> Disabled yesterday...
>
> # alias ls="ls --color=yes --classify"  # `--color=auto' tells ls to use color
> #                                       # iff output is a tty
>
> Though, even while I'm using your prompt definition, your prompt regexp
> definition, bash as shell, and no color in the ls command, I still have the
> same problem: "Emacs" hangs when C-c C-c on the `ls *.org' code block.
>
> Not sure to understand what I can do to go further...
>

I'm not sure, a fixed prompt regexp should solve the problem.  I now
believe that ansi-coloring may have been a red-herring.  I *do* have
colored ls output aswell, however the following works for me without any
hang.  The only difference I can see between our setups is a matching
prompt regexp.

--8<---------------cut here---------------start------------->8---
#+begin_src sh :session eric
  cd ~/Desktop/clj/
  ls *.clj
#+end_src

#+results:
| "ants.clj" | "" | "concurrent.clj" | "" | "hello.clj" | "" | "spell-checker.clj" |
--8<---------------cut here---------------end--------------->8---

Hope this is helpful. Best -- Eric

>
> Best regards,
>   Seb

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

* Re: Re: [babel] Executing sh-code
  2009-12-02 14:55           ` Sébastien Vauban
@ 2009-12-02 20:16             ` Eric Schulte
  2009-12-03  9:27               ` Sébastien Vauban
  0 siblings, 1 reply; 24+ messages in thread
From: Eric Schulte @ 2009-12-02 20:16 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

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

> Hi Eric,
>
> "Eric Schulte" wrote:
>> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
>>>
>>> What's the impact of specifying "sh" or "bash" for the snippet?
>>
>> While "sh" blocks should work "bash" blocks will not be recognized. In
>> org-babel "sh" doesn't explicitly mean the "sh" command, but rather means
>> 'run shell' which will default to whatever shell you have configured.
>
> I wonder if it wouldn't be beneficial to make such a feature explicit. I think
> the right shell environment cannot be guessed at runtime. Am I right?
>

Hmm, currently we just use the `shell' command which defaults to the
user's defined shell.  I would have to investigate as to how to
explicitly specify a particular shell to run, but I certainly do see
your point that there are times when an explicit shell environment would
be desirable.

I'll create a TODO to reflect this need.

>
> Let's imagine two use cases:
>
> 1. I only have zsh on my machine, and I'm writing a document with bash code
>    blocks. What if the user executing them is using zsh as his default shell?
>
> 2. I have both bash and zsh installed on my machine. I want to write some code
>    blocks in bash, and other in zsh. How can I make the difference explicit?
>
> BTW, a "needed" feature is the executable flag for shell scripts. I found a
> reference to it ("PROPOSED make tangled files executable? At least if using
> shebang line") on http://orgmode.org/worg/org-contrib/babel/development.php.
>

Yes, I agree that this should be implemented, patches are welcome :)

Thanks for the very useful feedback, hopefully we'll be able to make
some progress in these areas soon.

Best -- Eric

>
> Thanks anyway for your marvelous tool (replacing my need for Nuweb, and giving
> me much more opportunities),
>   Seb

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

* Re: [babel] Executing sh-code
  2009-12-02 20:16             ` Eric Schulte
@ 2009-12-03  9:27               ` Sébastien Vauban
  2009-12-03 16:06                 ` Eric Schulte
  0 siblings, 1 reply; 24+ messages in thread
From: Sébastien Vauban @ 2009-12-03  9:27 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

"Eric Schulte" wrote:
> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>> "Eric Schulte" wrote:
>>> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>>>>
>>>> What's the impact of specifying "sh" or "bash" for the snippet?
>>>
>>> While "sh" blocks should work "bash" blocks will not be recognized. In
>>> org-babel "sh" doesn't explicitly mean the "sh" command, but rather means
>>> 'run shell' which will default to whatever shell you have configured.
>>
>> I wonder if it wouldn't be beneficial to make such a feature explicit. I think
>> the right shell environment cannot be guessed at runtime. Am I right?
>
> Hmm, currently we just use the `shell' command which defaults to the user's
> defined shell. I would have to investigate as to how to explicitly specify a
> particular shell to run, but I certainly do see your point that there are
> times when an explicit shell environment would be desirable.
>
> I'll create a TODO to reflect this need.

OK. Thanks.


>> Let's imagine two use cases:
>>
>> 1. I only have zsh on my machine, and I'm writing a document with bash code
>>    blocks. What if the user executing them is using zsh as his default shell?

I meant "I only have bash on my machine". But, whatever, you understood my
point.


>> 2. I have both bash and zsh installed on my machine. I want to write some code
>>    blocks in bash, and other in zsh. How can I make the difference explicit?
>>
>> BTW, a "needed" feature is the executable flag for shell scripts. I found a
>> reference to it ("PROPOSED make tangled files executable? At least if using
>> shebang line") on http://orgmode.org/worg/org-contrib/babel/development.php.
>
> Yes, I agree that this should be implemented, patches are welcome :)

I can imagine. My skills are still maybe a bit low to be productive in that
area. But I really would like to help. Second problem is -- and that must be
the same for everybody (you included) -- a deep lack of time, with real work
for real clients to be done during day, and little daughter to be taken care
of for (almost all) the rest of the time.

That's not an excuse. If I get time, I'll try to...


> Thanks for the very useful feedback, hopefully we'll be able to make
> some progress in these areas soon.

For the time I can now spend on Org-mode, I am making a document that uses
(part of) all the power of Org-babel. My intention is to share my result to
all of you, when it gets finished. That way, maybe I'll get feedback and
improvements as well on it...

It will be helpful for both Org-babel'ers (as an example) and for others as
well, for automating the creation of reports about... sshhht. Will tell when
it's done.

The plan is to use the best of what you give to us, including tables, shell
scripts and R plots.

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] 24+ messages in thread

* Re: Re: [babel] Executing sh-code
  2009-12-03  9:27               ` Sébastien Vauban
@ 2009-12-03 16:06                 ` Eric Schulte
  0 siblings, 0 replies; 24+ messages in thread
From: Eric Schulte @ 2009-12-03 16:06 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

Hi Sébastien,

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

> Hi Eric,
>
> "Eric Schulte" wrote:

[...]

>> Yes, I agree that this should be implemented, patches are welcome :)
>
> I can imagine. My skills are still maybe a bit low to be productive in that
> area. But I really would like to help. Second problem is -- and that must be
> the same for everybody (you included) -- a deep lack of time, with real work
> for real clients to be done during day, and little daughter to be taken care
> of for (almost all) the rest of the time.
>

Yes, lack of sufficient time is very much my limiting factor as well.
I'm looking forward to an extended Christmas break -- after finals --
when I should be able to start to catch up with these accumulating
development tasks.

>
> That's not an excuse. If I get time, I'll try to...
>

Please don't let my flippant reply above make you feel obligated to
learn elisp.  I really do enjoy performing this development myself when
I have time.

>
>> Thanks for the very useful feedback, hopefully we'll be able to make
>> some progress in these areas soon.
>
> For the time I can now spend on Org-mode, I am making a document that uses
> (part of) all the power of Org-babel. My intention is to share my result to
> all of you, when it gets finished. That way, maybe I'll get feedback and
> improvements as well on it...
>
> It will be helpful for both Org-babel'ers (as an example) and for others as
> well, for automating the creation of reports about... sshhht. Will tell when
> it's done.
>
> The plan is to use the best of what you give to us, including tables, shell
> scripts and R plots.
>

I'm intrigued.  Tom Dye has been good enough to start an
org-babel-uses.org file demonstrating some example uses of org-babel.
It is currently available in the Worg git repository at

org-contrib/babel/org-babel-uses.org

however for some reason it isn't surviving the html publication process.
Most likely this is due to the baroque combination of interacting
source-code blocks lurking in the file.

I look forward to your unveiling! -- Eric

>
> Best regards,
>   Seb

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

* Re: [babel] Executing sh-code
  2009-12-02 19:09             ` Eric Schulte
@ 2009-12-04 13:25               ` Sébastien Vauban
  2009-12-04 14:09                 ` Sébastien Vauban
  2009-12-04 17:03                 ` Eric Schulte
  0 siblings, 2 replies; 24+ messages in thread
From: Sébastien Vauban @ 2009-12-04 13:25 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

"Eric Schulte" wrote:
> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>>>>
>>>> #+begin_src sh :session "ecm"
>>>> ls *.org
>>>> #+end_src

Nothing to do with the problem, but better to write `:session ecm' than
`:session "ecm"', no?


>>>> I C-c C-c the first snippet. Nothing special, except it doesn't hang
>>>> anymore. Second snippet. C-c C-c. There, it still hangs ;-((
>>
>> [...]
>>
>>> So the fix here is to fix the value of the `comint-prompt-regexp'
>>> variable in your shell.  Org-babel uses this variable to digest output
>>> from the shell.  I have mine set with the following
>>>
>>> (defun schulte/set-shell-prompt-regexp ()
>>>   (setq comint-prompt-regexp "^\(.+\)"))
>>> (add-hook 'shell-mode-hook 'schulte/set-shell-prompt-regexp)
>>
>> I've put that in my .emacs file, as you can see (when asking for its value in
>> the shell buffer):
>
> I'm sorry I wasn't clear in my earlier email.  You will need to craft
> your own regexp to replace "^\(.+\)" in the above code.  This is because
> you will need to match your own prompt as it appears in your *shell*
> buffers locally.  This would be the product of your personal .bashrc or
> .zshrc prompt configuration.  The example I pasted above matches my own
> prompt which has a non-standard
>
> ( ~ )
>
> style.
>
>>> You'll have to change the regexp ("^\(.+\)" in my example) to match your
>>> prompt.
>>
>> Nope. Because I'm using your prompt, as you can see in the above shell
>> session.
>
> Nope, I use a different prompt.  To match a prompt like what you have
> above you'd want to use something like closer to the default value of
> "^[^#$%>\n]*[#$%>] *".  Sorry for the confusion here.

Okaaayy. Did not look enough at the regexp... Sorry.


> [...] The following works for me without any hang.
> The only difference I can see between our setups is a matching prompt
> regexp.

That was it. Fixing my PS1 prompt to be like yours (temporarily keeping your
regexp from the comint-prompt) *did* solve the problem.

> #+begin_src sh :session eric
>   cd ~/Desktop/clj/
>   ls *.clj
> #+end_src
>
> #+results:
> | "ants.clj" | "" | "concurrent.clj" | "" | "hello.clj" | "" | "spell-checker.clj" |

Similar results for my directory.

Thanks a lot!!!

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] 24+ messages in thread

* Re: [babel] Executing sh-code
  2009-12-04 13:25               ` Sébastien Vauban
@ 2009-12-04 14:09                 ` Sébastien Vauban
  2009-12-04 17:04                   ` Eric Schulte
  2009-12-07  1:10                   ` Torsten Wagner
  2009-12-04 17:03                 ` Eric Schulte
  1 sibling, 2 replies; 24+ messages in thread
From: Sébastien Vauban @ 2009-12-04 14:09 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

Sébastien Vauban wrote:
> "Eric Schulte" wrote:
>>
>> [...] The following works for me without any hang.
>> The only difference I can see between our setups is a matching prompt
>> regexp.
>
> That was it. Fixing my PS1 prompt to be like yours (temporarily keeping your
> regexp from the comint-prompt) *did* solve the problem.

Testing that a bit further, I notice that:

- my Bash prompt must be uncolored for the output to be catchable by
  Org-babel;

- ls can be colored, but control characters are then passed "as is" to
  Org-babel, so better not doing it.

Dunno about the multiline prompt. Stopped using this. Causes me too much
trouble anyway with other configs as well (such as Tramp).

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] 24+ messages in thread

* Re: Re: [babel] Executing sh-code
  2009-12-04 13:25               ` Sébastien Vauban
  2009-12-04 14:09                 ` Sébastien Vauban
@ 2009-12-04 17:03                 ` Eric Schulte
  1 sibling, 0 replies; 24+ messages in thread
From: Eric Schulte @ 2009-12-04 17:03 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

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

> Hi Eric,
>
> "Eric Schulte" wrote:
>> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
>>>>>
>>>>> #+begin_src sh :session "ecm"
>>>>> ls *.org
>>>>> #+end_src
>
> Nothing to do with the problem, but better to write `:session ecm' than
> `:session "ecm"', no?
>

Correct, it will be interpreted as a string either way but :session
"ecm" will actually name your buffer '"emc"' quotes included

[...]
> That was it. Fixing my PS1 prompt to be like yours (temporarily keeping your
> regexp from the comint-prompt) *did* solve the problem.
>
>> #+begin_src sh :session eric
>>   cd ~/Desktop/clj/
>>   ls *.clj
>> #+end_src
>>
>> #+results:
>> | "ants.clj" | "" | "concurrent.clj" | "" | "hello.clj" | "" | "spell-checker.clj" |
>
> Similar results for my directory.
>
> Thanks a lot!!!
>

Excellent, happy this has been resolved -- Eric

>
> Best regards,
>   Seb

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

* Re: Re: [babel] Executing sh-code
  2009-12-04 14:09                 ` Sébastien Vauban
@ 2009-12-04 17:04                   ` Eric Schulte
  2009-12-07  1:10                   ` Torsten Wagner
  1 sibling, 0 replies; 24+ messages in thread
From: Eric Schulte @ 2009-12-04 17:04 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

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

> Hi Eric,
>
> Sébastien Vauban wrote:
>> "Eric Schulte" wrote:
>>>
>>> [...] The following works for me without any hang.
>>> The only difference I can see between our setups is a matching prompt
>>> regexp.
>>
>> That was it. Fixing my PS1 prompt to be like yours (temporarily keeping your
>> regexp from the comint-prompt) *did* solve the problem.
>
> Testing that a bit further, I notice that:
>
> - my Bash prompt must be uncolored for the output to be catchable by
>   Org-babel;
>
> - ls can be colored, but control characters are then passed "as is" to
>   Org-babel, so better not doing it.
>

Thanks for these notes.  I'll add a task related to this, as it
shouldn't be too difficult to strip out the ansi-color characters.

Thanks -- Eric

>
> Dunno about the multiline prompt. Stopped using this. Causes me too much
> trouble anyway with other configs as well (such as Tramp).
>
> Best regards,
>   Seb

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

* Re: Re: [babel] Executing sh-code
  2009-12-04 14:09                 ` Sébastien Vauban
  2009-12-04 17:04                   ` Eric Schulte
@ 2009-12-07  1:10                   ` Torsten Wagner
  2009-12-07  9:59                     ` Sébastien Vauban
  1 sibling, 1 reply; 24+ messages in thread
From: Torsten Wagner @ 2009-12-07  1:10 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

> Hi Eric,
> 
> Sébastien Vauban wrote:
> > "Eric Schulte" wrote:
> >>
> >> [...] The following works for me without any hang.
> >> The only difference I can see between our setups is a matching prompt
> >> regexp.
> >
> > That was it. Fixing my PS1 prompt to be like yours (temporarily keeping 
your
> > regexp from the comint-prompt) *did* solve the problem.
> 
> Testing that a bit further, I notice that:
> 
> - my Bash prompt must be uncolored for the output to be catchable by
>   Org-babel;
> 
> - ls can be colored, but control characters are then passed "as is" to
>   Org-babel, so better not doing it.


As I said before, the example worked fine for me...
I like to add that I use a very very colorful prompt but using zsh instead of 
bash....
Maybe this is somehow interesting for bug-fixing.


Best regards

Torsten

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

* Re: [babel] Executing sh-code
  2009-12-07  1:10                   ` Torsten Wagner
@ 2009-12-07  9:59                     ` Sébastien Vauban
  0 siblings, 0 replies; 24+ messages in thread
From: Sébastien Vauban @ 2009-12-07  9:59 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Torsten,

Torsten Wagner wrote:
>> Sébastien Vauban wrote:
>> > "Eric Schulte" wrote:
>> >>
>> >> [...] The following works for me without any hang.
>> >> The only difference I can see between our setups is a matching prompt
>> >> regexp.
>> >
>> > That was it. Fixing my PS1 prompt to be like yours (temporarily keeping
>> > your regexp from the comint-prompt) *did* solve the problem.
>> 
>> Testing that a bit further, I notice that:
>> 
>> - my Bash prompt must be uncolored for the output to be catchable by
>>   Org-babel;
>> 
>> - ls can be colored, but control characters are then passed "as is" to
>>   Org-babel, so better not doing it.
>
> As I said before, the example worked fine for me...
> I like to add that I use a very very colorful prompt but using zsh instead of 
> bash....
> Maybe this is somehow interesting for bug-fixing.

What's your value for PS1 under zsh?

What's your value for comint-prompt-regexp under Emacs shell?

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] 24+ messages in thread

end of thread, other threads:[~2009-12-07  9:59 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-25 14:22 [babel] Executing sh-code Sébastien Vauban
2009-11-27  9:15 ` Sébastien Vauban
2009-11-27 10:46   ` Eric S Fraga
2009-11-27 10:00 ` Torsten Wagner
2009-11-27 10:43   ` Sébastien Vauban
2009-11-27 19:32     ` Eric Schulte
2009-11-27 19:46     ` Dan Davison
2009-11-29 21:03       ` Sébastien Vauban
2009-11-30 15:44         ` Eric Schulte
2009-11-30 16:02           ` Nick Dokos
2009-11-30 16:16             ` Eric Schulte
2009-12-01  8:37               ` Sébastien Vauban
2009-12-01 10:01           ` Sébastien Vauban
2009-12-02 19:09             ` Eric Schulte
2009-12-04 13:25               ` Sébastien Vauban
2009-12-04 14:09                 ` Sébastien Vauban
2009-12-04 17:04                   ` Eric Schulte
2009-12-07  1:10                   ` Torsten Wagner
2009-12-07  9:59                     ` Sébastien Vauban
2009-12-04 17:03                 ` Eric Schulte
2009-12-02 14:55           ` Sébastien Vauban
2009-12-02 20:16             ` Eric Schulte
2009-12-03  9:27               ` Sébastien Vauban
2009-12-03 16:06                 ` 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).