 
 ;; Emacs Lisp Archive Entry
 ;; Filename: ledger.el
-;; Version: 1.1
+;; Version: 1.2
 ;; Date: Thu 02-Apr-2004
 ;; Keywords: data
 ;; Author: John Wiegley (johnw AT gnu DOT org)

    (define-key map [(control ?c) (control ?y)] 'ledger-set-year)
    (define-key map [(control ?c) (control ?m)] 'ledger-set-month)
    (define-key map [(control ?c) (control ?c)] 'ledger-toggle-current)
    (define-key map [(control ?c) (control ?p)] 'ledger-print-result)
    (define-key map [(control ?c) (control ?r)] 'ledger-reconcile)))

(defun ledger-parse-entries (account &optional all-p)
  (let (total entries)
    (ledger-iterate-entries
     (function
      (lambda (start date mark desc)
	(when (or all-p (not mark))
	  (forward-line)
	  (setq total 0.0)
	  (while (looking-at
		  (concat "\\s-+\\([A-Za-z_].+?\\)\\(\\s-*$\\|  \\s-*"
			  "\\([^0-9]+\\)\\s-*\\([0-9,.]+\\)\\)?"
			  "\\(\\s-+;.+\\)?$"))
	    (let ((acct (match-string 1))
		  (amt (match-string 4)))
	      (when amt
		(while (string-match "," amt)
		  (setq amt (replace-match "" nil nil amt)))
		(setq amt (string-to-number amt)
		      total (+ total amt)))
	      (if (string= account acct)
		  (setq entries
			(cons (list (copy-marker start)
				    mark date desc (or amt total))
			      entries)
			all-p t)))
	    (forward-line))))))
    entries))

(defvar ledger-reconcile-text "Reconcile")
(defvar ledger-reconcile-mode-abbrev-table)

(define-derived-mode ledger-reconcile-mode text-mode 'ledger-reconcile-text
  "A mode for reconciling ledger entries."
  (let ((map (make-sparse-keymap)))
    (define-key map [? ] 'ledger-reconcile-toggle)
    (define-key map [?q]
      (function

	  (setq clear t))))
    clear))

(defvar ledger-mode-abbrev-table)

(define-derived-mode ledger-mode text-mode "Ledger"
