From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric S Fraga Subject: Re: Orgmode for budgeting/expense recording Date: Fri, 02 Oct 2009 14:21:35 +0100 Message-ID: <87d456q6cg.wl%ucecesf@ucl.ac.uk> References: <20091001174325.GM17702@thinkpad.adamsinfoserv.com> <87my4aqd45.wl%ucecesf@ucl.ac.uk> Reply-To: Eric S Fraga Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Fri_Oct__2_14:21:35_2009-1" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mti4v-0005t0-Ft for emacs-orgmode@gnu.org; Fri, 02 Oct 2009 09:21:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mti4q-0005o8-BU for emacs-orgmode@gnu.org; Fri, 02 Oct 2009 09:21:44 -0400 Received: from [199.232.76.173] (port=40332 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mti4p-0005o0-HS for emacs-orgmode@gnu.org; Fri, 02 Oct 2009 09:21:39 -0400 Received: from vscane-c.ucl.ac.uk ([144.82.108.43]:41751) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mti4p-00029T-4g for emacs-orgmode@gnu.org; Fri, 02 Oct 2009 09:21:39 -0400 In-Reply-To: <87my4aqd45.wl%ucecesf@ucl.ac.uk> 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 --Multipart_Fri_Oct__2_14:21:35_2009-1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable At Fri, 02 Oct 2009 11:55:22 +0100, Eric S Fraga wrote: > It would be interesting to see a org-babel interface to ledger... > what ledger is missing, in the context of emacs, is an easy way to see > the actual output of the ledger command (e.g. bal or reg) while > looking at the ledger file. okay, interesting enough that I've done a first attempt (good enough for what I need but probably incredibly clumsy elisp code as I'm really not an elisp programmer...). Attached is org-babel-ledger.el which works with this simple example ledger: --8<---------------cut here---------------start------------->8--- #+begin_src ledger :results output :cmdline -s bal 2009/09/30 salary account:bank =C2=A32000.00 income:salary 2009/10/01 rent payee:landlord =C2=A3 500.00 account:bank #+end_src ledger --8<---------------cut here---------------end--------------->8--- If you change "-s bal" to "reg" you get a register output, for instance. I have no idea what happens if you try some of the esoteric ledger commands but I only tend to use bal and reg with various arguments... Works on Debian linux with emacs 23 and most recent org and org-babel. The definitely clumsy code is in extracting the output of the ledger command so any input would be more than welcome! Oh, use by (require 'org-babel-ledger) as per the other languages... Thanks, eric --Multipart_Fri_Oct__2_14:21:35_2009-1 Content-Type: application/octet-stream; type=emacs-lisp Content-Disposition: attachment; filename="org-babel-ledger.el" Content-Transfer-Encoding: 7bit ;;; org-babel-ledger.el --- org-babel functions for ledger evaluation ;; Copyright (c) 2009 Eric S Fraga ;; based on code by ;; Copyright (C) 2009 Eric Schulte ;; Author: Eric Schulte ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; Version: 0.01 ;;; License: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; Org-Babel support for evaluating ledger entries. ;; ;; This differs from most standard languages in that ;; ;; 1) there is no such thing as a "session" in ledger ;; ;; 2) we are generally only going to return output from the leger program ;; ;; 3) we are adding the "cmdline" header argument ;; ;; 4) there are no variables ;;; Code: (require 'org-babel) (org-babel-add-interpreter "ledger") (add-to-list 'org-babel-tangle-langs '("ledger" "ledger")) (defvar org-babel-default-header-args:ledger '((:results . "output") (:cmdline . "bal")) "Default arguments to use when evaluating a ledger source block.") (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 (make-temp-file "org-babel-ledger")) (out-file (make-temp-file "org-babel-ledger-output")) ) (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))) (with-temp-buffer (insert-file-contents out-file) (buffer-string)) )) (defun org-babel-prep-session:ledger (session params) (error "Ledger does not support sessions")) (provide 'org-babel-ledger) ;;; org-babel-ledger.el ends here --Multipart_Fri_Oct__2_14:21:35_2009-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --Multipart_Fri_Oct__2_14:21:35_2009-1--