emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric S Fraga <ucecesf@ucl.ac.uk>
To: emacs-orgmode@gnu.org
Subject: Re: Orgmode for budgeting/expense recording
Date: Fri, 02 Oct 2009 14:21:35 +0100	[thread overview]
Message-ID: <87d456q6cg.wl%ucecesf@ucl.ac.uk> (raw)
In-Reply-To: <87my4aqd45.wl%ucecesf@ucl.ac.uk>

[-- Attachment #1: Type: text/plain, Size: 1396 bytes --]

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       £2000.00
2009/10/01 rent
  payee:landlord     £ 500.00
#+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

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...


[-- Attachment #2: org-babel-ledger.el --]
[-- Type: application/octet-stream, Size: 2551 bytes --]

;;; 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
;; 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

[-- Attachment #3: Type: text/plain, Size: 204 bytes --]

Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.

  reply	other threads:[~2009-10-02 13:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-01 16:13 Orgmode for budgeting/expense recording Raffi R
2009-10-01 17:43 ` Russell Adams
2009-10-01 21:36   ` Raffi R
2009-10-01 22:07     ` Matt Lundin
2009-10-02 10:55   ` Eric S Fraga
2009-10-02 13:21     ` Eric S Fraga [this message]
2009-10-02 14:08     ` Russell Adams
2009-10-02 14:25       ` Eric S Fraga
2009-10-02 18:12         ` Russell Adams
2009-10-02 14:52     ` Matt Lundin
2009-10-02 15:01       ` Eric S Fraga
2009-10-02 15:30         ` Matthew Lundin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d456q6cg.wl%ucecesf@ucl.ac.uk \
    --to=ucecesf@ucl.ac.uk \
    --cc=e.fraga@ucl.ac.uk \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).