From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?S=C3=A9bastien_Vauban?= Subject: Re: Org-Babel and Ledger Date: Fri, 13 Aug 2010 11:23:34 +0200 Message-ID: <87zkwqzx0p.fsf@mundaneum.com> References: <87eiemsk0m.fsf@mundaneum.com> <87fwz2b634.fsf@pellet.net> <87tyng66ja.fsf@gmail.com> <87vd7gyrz6.fsf@mundaneum.com> <871va3v3qk.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: 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-mXXj517/zsQ@public.gmane.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org To: emacs-orgmode-mXXj517/zsQ@public.gmane.org Hi Eric, "Eric Schulte" wrote: > S=C3=A9bastien Vauban writes: >> >>>>> 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 >>> >>> (org-table-convert-region (point-min) (point-max)) >>> >>> 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 fie= lds >> (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. T= he > following works for me, on the case your provided although I suppose it m= ay > not work on all cases. > > #+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 E= UR | 166.70 EUR | > | 09-Sep-17 CHEQUE : 7691785 | Expenses:Unknown | 100.00 E= UR | 266.70 EUR | > | 09-Oct-16 REMISE CHEQUE N 8686318 001 105 | Expenses:Unknown | -525.00 = EUR | -258.30 EUR | > > Hope this helps -- Eric Of course, it does, Eric! I misunderstood the above DOCSTRING because, IMHO, it's not that clear: "When a number, use that many spaces as field separator" meant, for me, that if using the number 2 (as you do), it would consider a new field every 2 consecutive spaces, and leave me with a lot of empty fields... In fact, it should be written "consider any amount of whitespaces (above the given number) as a field separator" or something like that, if you understa= nd me right. I was blocked on the fact that every 2 spaces would be a new field separato= r, and not every string of 2 or more spaces... Thanks a lot (once again)!! Best regards, Seb --=20 S=C3=A9bastien 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