From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Re: Org-Babel and Ledger Date: Thu, 12 Aug 2010 16:57:23 -0600 Message-ID: <871va3v3qk.fsf@gmail.com> References: <87eiemsk0m.fsf@mundaneum.com> <87fwz2b634.fsf@pellet.net> <87tyng66ja.fsf@gmail.com> <87vd7gyrz6.fsf@mundaneum.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=33097 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OjgiT-0002DO-Jg for emacs-orgmode@gnu.org; Thu, 12 Aug 2010 18:57:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OjgiR-0008JN-Ud for emacs-orgmode@gnu.org; Thu, 12 Aug 2010 18:57:41 -0400 Received: from mail-yw0-f41.google.com ([209.85.213.41]:49788) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OjgiR-0008J7-QS for emacs-orgmode@gnu.org; Thu, 12 Aug 2010 18:57:39 -0400 Received: by ywg8 with SMTP id 8so844474ywg.0 for ; Thu, 12 Aug 2010 15:57:38 -0700 (PDT) In-Reply-To: <87vd7gyrz6.fsf@mundaneum.com> (=?utf-8?Q?=22S=C3=A9bastien?= Vauban"'s message of "Thu, 12 Aug 2010 13:45:33 +0200") 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 Hi Seb, S=C3=A9bastien Vauban writes: > Hi Eric(s), > >>>> As you can see, the tables are completely wrongly made, because they're >>>> based on spaces ("=C3=A0 la Awk") and not on fixed position of fields = ("=C3=A0 la >>>> Cut"). >>>> >>>> What can I do about this? >>>> >>>> - Post-process every ledger command with some awk or cut command that = will >>>> do whatever is needed >>>> >>>> - Exploit the CSV export format (never tried, don't have Ledger 3 >>>> installed yet -- and I'm also using hledger...) >>> >>> Couldn't you use ledger's format strings for fine-tuned control of the >>> command output? I don't know how you're snarfing the output, but it see= ms >>> like you could using formatting to produce something that already looks >>> very much like an org table, or perhaps CSV. > > That anser is not really applicable in my case, as I would like to use at > least `ledger' and `hledger' for different reports, and they don't share = the > same exporting capabilities. > > Plus the problem would come back for any other command-line tool... > > >> Many languages import tabular contents into elisp tables which are then >> inserted into Org-mode buffers as Org-formatted tables. This should be >> possible by replacing the call to `buffer-string' at the end of the >> `org-babel-execute:ledger' function with something analogous to the >> following (copied from ob-sqlite.el). >> >> (if (or (member "scalar" result-params) >> (member "html" result-params) >> (member "code" result-params) >> (equal (point-min) (point-max))) >> (buffer-string) >> (org-table-convert-region (point-min) (point-max)) > > That's, then, the interesting line for me... > > >> (org-babel-sqlite-table-or-scalar >> (org-babel-sqlite-offset-colnames >> (org-table-to-lisp) headers-p))) >> >> I would recommend this approach over shell-script post-processing. > > That seems not to work for me, as input data is, for example: > > 09-Aug-21 CHEQUE : 9953055 Expenses:Unknown = 166.70 EUR 166.70 EUR > 09-Sep-17 CHEQUE : 7691785 Expenses:Unknown = 100.00 EUR 266.70 EUR > 09-Oct-16 REMISE CHEQUE N 8686318 001 105 Expenses:Unknown = -525.00 EUR -258.30 EUR > > and as =3Dorg-table-convert-region=3D can't convert fixed positioned fiel= ds > (when SPC are used instead of TAB): > > (org-table-convert-region beg0 end0 &optional separator) > > Convert region to a table. > The region goes from beg0 to end0, but these borders will be moved > slightly, to make sure a beginning of line in the first line is included. > > separator specifies the field separator in the lines. It can have the > following values: > > '(4) Use the comma as a field separator > '(16) Use a TAB as field separator > integer When a number, use that many spaces as field separator > nil When nil, the command tries to be smart and figure out the > separator in the following way: > - when each line contains a TAB, assume TAB-separated material > - when each line contains a comma, assume CSV material > - else, assume one or more SPACE characters as separator. > > Should that function be smarter, or do I still need pre-processing, then? > Neither, notice that if you pass an integer as the third argument to org-table-convert-region it will parse on that many consecutive spaces. The following works for me, on the case your provided although I suppose it may not work on all cases. --8<---------------cut here---------------start------------->8--- #+results: ledger-output #+begin_example=20 09-Aug-21 CHEQUE : 9953055 Expenses:Unknown = 166.70 EUR 166.70 EUR 09-Sep-17 CHEQUE : 7691785 Expenses:Unknown = 100.00 EUR 266.70 EUR 09-Oct-16 REMISE CHEQUE N 8686318 001 105 Expenses:Unknown = -525.00 EUR -258.30 EUR #+end_example #+begin_src emacs-lisp :var ledger=3Dledger-output (with-temp-buffer (insert ledger) (message ledger) (org-table-convert-region (point-min) (point-max) 2) (org-table-to-lisp)) #+end_src #+results: | 09-Aug-21 CHEQUE : 9953055 | Expenses:Unknown | 166.70 EUR= | 166.70 EUR | | 09-Sep-17 CHEQUE : 7691785 | Expenses:Unknown | 100.00 EUR= | 266.70 EUR | | 09-Oct-16 REMISE CHEQUE N 8686318 001 105 | Expenses:Unknown | -525.00 EU= R | -258.30 EUR | --8<---------------cut here---------------end--------------->8--- Hope this helps -- Eric > > Thanks for your comments... > > Best regards, > Seb