Re: [O] babel completion notification
The other options are prettier and the hook is more flexible; I had only cared about tangling though so I set this: (defadvice org-babel-tangle (before org-babel-tangle-before activate) (message (concat "org-babel-tangle BEFORE: <" (format-time-string "%Y-%m-%dT%T%z") ">"))) (defadvice org-babel-tangle (after org-babel-tangle-after activate) (message (concat "org-babel-tangle AFTER: <" (format-time-string "%Y-%m-%dT%T%z") ">"))) For some reason couldn't get around advice working here, it was just never run. On Tue, Mar 18, 2014 at 9:32 AM, Eric Schulte wrote: > > However, there is a problem: > > > > --8<---cut here---start->8--- > > #+name: notify > > #+BEGIN_SRC emacs-lisp :results none > > (shell-command "popup.py DONE") > > #+END_SRC > > > > #+name: long-running > > #+BEGIN_SRC shell :results output :post notify > > sleep 5 > > echo DONE > > #+END_SRC > > > > #+RESULTS: long-running > > : nil > > --8<---cut here---end--->8--- > > > > The result seems to be the result of the notify block, not the > > long-running one. > > Yes, that's how post blocks are supposed to work, they're normally used > to post-process results. You should add a variable to the post block > and have it return that variable, e.g., > > #+name: notify > #+begin_src emacs-lisp :var data="" > (shell-command "popup.py DONE") > data > #+end_src > > -- > Eric Schulte > https://cs.unm.edu/~eschulte > PGP: 0x614CA05D > > -- Grant Rettke | ACM, AMA, COG, IEEE g...@wisdomandwonder.com | http://www.wisdomandwonder.com/ “Wisdom begins in wonder.” --Socrates ((λ (x) (x x)) (λ (x) (x x))) “Life has become immeasurably better since I have been forced to stop taking it seriously.” --Thompson
Re: [O] babel completion notification
> However, there is a problem: > > --8<---cut here---start->8--- > #+name: notify > #+BEGIN_SRC emacs-lisp :results none > (shell-command "popup.py DONE") > #+END_SRC > > #+name: long-running > #+BEGIN_SRC shell :results output :post notify > sleep 5 > echo DONE > #+END_SRC > > #+RESULTS: long-running > : nil > --8<---cut here---end--->8--- > > The result seems to be the result of the notify block, not the > long-running one. Yes, that's how post blocks are supposed to work, they're normally used to post-process results. You should add a variable to the post block and have it return that variable, e.g., #+name: notify #+begin_src emacs-lisp :var data="" (shell-command "popup.py DONE") data #+end_src -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D
Re: [O] babel completion notification
Eric Schulte writes: > Nick Dokos writes: > >> (popup.py is my homemade notifier) > > Try adding `(lambda () (shell-command-to-string "popup.py babel done"))' > to your `org-babel-after-execute-hook'. > >> >> I get the popup immediately and the results after 10 seconds. The >> org-babel-after-execute-hook method worked fine. >> Yes, as I said, the hook worked fine :-), although the function would have to be munged so that the notification doesn't pop up indiscriminately after every evaluation. > > That is probably because the elisp form in the :post value is executed > at header-argument parse time before the code block is executed. If > instead your use a code block name as your post header argument it will > only be evaluated after the code block finishes. > Thanks - that's good to know: the fact that it can be applied selectively to certain code blocks does make it a much better solution than the hook. However, there is a problem: --8<---cut here---start->8--- #+name: notify #+BEGIN_SRC emacs-lisp :results none (shell-command "popup.py DONE") #+END_SRC #+name: long-running #+BEGIN_SRC shell :results output :post notify sleep 5 echo DONE #+END_SRC #+RESULTS: long-running : nil --8<---cut here---end--->8--- The result seems to be the result of the notify block, not the long-running one. -- Nick
Re: [O] babel completion notification
Nick Dokos writes: > Ken Mankoff writes: > >> Hi Eric, >> >> On 2014-03-17 at 17:05, Eric Schulte wrote: >>> Ken Mankoff writes: >>> Until asynchronous babel exists, it would be nice to at least be notified when long-running tasks complete. Does anyone have advice how to set up a hook on babel completion so that growl or some other system notification alerts, perhaps only if the execution took more than x seconds? >>> >>> You can use the org-babel-after-execute-hook to run any action after a >>> code block finishes executing. >> >> Yes, and your reply makes me recall that :post works too, so I can >> call a shell command "notifier" (or Growl) like this: >> >> #+BEGIN_SRC python -n :results output :post (shell-command-to-string >> "notifier 'babel done'") >> print "hello, world" >> #+END_SRC >> #+RESULTS: >> > > The :post method does not seem to work for me. With: > > --8<---cut here---start->8--- > #+BEGIN_SRC sh :results output :post (shell-command-to-string "popup.py > babel done") > sleep 10 > echo DONE > #+END_SRC > --8<---cut here---end--->8--- > > (popup.py is my homemade notifier) Try adding `(lambda () (shell-command-to-string "popup.py babel done"))' to your `org-babel-after-execute-hook'. > > I get the popup immediately and the results after 10 seconds. The > org-babel-after-execute-hook method worked fine. > That is probably because the elisp form in the :post value is executed at header-argument parse time before the code block is executed. If instead your use a code block name as your post header argument it will only be evaluated after the code block finishes. Best, > > Nick > > > > > -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D
Re: [O] babel completion notification
Ken Mankoff writes: > Hi Eric, > > On 2014-03-17 at 17:05, Eric Schulte wrote: >> Ken Mankoff writes: >> >>> Until asynchronous babel exists, it would be nice to at least be >>> notified when long-running tasks complete. Does anyone have advice >>> how to set up a hook on babel completion so that growl or some >>> other system notification alerts, perhaps only if the execution >>> took more than x seconds? >> >> You can use the org-babel-after-execute-hook to run any action after a >> code block finishes executing. > > Yes, and your reply makes me recall that :post works too, so I can > call a shell command "notifier" (or Growl) like this: > > #+BEGIN_SRC python -n :results output :post (shell-command-to-string > "notifier 'babel done'") > print "hello, world" > #+END_SRC > #+RESULTS: > The :post method does not seem to work for me. With: --8<---cut here---start->8--- #+BEGIN_SRC sh :results output :post (shell-command-to-string "popup.py babel done") sleep 10 echo DONE #+END_SRC --8<---cut here---end--->8--- (popup.py is my homemade notifier) I get the popup immediately and the results after 10 seconds. The org-babel-after-execute-hook method worked fine. Nick
Re: [O] babel completion notification
Hi Eric, On 2014-03-17 at 17:05, Eric Schulte wrote: > Ken Mankoff writes: > >> Until asynchronous babel exists, it would be nice to at least be >> notified when long-running tasks complete. Does anyone have advice >> how to set up a hook on babel completion so that growl or some >> other system notification alerts, perhaps only if the execution >> took more than x seconds? > > You can use the org-babel-after-execute-hook to run any action after a > code block finishes executing. Yes, and your reply makes me recall that :post works too, so I can call a shell command "notifier" (or Growl) like this: #+BEGIN_SRC python -n :results output :post (shell-command-to-string "notifier 'babel done'") print "hello, world" #+END_SRC #+RESULTS: Thanks, -k.
Re: [O] babel completion notification
Hi Ken, Ken Mankoff writes: > I see from old emails to this list that asynchronous babel does not > exist and is non-trivial to implement. Yes, at least my initial attempts to implement this did not succeed (see line 100 of ob-comint.el), and I haven't had the time to revisit the issue. In actuality it may not be that much work to provide for asynchronous evaluation (at least in most cases). > Until asynchronous babel exists, it would be nice to at least be > notified when long-running tasks complete. Does anyone have advice how > to set up a hook on babel completion so that growl or some other > system notification alerts, perhaps only if the execution took more > than x seconds? > You can use the org-babel-after-execute-hook to run any action after a code block finishes executing. Best, > > Thanks, > > -k. > -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D
[O] babel completion notification
I see from old emails to this list that asynchronous babel does not exist and is non-trivial to implement. Until asynchronous babel exists, it would be nice to at least be notified when long-running tasks complete. Does anyone have advice how to set up a hook on babel completion so that growl or some other system notification alerts, perhaps only if the execution took more than x seconds? Thanks, -k.