On Thu, 22 Jul 2010 10:06:30 -0700, "Eric Schulte" <schulte.e...@gmail.com> wrote: > > Eric S Fraga <ucec...@ucl.ac.uk> writes: > > > On Thu, 22 Jul 2010 01:26:29 -0500, Russell Adams > > <rlad...@adamsinfoserv.com> wrote: > >> > >> On Thu, Jul 22, 2010 at 01:20:58AM -0500, Marcelo de Moraes Serpa wrote: > >> > Hey list, > >> > > >> > I was wondering if anyone out there manages his personal accounting > >> > with org. I never really managed my personal finances, but I think > >> > it's about time to know where my money comes from and where it is > >> > going (and where the leaks are :P). I would use something like > >> > lessaccounting.com, but I would rather integrate it into my > >> > orgmode-based PIM. Any ideas? > >> > >> I use John Wiegley's Ledger (of Remember fame), which is a CLI tool > >> that does reporting against plain text files. > >> > >> I do my expense reporting and business accounting in it. Very flexible > >> and because it is text based, I can use version control and emacs. > > > > and, with org-babel, you can place your ledger entries in an org > > file... I have a simple ob-ledger implementation which doesn't do > > tangling yet (as I don't yet know how to provide this level of > > support) but it does work for single blocks of ledger entries. > > Tangling does not require *any* language specific support. Since the > integration of Babel into Org-mode any type of code block should tangle > just fine. For example the following minimal org file tangles a code > block of the fictional /schulte/ language to a file "eric.sh"
Yes, thanks, I figured this out on the way home (the advantage of a long commute is time to play!) before I got your email. The tangling works like a charm. What's even better is that ability to specify the tangle property as an org property which only affects code blocks within a certain heading! Fantastic. > It does look like there is fertile ground for Babel<->Ledger > integration. Attached is my simple, linux only, org-babel solution and an example org file which uses it. Note, I've still not had a chance to look at the ob-template in Worg so I'm sure my ob-ledger file could be improved... Thanks again all those who have contributed to babel! eric
;;; ob-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 'ob-ledger) ;;; org-babel-ledger.el ends here
* ledger test *** income and expenses :PROPERTIES: :tangle: account.ledger :END: The property for this heading specifies where the tangled output of the ledger code blocks in what follows should end up. ***** income The first set of entries relates to income, either monthly pay or interest, all typically going into my bank account. #+begin_src ledger 2010/01/01 * Starting balance assets:bank:savings £1300.00 income:starting balances 2010/07/22 * Got paid assets:bank:chequing £1000.00 income:salary 2010/07/31 * Interest on bank savings assets:bank:savings £3.53 income:interest 2010/07/31 * Transfer savings assets:bank:savings £250.00 assets:bank:chequing 2010/08/01 got paid again assets:bank:chequing £1000.00 income:salary #+end_src ***** expenses The following entries relate to personal expenses (rent and food). #+begin_src ledger 2010/07/23 Rent expenses:rent £500.00 assets:bank:chequing 2010/07/24 Food expenses:food £150.00 assets:bank:chequing #+end_src *** Financial summary Assuming you have tangled the ledger entries (=C-c C-v t=), you can now perform all kinds of calculations ***** overall summary The overall balance of your account and expenditure with a breakdown according to category: #+begin_src ledger :cmdline -s bal :results value !include /home/ucecesf/s/test/account.ledger #+end_src #+results: #+begin_example £2653.53 assets:bank £1100.00 chequing £1553.53 savings £650.00 expenses £150.00 food £500.00 rent £-3303.53 income £-3.53 interest £-2000.00 salary £-1300.00 starting balances #+end_example ***** monthly register You can also generate a monthly register by executing the following: #+begin_src ledger :cmdline -M -w reg !include /home/ucecesf/s/test/account.ledger #+end_src #+results: #+begin_example 2010/01/01 - 2010/01/31 assets:bank:savings £1300.00 £1300.00 income:starting balances £-1300.00 0 2010/07/01 - 2010/07/31 assets:bank:chequing £100.00 £100.00 assets:bank:savings £253.53 £353.53 expenses:food £150.00 £503.53 expenses:rent £500.00 £1003.53 income:interest £-3.53 £1000.00 income:salary £-1000.00 0 2010/08/01 - 2010/08/01 assets:bank:chequing £1000.00 £1000.00 income:salary £-1000.00 0 #+end_example
-- Eric S Fraga GnuPG: 8F5C 279D 3907 E14A 5C29 570D C891 93D8 FFFC F67D
_______________________________________________ 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