From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Re: [babel] ledger tutorial on Worg Date: Wed, 08 Sep 2010 16:46:57 -0600 Message-ID: <87hbhzj1ae.fsf@gmail.com> References: <871v9lm0s3.wl%ucecesf@ucl.ac.uk> <4296BE2D-051E-47E8-8AA7-24582082DD0F@gmail.com> <87zkw8vzxw.fsf@gmail.com> <87aao1bt8w.fsf@mundaneum.com> <87mxs1co0f.wl%ucecesf@ucl.ac.uk> <87mxs071us.fsf@mundaneum.com> <87tym8b3e0.fsf@gmail.com> <87mxryv9ah.fsf@mundaneum.com> <8762ymo6hf.fsf@gmail.com> <877hizvrui.fsf@mundaneum.com> <87wrqxw3ou.fsf@gmail.com> <871v94wspn.fsf@mundaneum.com> <87r5h4xgt3.fsf@gmail.com> <87bp87kj7b.fsf@mundaneum.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=59941 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OtTVj-00063N-Du for emacs-orgmode@gnu.org; Wed, 08 Sep 2010 18:53:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OtTVh-0002BO-Oy for emacs-orgmode@gnu.org; Wed, 08 Sep 2010 18:52:59 -0400 Received: from mail-iw0-f169.google.com ([209.85.214.169]:58695) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OtTVh-0002BH-I1 for emacs-orgmode@gnu.org; Wed, 08 Sep 2010 18:52:57 -0400 Received: by iwn33 with SMTP id 33so620589iwn.0 for ; Wed, 08 Sep 2010 15:52:57 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?utf-8?Q?S=C3=A9bastien?= Vauban Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable S=C3=A9bastien Vauban writes: > Hi Eric, > > "Eric Schulte" wrote: >> S=C3=A9bastien Vauban writes: >>> "Eric Schulte" wrote: >>>> S=C3=A9bastien Vauban writes: >>>>> "Eric Schulte" wrote: >>>>>> S=C3=A9bastien Vauban writes: >>>>>>> >>>>>>> 2. When the evaluation produces no output, but had well produced ou= tput >>>>>>> before, shouldn't Babel have to delete the previously written >>>>>>> results in the Org buffer? >>>>>> >>>>>> This is a good point. Currently Babel just quits if it receives a nil >>>>>> result, but I think you're right that we should replace existing res= ults >>>>>> when a nil result has been returned. I'll add this as PROPOSED to the >>>>>> babel task list. >>>>> >>>>> I consider this kind of mandatory, for the sake of coherency, and to >>>>> really make use of Org-babel every time I want to run some shell comm= ands >>>>> (and change them, eventually getting no results then). >>>> >>>> I've just pushed up a change that implements this behavior. >>> >>> From my point of view, it does not work yet. Take this example: >>> >>> With `:cmdline reg unknown', it produced the line with -21.91 EUR. Corr= ect. >>> >>> Now, if I write `:cmdline "reg" unknown', I expect no output from Ledge= r, >>> and thus the results block to be removed. That's not the case. >> >> If ledger throws an exception then the result probably will not be repla= ced, >> however if ledger does return an empty result, then the existing result = will >> be removed. > > What do you mean by ledger throwing an exception? Having a return code > different from 0? > Yes, that's exactly what I mean. > > For me, the result block should be removed in both cases: > - "exception" of ledger > - empty result of ledger > > Or, if not, then (even better): instead of simply removing the result blo= ck, > replace it with a sort of error message, saying that ledger's execution f= ailed > and returned XXX as exit code. > This is what we used to do (insert the error output into the buffer as results), however we now treat error messages and STDOUT differently, and Babel /should/ notify you of error output and then abort the evaluation chain. > > Whatever the solution, we have to clearly be aware that the previous > results are now wrong, and that the new result is a failure or empty. > Agreed, this notification should be done through a pop-up buffer of the error output (however the previous results are retained because at least when they were generated they were not an error). Also, returning the error results could cause problems in the case of chained code blocks. I don't have a local ledger install, and I didn't implement the Babel ledger support, but I've made some changes to ob-ledger so that it now uses the general Babel external evaluation tools (which should raise errors as I've mentioned above). Could you give this patch (attached) a try and let me know if it improves the behavior you're seeing? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=ledger-notices-errors.patch diff --git a/lisp/ob-ledger.el b/lisp/ob-ledger.el index edd803f..ddaa93a 100644 --- a/lisp/ob-ledger.el +++ b/lisp/ob-ledger.el @@ -38,6 +38,7 @@ ;;; Code: (require 'ob) +(require 'ob-eval) (require 'org) (defvar org-babel-default-header-args:ledger @@ -48,15 +49,13 @@ "Execute a block of Ledger entries with org-babel. This function is called by `org-babel-execute-src-block'." (message "executing Ledger source code block") - (let ((result-params (split-string (or (cdr (assoc :results params)) ""))) - (cmdline (cdr (assoc :cmdline params))) - (in-file (org-babel-temp-file "ledger-")) - (out-file (org-babel-temp-file "ledger-output-")) - ) + (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) + (cmdline (cdr (assoc :cmdline params))) + (in-file (org-babel-temp-file "ledger-")) + (out-file (org-babel-temp-file "ledger-output-")) + (cmd (concat "ledger -f " in-file " " cmdline " > " out-file))) (with-temp-file in-file (insert body)) - (message (concat "ledger -f " in-file " " cmdline)) - (with-output-to-string - (shell-command (concat "ledger -f " in-file " " cmdline " > " out-file))) + (message cmd) (org-babel-eval cmd "") (with-temp-buffer (insert-file-contents out-file) (buffer-string)))) (defun org-babel-prep-session:ledger (session params) --=-=-= > > >>> Other peculiarity, if I write `:cmdline reeg unknown', I get an >>> exception: >> >> Ah, thanks for pointing this out, it seems I introduced an error with my >> previous change. I've just pushed up a fix for this issue. > > Thanks. But right now, I don't get anything back from the following (same as > for thread about isodoc letters): > After updating Org-mode are you running make clean && make (and maybe make install) to clear out the old compiled elisp files? Best -- Eric > > #+srcname: ledger-journal > #+begin_src ledger > 2008/01/03 * (SCORPIOS ) SEB VAUBAN > Assets:Bank:Checking:799997400530 550.00 EUR > Assets:Bank:Transferred > > 2008/01/01 * ( ) UNKNOWN-PAYEE > Assets:Bank:Checking:799997400530 21.91 EUR > Expenses:Unknown > #+end_src > > #+srcname: ledger-registry > #+begin_src ledger :cmdline reg unknown :noweb yes :session > <> > #+end_src > > In the *Messages* buffer, I get: > > Checking for library `filladapt'... Found > Fontifying scorpios.org... (regexps.............................................) > Checking for library `filladapt'... Found > Fontifying scorpios.org... (regexps..............................................) > Checking for library `filladapt'... Found > Fontifying scorpios.org... (regexps...............................................) > Checking for library `filladapt'... Found > Checking for library `filladapt'... Found > Org-mode restarted > Local setup has been refreshed > > ... but no result block is added in my Org buffer. > > I'll carefully test all of this, as soon as I can re-execute Babel under > normal conditions. > > Thanks for your help. > > Best regards, > Seb --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--