From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [Babel] Handling of errors when using Ledger Date: Thu, 23 Dec 2010 10:28:51 +0000 Message-ID: References: <877hhudxor.fsf@mundaneum.com> <87sk0inmys.fsf@stats.ox.ac.uk> <807hhnfaix.fsf@mundaneum.com> <87mxqiv7q3.wl%ucecesf@ucl.ac.uk> <871v68eb5k.fsf@pinto.chemeng.ucl.ac.uk> <87vd3kxq69.fsf@gmail.com> <87bp5ccl7t.fsf@pinto.chemeng.ucl.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=40134 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PViQ5-0002Es-KB for emacs-orgmode@gnu.org; Thu, 23 Dec 2010 05:29:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PViQ3-0000xC-4S for emacs-orgmode@gnu.org; Thu, 23 Dec 2010 05:29:13 -0500 Received: from lo.gmane.org ([80.91.229.12]:45790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PViQ2-0000wO-Pb for emacs-orgmode@gnu.org; Thu, 23 Dec 2010 05:29:11 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PViPz-0002vA-5z for emacs-orgmode@gnu.org; Thu, 23 Dec 2010 11:29:07 +0100 Received: from cpc14-cmbg15-2-0-cust848.5-4.cable.virginmedia.com ([82.26.3.81]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 23 Dec 2010 11:29:07 +0100 Received: from dandavison7 by cpc14-cmbg15-2-0-cust848.5-4.cable.virginmedia.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 23 Dec 2010 11:29:07 +0100 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: emacs-orgmode@gnu.org Eric S Fraga writes: > Dan Davison writes: > >> Eric S Fraga writes: >> >>> Dan writes: >>> >>> [...] >>> >>>> This patch should make ob-ledger use the common org-babel error mechanism. It is >>>> in branch ledger of the main repo. However, I'm not yet a ledger user. Could >>>> someone test it? >>> >>> Unfortunately, it doesn't work at all [1] for a very simple reason: you >>> have removed the -f option which specifies the file that ledger should >>> read. >> >> Hi Eric, >> >> Yes, ob-eval passes the src block body to the interpreter on standard >> input. I assumed that ledger would be able to read its transaction data >> from standard input. Is that not the case? What about with "--file -" >> or "-f -"? > >> [...] > >> If ledger can't read the src blocks body from stdin (and if it can't, I >> expect there's a good reason why not), then maybe this is a motivation >> for changing ob-eval so that the block body is read from file. > > Indeed, ledger cannot read from standard input. Hi Eric, I've asked on the ledger list and the 3.0 (and perhaps some older) versions of ledger do support -f - to read from stdin. Could you try this version of the patch? Thanks, Dan diff --git a/lisp/ob-ledger.el b/lisp/ob-ledger.el index a02eb6f..ef0f52e 100644 --- a/lisp/ob-ledger.el +++ b/lisp/ob-ledger.el @@ -43,24 +43,15 @@ '((:results . "output") (:cmdline . "bal")) "Default arguments to use when evaluating a ledger source block.") +(defvar org-babel-ledger-command "ledger" + "Command to invoke ledger") + (defun org-babel-execute:ledger (body params) "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-"))) - (with-temp-file in-file (insert body)) - (message (concat "ledger" - " -f " (org-babel-process-file-name in-file) - " " cmdline)) - (with-output-to-string - (shell-command (concat "ledger" - " -f " (org-babel-process-file-name in-file) - " " cmdline - " > " (org-babel-process-file-name out-file)))) - (with-temp-buffer (insert-file-contents out-file) (buffer-string)))) + (org-babel-eval + (concat org-babel-ledger-command " -f - " (cdr (assoc :cmdline params))) + body)) > From the man page: > > ,---- > | All commands require a Ledger data file which can be specified with -f > | filename or via the LEDGER_FILE environment variable. > `---- > > and later: > > ,---- > | -f, --file FILE > | > | Reads FILE as a Ledger file. This option may be specified multiple > | times. FILE may also be a list of file names separated by colons. > | Typically, the environment variable LEDGER_FILE is set rather than > | using this command-line option. > `---- > > Using an environment variable is not a good or viable solution for > babel, as far as I can figure, and there does not seem to be any concept > of "-" for standard input in lieu of a file. I cannot see any reason > for this and, to be honest, I find it annoying [1] as a long time Unix user > wishing to join tools together with pipes etc. But maybe John Wiegley > had his reasons for taking this decision. Maybe he can comment on > this... I think he reads this list? > >> Incidentally, I have for a long time wondered whether we should permit >> src blocks to read *input data* from standard input. This would require >> altering ob-eval such that the src block body is read from file. Then we >> could do things like >> >> #+source: output-some-text >> #+begin_src sh :results output >> # print stuff >> #+end_src >> #+begin_src perl :stdin output-some-text >> while ( <> ) { >> # process the text >> } >> #+end_src > > This could be a solution. In thinking about all of my babel uses, this > would have no impact on me but others may have different opinions? It > would seem to be a safer route in any case? > > Thanks, > eric > > > Footnotes: > [1] but not annoying enough to stop using ledger, of course, as it's a > brilliant tool otherwise!