summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ldg-complete.el71
-rw-r--r--lisp/ldg-exec.el52
-rw-r--r--lisp/ldg-fonts.el88
-rw-r--r--lisp/ldg-mode.el224
-rw-r--r--lisp/ldg-new.el20
-rw-r--r--lisp/ldg-occur.el252
-rw-r--r--lisp/ldg-post.el97
-rw-r--r--lisp/ldg-reconcile.el250
-rw-r--r--lisp/ldg-regex.el147
-rw-r--r--lisp/ldg-register.el35
-rw-r--r--lisp/ldg-report.el140
-rw-r--r--lisp/ldg-sort.el61
-rw-r--r--lisp/ldg-state.el81
-rw-r--r--lisp/ldg-test.el29
-rw-r--r--lisp/ldg-texi.el39
-rw-r--r--lisp/ldg-xact.el39
16 files changed, 1297 insertions, 328 deletions
diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el
index 7b4b0471..996df558 100644
--- a/lisp/ldg-complete.el
+++ b/lisp/ldg-complete.el
@@ -1,3 +1,24 @@
+;;; ldg-complete.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
;;(require 'esh-util)
;;(require 'esh-arg)
(require 'pcomplete)
@@ -68,9 +89,9 @@
(let ((entry (assoc (car elements) root)))
(if entry
(setq root (cdr entry))
- (setq entry (cons (car elements) (list t)))
- (nconc root (list entry))
- (setq root (cdr entry))))
+ (setq entry (cons (car elements) (list t)))
+ (nconc root (list entry))
+ (setq root (cdr entry))))
(setq elements (cdr elements)))))))))
(defun ledger-accounts ()
@@ -85,18 +106,18 @@
(setq prefix (concat prefix (and prefix ":")
(car elements))
root (cdr entry))
- (setq root nil elements nil)))
+ (setq root nil elements nil)))
(setq elements (cdr elements)))
(and root
(sort
(mapcar (function
(lambda (x)
- (let ((term (if prefix
- (concat prefix ":" (car x))
- (car x))))
- (if (> (length (cdr x)) 1)
- (concat term ":")
- term))))
+ (let ((term (if prefix
+ (concat prefix ":" (car x))
+ (car x))))
+ (if (> (length (cdr x)) 1)
+ (concat term ":")
+ term))))
(cdr root))
'string-lessp))))
@@ -108,21 +129,21 @@
(ledger-thing-at-point)) 'entry)
(if (null current-prefix-arg)
(ledger-entries) ; this completes against entry names
- (progn
- (let ((text (buffer-substring (line-beginning-position)
- (line-end-position))))
- (delete-region (line-beginning-position)
- (line-end-position))
- (condition-case err
- (ledger-add-entry text t)
- ((error)
- (insert text))))
- (forward-line)
- (goto-char (line-end-position))
- (search-backward ";" (line-beginning-position) t)
- (skip-chars-backward " \t0123456789.,")
- (throw 'pcompleted t)))
- (ledger-accounts)))))
+ (progn
+ (let ((text (buffer-substring (line-beginning-position)
+ (line-end-position))))
+ (delete-region (line-beginning-position)
+ (line-end-position))
+ (condition-case err
+ (ledger-add-entry text t)
+ ((error)
+ (insert text))))
+ (forward-line)
+ (goto-char (line-end-position))
+ (search-backward ";" (line-beginning-position) t)
+ (skip-chars-backward " \t0123456789.,")
+ (throw 'pcompleted t)))
+ (ledger-accounts)))))
(defun ledger-fully-complete-entry ()
"Do appropriate completion for the thing at point"
diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el
index bf3565b4..e9cefd20 100644
--- a/lisp/ldg-exec.el
+++ b/lisp/ldg-exec.el
@@ -1,3 +1,30 @@
+;;; ldg-exec.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+(defconst ledger-version-needed "3.0.0"
+ "The version of ledger executable needed for interactive features")
+
+(defvar ledger-works nil
+ "Flag showing whether the ledger binary can support ledger-mode interactive features")
+
(defgroup ledger-exec nil
"Interface to the Ledger command-line accounting program."
:group 'ledger)
@@ -31,4 +58,29 @@
(read (current-buffer))
(kill-buffer (current-buffer)))))
+(defun ledger-version-greater-p (needed)
+ "verify the ledger binary is usable for ledger-mode"
+ (let ((buffer ledger-buf)
+ (version-strings '())
+ (version-number))
+ (with-temp-buffer
+ (ledger-exec-ledger buffer (current-buffer) "--version")
+ (goto-char (point-min))
+ (delete-horizontal-space)
+ (setq version-strings (split-string
+ (buffer-substring-no-properties (point)
+ (+ (point) 12))))
+ (if (and (string-match (regexp-quote "Ledger") (car version-strings))
+ (or (string= needed (car (cdr version-strings)))
+ (string< needed (car (cdr version-strings)))))
+ t
+ nil))))
+
+(defun ledger-check-version ()
+ (interactive)
+ (setq ledger-works (ledger-version-greater-p ledger-version-needed))
+ (if ledger-works
+ (message "Good Ledger Version")
+ (message "Bad Ledger Version")))
+
(provide 'ldg-exec)
diff --git a/lisp/ldg-fonts.el b/lisp/ldg-fonts.el
new file mode 100644
index 00000000..6032e361
--- /dev/null
+++ b/lisp/ldg-fonts.el
@@ -0,0 +1,88 @@
+;;; ldg-fonts.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+
+(defgroup ledger-faces nil "Ledger mode highlighting" :group 'ledger)
+(defface ledger-font-uncleared-face
+ `((t :foreground "green" :weight bold ))
+ "Default face for Ledger"
+ :group 'ledger-faces)
+
+(defface ledger-font-cleared-face
+ `((t :foreground "grey70" :weight normal ))
+ "Default face for cleared (*) transactions"
+ :group 'ledger-faces)
+
+(defface ledger-font-pending-face
+ `((t :foreground "yellow" :weight normal ))
+ "Default face for pending (!) transactions"
+ :group 'ledger-faces)
+
+(defface ledger-font-other-face
+ `((t :foreground "yellow" ))
+ "Default face for other transactions"
+ :group 'ledger-faces)
+
+(defface ledger-font-posting-account-face
+ `((t :foreground "lightblue" ))
+ "Face for Ledger accounts"
+ :group 'ledger-faces)
+
+(defface ledger-font-posting-amount-face
+ `((t :foreground "yellow" ))
+ "Face for Ledger amounts"
+ :group 'ledger-faces)
+
+(defface ledger-font-comment-face
+ `((t :foreground "orange" ))
+ "Face for Ledger comments"
+ :group 'ledger-faces)
+
+(defface ledger-font-reconciler-uncleared-face
+ `((t :foreground "green" :weight normal ))
+ "Default face for uncleared transactions in the reconcile window"
+ :group 'ledger-faces)
+
+(defface ledger-font-reconciler-cleared-face
+ `((t :foreground "grey70" :weight normal ))
+ "Default face for cleared (*) transactions in the reconcile window"
+ :group 'ledger-faces)
+
+(defface ledger-font-reconciler-pending-face
+ `((t :foreground "yellow" :weight normal ))
+ "Default face for pending (!) transactions in the reconcile window"
+ :group 'ledger-faces)
+
+
+(defvar ledger-font-lock-keywords
+ '(("^[0-9]+[-/.=][-/.=0-9]+\\s-\\!\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)" 2 'ledger-font-pending-face)
+ ("^[0-9]+[-/.=][-/.=0-9]+\\s-\\*\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)" 2 'ledger-font-cleared-face)
+ ("^[0-9]+[-/.=][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)" 2 'ledger-font-uncleared-face)
+ ("^\\s-+\\([*]\\s-*\\)?\\(\\([[(]\\)?[^*:
+ ]+?:\\([^]);
+ ]\\|\\s-\\)+?\\([])]\\)?\\)\\( \\| \\|$\\)"
+ 2 'ledger-font-posting-account-face) ; works
+ ("\\( \\| \\|^\\)\\(;.*\\)" 2 'ledger-font-comment-face) ; works
+ ("^\\([~=].+\\)" 1 ledger-font-other-face)
+ ("^\\([A-Za-z]+ .+\\)" 1 ledger-font-other-face))
+ "Expressions to highlight in Ledger mode.")
+
+(provide 'ldg-fonts) \ No newline at end of file
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el
index 4d13d7d2..f71bb58e 100644
--- a/lisp/ldg-mode.el
+++ b/lisp/ldg-mode.el
@@ -1,57 +1,119 @@
+;;; ldg-mode.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+
+(defsubst ledger-current-year ()
+ (format-time-string "%Y"))
+(defsubst ledger-current-month ()
+ (format-time-string "%m"))
+
+(defvar ledger-year (ledger-current-year)
+ "Start a ledger session with the current year, but make it
+customizable to ease retro-entry.")
+(defvar ledger-month (ledger-current-month)
+ "Start a ledger session with the current month, but make it
+customizable to ease retro-entry.")
+
+
(defcustom ledger-default-acct-transaction-indent " "
"Default indentation for account transactions in an entry."
:type 'string
:group 'ledger)
-(defvar bold 'bold)
-(defvar ledger-font-lock-keywords
- '(("\\( \\| \\|^\\)\\(;.*\\)" 2 font-lock-comment-face)
- ("^[0-9]+[-/.=][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)" 2 bold)
- ;;("^[0-9]+[-/.=][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)"
- ;; 2 font-lock-type-face)
- ("^\\s-+\\([*]\\s-*\\)?\\(\\([[(]\\)?[^*:
- ]+?:\\([^]);
- ]\\|\\s-\\)+?\\([])]\\)?\\)\\( \\| \\|$\\)"
- 2 font-lock-keyword-face)
- ("^\\([~=].+\\)" 1 font-lock-function-name-face)
- ("^\\([A-Za-z]+ .+\\)" 1 font-lock-function-name-face))
- "Expressions to highlight in Ledger mode.")
(defvar ledger-mode-abbrev-table)
;;;###autoload
(define-derived-mode ledger-mode text-mode "Ledger"
- "A mode for editing ledger data files."
- (ledger-post-setup)
-
- (set (make-local-variable 'comment-start) " ; ")
- (set (make-local-variable 'comment-end) "")
- (set (make-local-variable 'indent-tabs-mode) nil)
-
- (if (boundp 'font-lock-defaults)
- (set (make-local-variable 'font-lock-defaults)
- '(ledger-font-lock-keywords nil t)))
-
- (set (make-local-variable 'pcomplete-parse-arguments-function)
- 'ledger-parse-arguments)
- (set (make-local-variable 'pcomplete-command-completion-function)
- 'ledger-complete-at-point)
- (set (make-local-variable 'pcomplete-termination-string) "")
-
- (let ((map (current-local-map)))
- (define-key map [(control ?c) (control ?a)] 'ledger-add-entry)
- (define-key map [(control ?c) (control ?d)] 'ledger-delete-current-entry)
- (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 ?e)] 'ledger-toggle-current-entry)
- (define-key map [(control ?c) (control ?r)] 'ledger-reconcile)
- (define-key map [(control ?c) (control ?s)] 'ledger-sort)
- (define-key map [(control ?c) (control ?t)] 'ledger-test-run)
- (define-key map [tab] 'pcomplete)
- (define-key map [(control ?i)] 'pcomplete)
- (define-key map [(control ?c) tab] 'ledger-fully-complete-entry)
- (define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-entry)))
+ "A mode for editing ledger data files."
+ (ledger-check-version)
+ (ledger-post-setup)
+
+ (set (make-local-variable 'comment-start) " ; ")
+ (set (make-local-variable 'comment-end) "")
+ (set (make-local-variable 'indent-tabs-mode) nil)
+
+ (if (boundp 'font-lock-defaults)
+ (set (make-local-variable 'font-lock-defaults)
+ '(ledger-font-lock-keywords nil t)))
+
+ (set (make-local-variable 'pcomplete-parse-arguments-function)
+ 'ledger-parse-arguments)
+ (set (make-local-variable 'pcomplete-command-completion-function)
+ 'ledger-complete-at-point)
+ (set (make-local-variable 'pcomplete-termination-string) "")
+
+ (let ((map (current-local-map)))
+ (define-key map [(control ?c) (control ?a)] 'ledger-add-entry)
+ (define-key map [(control ?c) (control ?d)] 'ledger-delete-current-entry)
+ (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 ?e)] 'ledger-toggle-current-entry)
+ (define-key map [(control ?c) (control ?r)] 'ledger-reconcile)
+ (define-key map [(control ?c) (control ?s)] 'ledger-sort-region)
+ (define-key map [(control ?c) (control ?t)] 'ledger-test-run)
+ (define-key map [(control ?c) (control ?v)] 'ledger-post-edit-amount)
+ (define-key map [(control ?c) (control ?f)] 'ledger-occur)
+ (define-key map [tab] 'pcomplete)
+ (define-key map [(control ?i)] 'pcomplete)
+ (define-key map [(control ?c) tab] 'ledger-fully-complete-entry)
+ (define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-entry)
+ (define-key map [(control ?c) (control ?o) (control ?r)] 'ledger-report)
+ (define-key map [(control ?c) (control ?o) (control ?g)] 'ledger-report-goto)
+ (define-key map [(control ?c) (control ?o) (control ?a)] 'ledger-report-redo)
+ (define-key map [(control ?c) (control ?o) (control ?s)] 'ledger-report-save)
+ (define-key map [(control ?c) (control ?o) (control ?e)] 'ledger-report-edit)
+ (define-key map [(control ?c) (control ?o) (control ?k)] 'ledger-report-kill)
+
+ (define-key map [(meta ?p)] 'ledger-post-prev-xact)
+ (define-key map [(meta ?n)] 'ledger-post-next-xact)
+
+ (define-key map [menu-bar] (make-sparse-keymap "ldg-menu"))
+ (define-key map [menu-bar ldg-menu] (cons "Ledger" map))
+
+ (define-key map [report-kill] '(menu-item "Kill Report" ledger-report-kill :enable ledger-works))
+ (define-key map [report-edit] '(menu-item "Edit Report" ledger-report-edit :enable ledger-works))
+ (define-key map [report-save] '(menu-item "Save Report" ledger-report-save :enable ledger-works))
+ (define-key map [report-rrun] '(menu-item "Re-run Report" ledger-report-redo :enable ledger-works))
+ (define-key map [report-goto] '(menu-item "Goto Report" ledger-report-goto :enable ledger-works))
+ (define-key map [report-run] '(menu-item "Run Report" ledger-report :enable ledger-works))
+ (define-key map [sep5] '(menu-item "--"))
+ (define-key map [set-month] '(menu-item "Set Month" ledger-set-month :enable ledger-works))
+ (define-key map [set-year] '(menu-item "Set Year" ledger-set-year :enable ledger-works))
+ (define-key map [sep1] '("--"))
+ (define-key map [sort-buff] '(menu-item "Sort Buffer" ledger-sort-buffer))
+ (define-key map [sort-reg] '(menu-item "Sort Region" ledger-sort-region :enable mark-active))
+ (define-key map [sep2] '(menu-item "--"))
+ (define-key map [toggle-post] '(menu-item "Toggle Current Posting" ledger-toggle-current))
+ (define-key map [toggle-xact] '(menu-item "Toggle Current Transaction" ledger-toggle-current-entry))
+ (define-key map [sep4] '(menu-item "--"))
+ (define-key map [edit-amount] '(menu-item "Calc on Amount" ledger-post-edit-amount))
+ (define-key map [sep] '(menu-item "--"))
+ (define-key map [delete-xact] '(menu-item "Delete Entry" ledger-delete-current-entry))
+ (define-key map [add-xact] '(menu-item "Add Entry" ledger-add-entry :enable ledger-works))
+ (define-key map [sep3] '(menu-item "--"))
+ (define-key map [reconcile] '(menu-item "Reconcile Account" ledger-reconcile :enable ledger-works))
+ (define-key map [reconcile] '(menu-item "Hide Xacts" ledger-occur))
+ ))
(defun ledger-time-less-p (t1 t2)
"Say whether time value T1 is less than time value T2."
@@ -71,11 +133,53 @@ Return the difference in the format of a time value."
(ledger-iterate-entries
(function
(lambda (start date mark desc)
- (if (ledger-time-less-p moment date)
- (throw 'found t)))))))
+ (if (ledger-time-less-p moment date)
+ (throw 'found t)))))))
+
+(defun ledger-iterate-entries (callback)
+ (goto-char (point-min))
+ (let* ((now (current-time))
+ (current-year (nth 5 (decode-time now))))
+ (while (not (eobp))
+ (when (looking-at
+ (concat "\\(Y\\s-+\\([0-9]+\\)\\|"
+ "\\([0-9]\\{4\\}+\\)?[./]?"
+ "\\([0-9]+\\)[./]\\([0-9]+\\)\\s-+"
+ "\\(\\*\\s-+\\)?\\(.+\\)\\)"))
+ (let ((found (match-string 2)))
+ (if found
+ (setq current-year (string-to-number found))
+ (let ((start (match-beginning 0))
+ (year (match-string 3))
+ (month (string-to-number (match-string 4)))
+ (day (string-to-number (match-string 5)))
+ (mark (match-string 6))
+ (desc (match-string 7)))
+ (if (and year (> (length year) 0))
+ (setq year (string-to-number year)))
+ (funcall callback start
+ (encode-time 0 0 0 day month
+ (or year current-year))
+ mark desc)))))
+ (forward-line))))
+
+(defun ledger-set-year (newyear)
+ "Set ledger's idea of the current year to the prefix argument."
+ (interactive "p")
+ (if (= newyear 1)
+ (setq ledger-year (read-string "Year: " (ledger-current-year)))
+ (setq ledger-year (number-to-string newyear))))
+
+(defun ledger-set-month (newmonth)
+ "Set ledger's idea of the current month to the prefix argument."
+ (interactive "p")
+ (if (= newmonth 1)
+ (setq ledger-month (read-string "Month: " (ledger-current-month)))
+ (setq ledger-month (format "%02d" newmonth))))
(defun ledger-add-entry (entry-text &optional insert-at-point)
- (interactive "sEntry: ")
+ (interactive (list
+ (read-string "Entry: " (concat ledger-year "/" ledger-month "/"))))
(let* ((args (with-temp-buffer
(insert entry-text)
(eshell-parse-arguments (point-min) (point-max))))
@@ -89,17 +193,21 @@ Return the difference in the format of a time value."
(string-to-number (match-string 2 date))
(string-to-number (match-string 1 date)))))
(ledger-find-slot date)))
- (save-excursion
- (insert
- (with-temp-buffer
- (setq exit-code
- (apply #'ledger-run-ledger ledger-buf "entry"
- (mapcar 'eval args)))
- (goto-char (point-min))
- (if (looking-at "Error: ")
- (error (buffer-string))
- (buffer-string)))
- "\n"))))
+ (if (> (length args) 1)
+ (save-excursion
+ (insert
+ (with-temp-buffer
+ (setq exit-code
+ (apply #'ledger-exec-ledger ledger-buf ledger-buf "entry"
+ (mapcar 'eval args)))
+ (goto-char (point-min))
+ (if (looking-at "Error: ")
+ (error (buffer-string))
+ (buffer-string)))
+ "\n"))
+ (progn
+ (insert (car args) " \n\n")
+ (end-of-line -1)))))
(defun ledger-current-entry-bounds ()
(save-excursion
diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el
index 64377bb9..3ee48897 100644
--- a/lisp/ldg-new.el
+++ b/lisp/ldg-new.el
@@ -32,14 +32,24 @@
;;; Commentary:
-(require 'ldg-post)
-(require 'ldg-mode)
(require 'ldg-complete)
+(require 'ldg-exec)
+(require 'ldg-mode)
+(require 'ldg-post)
+(require 'ldg-reconcile)
+(require 'ldg-register)
+(require 'ldg-report)
(require 'ldg-state)
+(require 'ldg-test)
+(require 'ldg-texi)
+(require 'ldg-xact)
+(require 'ldg-sort)
+(require 'ldg-fonts)
+(require 'ldg-occur)
-;(autoload #'ledger-mode "ldg-mode" nil t)
-;(autoload #'ledger-fully-complete-entry "ldg-complete" nil t)
-;(autoload #'ledger-toggle-current "ldg-state" nil t)
+ ;(autoload #'ledger-mode "ldg-mode" nil t)
+ ;(autoload #'ledger-fully-complete-entry "ldg-complete" nil t)
+ ;(autoload #'ledger-toggle-current "ldg-state" nil t)
(autoload #'ledger-texi-update-test "ldg-texi" nil t)
(autoload #'ledger-texi-update-examples "ldg-texi" nil t)
diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el
new file mode 100644
index 00000000..09cca45b
--- /dev/null
+++ b/lisp/ldg-occur.el
@@ -0,0 +1,252 @@
+;;; ldg-mode.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+
+
+
+;;; Commentary:
+;; Provide code folding to ledger mode. Adapted from original loccur
+;; mode by Alexey Veretennikov <alexey dot veretennikov at gmail dot
+;; com>
+;;
+;; Adapted to ledger mode by Craig Earls <enderww at gmail dot
+;; com>
+
+;;; Code:
+
+(defface ledger-occur-folded-face
+ `((t :foreground "grey70" :invisible t ))
+ "Default face for Ledger occur mode hidden transactions"
+ :group 'ledger-faces)
+
+(defface ledger-occur-xact-face
+ `((t :background "blue" :weight normal ))
+ "Default face for Ledger occur mode shown transactions"
+ :group 'ledger-faces)
+
+(defconst ledger-occur-overlay-property-name 'ledger-occur-custom-buffer-grep)
+
+(defcustom ledger-occur-use-face-unfolded t
+ "if non-nil use a custom face for xacts shown in ledger-occur mode"
+ :group 'ledger)
+(make-variable-buffer-local 'ledger-occur-use-face-unfolded)
+
+
+(defvar ledger-occur-mode nil) ;; name of the minor mode, shown in the mode-line
+(make-variable-buffer-local 'ledger-occur-mode)
+
+(or (assq 'ledger-occur-mode minor-mode-alist)
+ (nconc minor-mode-alist
+ (list '(ledger-occur-mode ledger-occur-mode))))
+
+(defvar ledger-occur-history nil
+ "History of previously searched expressions for the prompt")
+(make-variable-buffer-local 'ledger-occur-history)
+
+(defvar ledger-occur-last-match nil
+ "Last match found")
+(make-variable-buffer-local 'ledger-occur-last-match)
+
+(defvar ledger-occur-overlay-list nil
+ "A list of currently active overlays to the ledger buffer.")
+(make-variable-buffer-local 'ledger-occur-overlay-list)
+
+
+(defun ledger-occur-mode (regex buffer)
+ (progn
+ (set-buffer buffer)
+ (setq ledger-occur-mode
+ (if (or ledger-occur-mode
+ (null regex)
+ (zerop (length regex)))
+ nil
+ (concat " Ledger-Folded: " regex)))
+ (force-mode-line-update)
+ (ledger-occur-remove-overlays)
+ (if ledger-occur-mode
+ (let* ((buffer-matches (ledger-occur-find-matches regex))
+ (ovl-bounds (ledger-occur-create-xact-overlay-bounds buffer-matches)))
+ (setq ledger-occur-overlay-list
+ (ledger-occur-create-xact-overlays ovl-bounds))
+ (setq ledger-occur-overlay-list
+ (append ledger-occur-overlay-list
+ (ledger-occur-create-folded-overlays buffer-matches)))
+ (setq ledger-occur-last-match regex))
+ (recenter))))
+
+(defun ledger-occur (regex)
+ "Perform a simple grep in current buffer for the regular
+ expression REGEX
+
+ This command hides all xact from the current buffer except
+ those containing the regular expression REGEX. A second call
+ of the function unhides lines again"
+ (interactive
+ (if ledger-occur-mode
+ (list nil)
+ (list (read-string (concat "Regexp<" (ledger-occur-prompt)
+ ">: ") "" 'ledger-occur-history ))))
+ (if (string-equal "" regex) (setq regex (ledger-occur-prompt)))
+ (ledger-occur-mode regex (current-buffer)))
+
+(defun ledger-occur-prompt ()
+ "Returns the default value of the prompt.
+
+ Default value for prompt is a current word or active
+ region(selection), if its size is 1 line"
+ (let ((prompt
+ (if (and transient-mark-mode
+ mark-active)
+ (let ((pos1 (region-beginning))
+ (pos2 (region-end)))
+ ;; Check if the start and the of an active region is on
+ ;; the same line
+ (if (= (line-number-at-pos pos1)
+ (line-number-at-pos pos2))
+ (buffer-substring-no-properties pos1 pos2)))
+ (current-word))))
+ prompt))
+
+(defun ledger-occur-create-folded-overlays(buffer-matches)
+ (let ((overlays
+ (let ((prev-end (point-min))
+ (temp (point-max)))
+ (mapcar (lambda (match)
+ (progn
+ (setq temp prev-end) ;need a swap so that the
+ ;last form in the lambda
+ ;is the (make-overlay)
+ (setq prev-end (1+ (cadr match))) ;add 1 so
+ ;that we skip
+ ;the empty
+ ;line after
+ ;the xact
+ (make-overlay
+ temp
+ (car match)
+ (current-buffer) t nil)))
+ buffer-matches))))
+ (mapcar (lambda (ovl)
+ (overlay-put ovl ledger-occur-overlay-property-name t)
+ (overlay-put ovl 'invisible t)
+ (overlay-put ovl 'intangible t))
+ (push (make-overlay (cadr (car(last buffer-matches)))
+ (point-max)
+ (current-buffer) t nil) overlays))))
+
+
+(defun ledger-occur-create-xact-overlays (ovl-bounds)
+ (let ((overlays
+ (mapcar (lambda (bnd)
+ (make-overlay
+ (car bnd)
+ (cadr bnd)
+ (current-buffer) t nil))
+ ovl-bounds)))
+ (mapcar (lambda (ovl)
+ (overlay-put ovl ledger-occur-overlay-property-name t)
+ (if ledger-occur-use-face-unfolded
+ (overlay-put ovl 'face 'ledger-occur-xact-face )))
+ overlays)))
+
+(defun ledger-occur-change-regex (regex buffer)
+ "use this function to programatically change the overlays,
+ rather than quitting out and restarting"
+ (progn
+ (set-buffer buffer)
+ (setq ledger-occur-mode nil)
+ (force-mode-line-update)
+ (ledger-occur-mode regex buffer)
+ (recenter)))
+
+(defun ledger-occur-quit-buffer (buffer)
+ "quits hidings transaction in the given buffer. Used for
+ coordinating ledger-occur with other buffers, like reconcile"
+ (progn
+ (set-buffer buffer)
+ (setq ledger-occur-mode nil)
+ (force-mode-line-update)
+ (ledger-occur-remove-overlays)
+ (recenter)))
+
+(defun ledger-occur-remove-overlays ()
+ (interactive)
+ (remove-overlays (point-min)
+ (point-max) ledger-occur-overlay-property-name t)
+ (setq ledger-occur-overlay-list nil))
+
+
+(defun ledger-occur-create-xact-overlay-bounds (buffer-matches)
+ (let ((prev-end (point-min))
+ (overlays (list)))
+ (when buffer-matches
+ (mapc (lambda (line)
+ (push (list (car line) (cadr line)) overlays)
+ (setq prev-end (cadr line)))
+ buffer-matches)
+ (setq overlays (nreverse overlays)))))
+
+(defun ledger-occur-find-xact-extents (pos)
+ "return point for beginning of xact and and of xact containing
+ position. Requires empty line separating xacts"
+ (interactive "d")
+ (save-excursion
+ (goto-char pos)
+ (let ((end-pos pos)
+ (beg-pos pos))
+ (backward-paragraph)
+ (forward-line)
+ (beginning-of-line)
+ (setq beg-pos (point))
+ (forward-paragraph)
+ (forward-line -1)
+ (end-of-line)
+ (setq end-pos (1+ (point)))
+ (list beg-pos end-pos))))
+
+(defun ledger-occur-find-matches (regex)
+ "Returns a list of 2-number tuples, specifying begnning of the
+ line and end of a line containing matching xact"
+ (save-excursion
+ (goto-char (point-min))
+ ;; Set initial values for variables
+ (let ((curpoint nil)
+ (endpoint nil)
+ (lines (list)))
+ ;; Search loop
+ (while (not (eobp))
+ (setq curpoint (point))
+ ;; if something found
+ (when (setq endpoint (re-search-forward regex nil 'end))
+ (save-excursion
+ (let ((bounds (ledger-occur-find-xact-extents (match-beginning 0))))
+ (push bounds lines)
+ (setq curpoint (cadr bounds)))) ;move to the end of the
+ ;xact, no need to search
+ ;inside it more
+ (goto-char curpoint))
+ (forward-line 1))
+ (setq lines (nreverse lines)))))
+
+
+(provide 'ldg-occur)
+
+;;; ldg-occur.el ends here
diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el
index 5d5381ae..ff664b1d 100644
--- a/lisp/ldg-post.el
+++ b/lisp/ldg-post.el
@@ -1,3 +1,24 @@
+;;; ldg-post.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
(require 'ldg-regex)
(defgroup ledger-post nil
@@ -45,16 +66,16 @@
PROMPT is a string to prompt with. CHOICES is a list of strings
to choose from."
(cond
- (ledger-post-use-iswitchb
- (let* ((iswitchb-use-virtual-buffers nil)
- (iswitchb-make-buflist-hook
- (lambda ()
- (setq iswitchb-temp-buflist choices))))
- (iswitchb-read-buffer prompt)))
- (ledger-post-use-ido
- (ido-completing-read prompt choices))
- (t
- (completing-read prompt choices))))
+ (ledger-post-use-iswitchb
+ (let* ((iswitchb-use-virtual-buffers nil)
+ (iswitchb-make-buflist-hook
+ (lambda ()
+ (setq iswitchb-temp-buflist choices))))
+ (iswitchb-read-buffer prompt)))
+ (ledger-post-use-ido
+ (ido-completing-read prompt choices))
+ (t
+ (completing-read prompt choices))))
(defvar ledger-post-current-list nil)
@@ -75,12 +96,12 @@ to choose from."
(match-end ledger-regex-post-line-group-account))
(insert account)
(cond
- ((> existing-len account-len)
- (insert (make-string (- existing-len account-len) ? )))
- ((< existing-len account-len)
- (dotimes (n (- account-len existing-len))
- (if (looking-at "[ \t]\\( [ \t]\\|\t\\)")
- (delete-char 1)))))))
+ ((> existing-len account-len)
+ (insert (make-string (- existing-len account-len) ? )))
+ ((< existing-len account-len)
+ (dotimes (n (- account-len existing-len))
+ (if (looking-at "[ \t]\\( [ \t]\\|\t\\)")
+ (delete-char 1)))))))
(goto-char pos)))
(defun ledger-next-amount (&optional end)
@@ -109,12 +130,12 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
(setq adjust (- target-col col))
(if (< col target-col)
(insert (make-string (- target-col col) ? ))
- (move-to-column target-col)
- (if (looking-back " ")
- (delete-char (- col target-col))
- (skip-chars-forward "^ \t")
- (delete-horizontal-space)
- (insert " ")))
+ (move-to-column target-col)
+ (if (looking-back " ")
+ (delete-char (- col target-col))
+ (skip-chars-forward "^ \t")
+ (delete-horizontal-space)
+ (insert " ")))
(forward-line))))))
(defun ledger-post-align-amount ()
@@ -135,16 +156,23 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
(defun ledger-post-edit-amount ()
(interactive)
(goto-char (line-beginning-position))
- (when (re-search-forward ledger-post-line-regexp (line-end-position) t)
- (goto-char (match-end ledger-regex-post-line-group-account))
- (when (re-search-forward "[-.,0-9]+" (line-end-position) t)
- (let ((val (match-string 0)))
- (goto-char (match-beginning 0))
- (delete-region (match-beginning 0) (match-end 0))
- (calc)
- (while (string-match "," val)
- (setq val (replace-match "" nil nil val)))
- (calc-eval val 'push)))))
+ (when (re-search-forward ledger-post-line-regexp (line-end-position) t)
+ (goto-char (match-end ledger-regex-post-line-group-account)) ;go to the and of the account
+ (let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;determine if the is an amount to edit
+ (if end-of-amount
+ (let ((val (match-string 0)))
+ (goto-char (match-beginning 0))
+ (delete-region (match-beginning 0) (match-end 0))
+ (calc)
+ (while (string-match "," val)
+ (setq val (replace-match "" nil nil val))) ;gets rid of commas
+ (calc-eval val 'push)) ;edit the amount
+ (progn ;make sure there are two spaces after the account name and go to calc
+ (if (search-backward " " (- (point) 3) t)
+ (goto-char (line-end-position))
+ (insert " "))
+ (calc))
+ ))))
(defun ledger-post-prev-xact ()
(interactive)
@@ -162,11 +190,6 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
(goto-char (match-end ledger-regex-post-line-group-account))))
(defun ledger-post-setup ()
- (let ((map (current-local-map)))
- (define-key map [(meta ?p)] 'ledger-post-prev-xact)
- (define-key map [(meta ?n)] 'ledger-post-next-xact)
- (define-key map [(control ?c) (control ?c)] 'ledger-post-pick-account)
- (define-key map [(control ?c) (control ?e)] 'ledger-post-edit-amount))
(if ledger-post-auto-adjust-amounts
(add-hook 'after-change-functions 'ledger-post-maybe-align t t))
(add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil))))
diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el
index baeadc33..2d591de5 100644
--- a/lisp/ldg-reconcile.el
+++ b/lisp/ldg-reconcile.el
@@ -1,21 +1,57 @@
+;;; ldg-reconcile.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
;; Reconcile mode
(defvar ledger-buf nil)
(defvar ledger-acct nil)
+(defcustom ledger-recon-buffer-name "*Reconcile*"
+ "Name to use for reconciliation window"
+ :group 'ledger)
+
+(defcustom ledger-fold-on-reconcile t
+ "if t, limit transactions shown in main buffer to those
+ matching the reconcile regex"
+ :group 'ledger)
(defun ledger-display-balance ()
+ "Calculate the cleared balance of the account being reconciled"
+ (interactive)
(let ((buffer ledger-buf)
(account ledger-acct))
(with-temp-buffer
- (let ((exit-code (ledger-run-ledger buffer "-C" "balance" account)))
- (if (/= 0 exit-code)
- (message "Error determining cleared balance")
- (goto-char (1- (point-max)))
- (goto-char (line-beginning-position))
- (delete-horizontal-space)
- (message "Cleared balance = %s"
- (buffer-substring-no-properties (point)
- (line-end-position))))))))
+ (ledger-exec-ledger buffer (current-buffer) "-C" "balance" account)
+ (goto-char (1- (point-max)))
+ (goto-char (line-beginning-position))
+ (delete-horizontal-space)
+ (message "Cleared balance = %s"
+ (buffer-substring-no-properties (point)
+ (line-end-position))))))
+
+(defun is-stdin (file)
+ "True if ledger file is standard input"
+ (or
+ (equal file "")
+ (equal file "<stdin>")
+ (equal file "/dev/stdin")))
(defun ledger-reconcile-toggle ()
(interactive)
@@ -23,18 +59,32 @@
(account ledger-acct)
(inhibit-read-only t)
cleared)
- (when (or (equal (car where) "<stdin>") (equal (car where) "/dev/stdin"))
+ (when (is-stdin (car where))
(with-current-buffer ledger-buf
- (goto-char (cdr where))
- (setq cleared (ledger-toggle-current 'pending)))
+ (goto-char (cdr where))
+ (setq cleared (ledger-toggle-current-entry)))
+ ;remove the existing face and add the new face
+ (remove-text-properties (line-beginning-position)
+ (line-end-position)
+ (list 'face))
(if cleared
- (add-text-properties (line-beginning-position)
- (line-end-position)
- (list 'face 'bold))
- (remove-text-properties (line-beginning-position)
- (line-end-position)
- (list 'face))))
- (forward-line)))
+ (add-text-properties (line-beginning-position)
+ (line-end-position)
+ (list 'face 'ledger-font-reconciler-cleared-face ))
+ (add-text-properties (line-beginning-position)
+ (line-end-position)
+ (list 'face 'ledger-font-reconciler-uncleared-face ))))
+ (forward-line)
+ (ledger-display-balance)))
+
+(defun ledger-reconcile-new-account (account)
+ (interactive "sAccount to reconcile: ")
+ (set (make-local-variable 'ledger-acct) account)
+ (let ((buf (current-buffer)))
+ (if ledger-fold-on-reconcile
+ (ledger-occur-change-regex account ledger-buf))
+ (set-buffer buf)
+ (ledger-reconcile-refresh)))
(defun ledger-reconcile-refresh ()
(interactive)
@@ -47,7 +97,7 @@
(forward-line line)))
(defun ledger-reconcile-refresh-after-save ()
- (let ((buf (get-buffer "*Reconcile*")))
+ (let ((buf (get-buffer ledger-recon-buffer-name)))
(if buf
(with-current-buffer buf
(ledger-reconcile-refresh)
@@ -62,7 +112,7 @@
(defun ledger-reconcile-delete ()
(interactive)
(let ((where (get-text-property (point) 'where)))
- (when (or (equal (car where) "<stdin>") (equal (car where) "/dev/stdin"))
+ (when (is-stdin (car where))
(with-current-buffer ledger-buf
(goto-char (cdr where))
(ledger-delete-current-entry))
@@ -74,9 +124,10 @@
(defun ledger-reconcile-visit ()
(interactive)
(let ((where (get-text-property (point) 'where)))
- (when (or (equal (car where) "<stdin>") (equal (car where) "/dev/stdin"))
+ (when (is-stdin (car where))
(switch-to-buffer-other-window ledger-buf)
- (goto-char (cdr where)))))
+ (goto-char (cdr where))
+ (recenter))))
(defun ledger-reconcile-save ()
(interactive)
@@ -87,7 +138,13 @@
(defun ledger-reconcile-quit ()
(interactive)
- (kill-buffer (current-buffer)))
+ (let ((buf ledger-buf))
+ ;Make sure you delete the window before you delete the buffer,
+ ;otherwise, madness ensues
+ (delete-window (get-buffer-window (current-buffer)))
+ (kill-buffer (current-buffer))
+ (if ledger-fold-on-reconcile
+ (ledger-occur-quit-buffer buf))))
(defun ledger-reconcile-finish ()
(interactive)
@@ -97,45 +154,148 @@
(let ((where (get-text-property (point) 'where))
(face (get-text-property (point) 'face)))
(if (and (eq face 'bold)
- (or (equal (car where) "<stdin>") (equal (car where) "/dev/stdin")))
+ (when (is-stdin (car where))))
(with-current-buffer ledger-buf
(goto-char (cdr where))
(ledger-toggle-current 'cleared))))
(forward-line 1)))
(ledger-reconcile-save))
+(defun ledger-marker-where-xact-is (emacs-xact)
+ "find the position of the xact in the ledger-buf buffer using
+ the emacs output from ledger, return a marker to the beginning
+ of the xact in the buffer"
+ (let ((buf ledger-buf))
+ (with-current-buffer buf ;use the ledger-buf buffer
+ (cons
+ (nth 0 item)
+ (if ledger-clear-whole-entries ;determines whether to
+ ;clear on the payee line
+ ;or posting line
+ (save-excursion
+ (goto-line (nth 1 item))
+ (point-marker))
+ (save-excursion
+ (goto-line (nth 0 xact))
+ (point-marker)))))))
+
(defun ledger-do-reconcile ()
- )
+ "get the uncleared transactions in the account and display them
+ in the *Reconcile* buffer"
+ (let* ((buf ledger-buf)
+ (account ledger-acct)
+ (items
+ (with-temp-buffer
+ (ledger-exec-ledger buf (current-buffer)
+ "--uncleared" "--real" "emacs" account)
+ (goto-char (point-min))
+ (unless (eobp)
+ (unless (looking-at "(")
+ (error (buffer-string)))
+ (read (current-buffer))))))
+ (if (> (length items) 0)
+ (dolist (item items)
+ (let ((index 1))
+ (dolist (xact (nthcdr 5 item))
+ (let ((beg (point))
+ (where (ledger-marker-where-xact-is item)))
+ (insert (format "%s %-4s %-30s %-30s %15s\n"
+ (format-time-string "%Y/%m/%d" (nth 2 item))
+ (if (nth 3 item)
+ (nth 3 item)
+ "")
+ (nth 4 item) (nth 1 xact) (nth 2 xact)))
+ (if (nth 3 xact)
+ (set-text-properties beg (1- (point))
+ (list 'face 'ledger-font-reconciler-cleared-face
+ 'where where))
+ (set-text-properties beg (1- (point))
+ (list 'face 'ledger-font-reconciler-uncleared-face
+ 'where where))))
+ (setq index (1+ index)))))
+ (insert (concat "There are no uncleared entries for " account)))
+ (goto-char (point-min))
+ (set-buffer-modified-p nil)
+ (toggle-read-only t)
+
+ ; this next piece of code ensures that the last of the visible
+ ; transactions in the ledger buffer is at the bottom of the
+ ; main window. The key to this is to ensure the window is selected
+ ; when the buffer point is moved and recentered. If they aren't
+ ; strange things happen.
+
+ (let
+ ((recon-window (get-buffer-window (get-buffer ledger-recon-buffer-name))))
+ (fit-window-to-buffer recon-window)
+ (with-current-buffer buf
+ (select-window (get-buffer-window buf))
+ (goto-char (point-max))
+ (recenter -1))
+
+ (select-window recon-window))))
(defun ledger-reconcile (account)
(interactive "sAccount to reconcile: ")
(let ((buf (current-buffer))
- (rbuf (get-buffer "*Reconcile*")))
+ (rbuf (get-buffer ledger-recon-buffer-name)))
(if rbuf
- (kill-buffer rbuf))
+ (progn
+ (quit-window (get-buffer-window rbuf))
+ (kill-buffer rbuf)))
(add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save)
+ (if ledger-fold-on-reconcile
+ (ledger-occur-mode account buf))
+
+ ;create the *Reconcile* window directly below the ledger buffer.
(with-current-buffer
- (pop-to-buffer (get-buffer-create "*Reconcile*"))
+ (progn
+ (set-window-buffer
+ (split-window (get-buffer-window (current-buffer)) nil nil)
+ (get-buffer-create ledger-recon-buffer-name))
+ (get-buffer ledger-recon-buffer-name))
(ledger-reconcile-mode)
(set (make-local-variable 'ledger-buf) buf)
(set (make-local-variable 'ledger-acct) account)
- (ledger-do-reconcile))))
+ (ledger-do-reconcile))))
(defvar ledger-reconcile-mode-abbrev-table)
(define-derived-mode ledger-reconcile-mode text-mode "Reconcile"
- "A mode for reconciling ledger entries."
- (let ((map (make-sparse-keymap)))
- (define-key map [(control ?m)] 'ledger-reconcile-visit)
- (define-key map [return] 'ledger-reconcile-visit)
- (define-key map [(control ?c) (control ?c)] 'ledger-reconcile-finish)
- (define-key map [(control ?x) (control ?s)] 'ledger-reconcile-save)
- (define-key map [(control ?l)] 'ledger-reconcile-refresh)
- (define-key map [? ] 'ledger-reconcile-toggle)
- (define-key map [?a] 'ledger-reconcile-add)
- (define-key map [?d] 'ledger-reconcile-delete)
- (define-key map [?n] 'next-line)
- (define-key map [?p] 'previous-line)
- (define-key map [?s] 'ledger-reconcile-save)
- (define-key map [?q] 'ledger-reconcile-quit)
- (use-local-map map)))
+ "A mode for reconciling ledger entries."
+ (let ((map (make-sparse-keymap)))
+ (define-key map [(control ?m)] 'ledger-reconcile-visit)
+ (define-key map [return] 'ledger-reconcile-visit)
+ (define-key map [(control ?c) (control ?c)] 'ledger-reconcile-finish)
+ (define-key map [(control ?x) (control ?s)] 'ledger-reconcile-save)
+ (define-key map [(control ?l)] 'ledger-reconcile-refresh)
+ (define-key map [? ] 'ledger-reconcile-toggle)
+ (define-key map [?a] 'ledger-reconcile-add)
+ (define-key map [?d] 'ledger-reconcile-delete)
+ (define-key map [?g] 'ledger-reconcile-new-account)
+ (define-key map [?n] 'next-line)
+ (define-key map [?p] 'previous-line)
+ (define-key map [?s] 'ledger-reconcile-save)
+ (define-key map [?q] 'ledger-reconcile-quit)
+ (define-key map [?b] 'ledger-display-balance)
+
+ (define-key map [menu-bar] (make-sparse-keymap "ldg-recon-menu"))
+ (define-key map [menu-bar ldg-recon-menu] (cons "Reconcile" map))
+ (define-key map [menu-bar ldg-recon-menu qui] '("Quit" . ledger-reconcile-quit))
+ (define-key map [menu-bar ldg-recon-menu sep1] '("--"))
+ (define-key map [menu-bar ldg-recon-menu pre] '("Previous Entry" . previous-line))
+ (define-key map [menu-bar ldg-recon-menu vis] '("Visit Entry" . ledger-reconcile-visit))
+ (define-key map [menu-bar ldg-recon-menu nex] '("Next Entry" . next-line))
+ (define-key map [menu-bar ldg-recon-menu sep2] '("--"))
+ (define-key map [menu-bar ldg-recon-menu del] '("Delete Entry" . ledger-reconcile-delete))
+ (define-key map [menu-bar ldg-recon-menu add] '("Add Entry" . ledger-reconcile-add))
+ (define-key map [menu-bar ldg-recon-menu tog] '("Toggle Entry" . ledger-reconcile-toggle))
+ (define-key map [menu-bar ldg-recon-menu sep3] '("--"))
+ (define-key map [menu-bar ldg-recon-menu bal] '("Show Cleared Balance" . ledger-display-balance))
+ (define-key map [menu-bar ldg-recon-menu sep4] '("--"))
+ (define-key map [menu-bar ldg-recon-menu rna] '("Reconcile New Account" . ledger-reconcile-new-account))
+ (define-key map [menu-bar ldg-recon-menu ref] '("Refresh" . ledger-reconcile-refresh))
+ (define-key map [menu-bar ldg-recon-menu sav] '("Save" . ledger-reconcile-save))
+
+ (use-local-map map)))
+
+(provide 'ldg-reconcile) \ No newline at end of file
diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el
index 1c6b8f06..680063f7 100644
--- a/lisp/ldg-regex.el
+++ b/lisp/ldg-regex.el
@@ -1,3 +1,24 @@
+;;; ldg-regex.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
(require 'rx)
(eval-when-compile
@@ -6,10 +27,10 @@
(defmacro ledger-define-regexp (name regex docs &rest args)
"Simplify the creation of a Ledger regex and helper functions."
(let ((defs
- (list
- `(defconst
- ,(intern (concat "ledger-" (symbol-name name) "-regexp"))
- ,(eval regex))))
+ (list
+ `(defconst
+ ,(intern (concat "ledger-" (symbol-name name) "-regexp"))
+ ,(eval regex))))
(addend 0) last-group)
(if (null args)
(progn
@@ -17,82 +38,82 @@
defs
(list
`(defconst
- ,(intern
- (concat "ledger-regex-" (symbol-name name) "-group"))
+ ,(intern
+ (concat "ledger-regex-" (symbol-name name) "-group"))
1)))
(nconc
defs
(list
`(defconst
- ,(intern (concat "ledger-regex-" (symbol-name name)
- "-group--count"))
+ ,(intern (concat "ledger-regex-" (symbol-name name)
+ "-group--count"))
1)))
(nconc
defs
(list
`(defmacro
- ,(intern (concat "ledger-regex-" (symbol-name name)))
- (&optional string)
+ ,(intern (concat "ledger-regex-" (symbol-name name)))
+ (&optional string)
,(format "Return the match string for the %s" name)
(match-string
,(intern (concat "ledger-regex-" (symbol-name name)
"-group"))
string)))))
-
- (dolist (arg args)
- (let (var grouping target)
- (if (symbolp arg)
- (setq var arg target arg)
- (assert (listp arg))
- (if (= 2 (length arg))
- (setq var (car arg)
- target (cadr arg))
- (setq var (car arg)
- grouping (cadr arg)
- target (caddr arg))))
-
- (if (and last-group
- (not (eq last-group (or grouping target))))
- (incf addend
- (symbol-value
- (intern-soft (concat "ledger-regex-"
- (symbol-name last-group)
- "-group--count")))))
- (nconc
- defs
- (list
- `(defconst
- ,(intern (concat "ledger-regex-" (symbol-name name)
- "-group-" (symbol-name var)))
- ,(+ addend
- (symbol-value
- (intern-soft
- (if grouping
- (concat "ledger-regex-" (symbol-name grouping)
- "-group-" (symbol-name target))
- (concat "ledger-regex-" (symbol-name target)
- "-group"))))))))
- (nconc
- defs
- (list
- `(defmacro
- ,(intern (concat "ledger-regex-" (symbol-name name)
- "-" (symbol-name var)))
- (&optional string)
- ,(format "Return the sub-group match for the %s %s."
- name var)
- (match-string
- ,(intern (concat "ledger-regex-" (symbol-name name)
- "-group-" (symbol-name var)))
- string))))
+
+ (dolist (arg args)
+ (let (var grouping target)
+ (if (symbolp arg)
+ (setq var arg target arg)
+ (assert (listp arg))
+ (if (= 2 (length arg))
+ (setq var (car arg)
+ target (cadr arg))
+ (setq var (car arg)
+ grouping (cadr arg)
+ target (caddr arg))))
+
+ (if (and last-group
+ (not (eq last-group (or grouping target))))
+ (incf addend
+ (symbol-value
+ (intern-soft (concat "ledger-regex-"
+ (symbol-name last-group)
+ "-group--count")))))
+ (nconc
+ defs
+ (list
+ `(defconst
+ ,(intern (concat "ledger-regex-" (symbol-name name)
+ "-group-" (symbol-name var)))
+ ,(+ addend
+ (symbol-value
+ (intern-soft
+ (if grouping
+ (concat "ledger-regex-" (symbol-name grouping)
+ "-group-" (symbol-name target))
+ (concat "ledger-regex-" (symbol-name target)
+ "-group"))))))))
+ (nconc
+ defs
+ (list
+ `(defmacro
+ ,(intern (concat "ledger-regex-" (symbol-name name)
+ "-" (symbol-name var)))
+ (&optional string)
+ ,(format "Return the sub-group match for the %s %s."
+ name var)
+ (match-string
+ ,(intern (concat "ledger-regex-" (symbol-name name)
+ "-group-" (symbol-name var)))
+ string))))
- (setq last-group (or grouping target))))
+ (setq last-group (or grouping target))))
- (nconc defs
- (list
- `(defconst ,(intern (concat "ledger-regex-" (symbol-name name)
- "-group--count"))
- ,(length args)))))
+ (nconc defs
+ (list
+ `(defconst ,(intern (concat "ledger-regex-" (symbol-name name)
+ "-group--count"))
+ ,(length args)))))
(cons 'progn defs)))
diff --git a/lisp/ldg-register.el b/lisp/ldg-register.el
index 7b5c0d0a..adb37a1a 100644
--- a/lisp/ldg-register.el
+++ b/lisp/ldg-register.el
@@ -1,3 +1,24 @@
+;;; ldg-register.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
(require 'ldg-post)
(require 'ldg-state)
@@ -16,8 +37,8 @@
:group 'ledger-register)
(defface ledger-register-pending-face
- '((((background light)) (:weight bold))
- (((background dark)) (:weight bold)))
+ '((((background light)) (:weight bold))
+ (((background dark)) (:weight bold)))
"Face used to highlight pending entries in a register report."
:group 'ledger-register)
@@ -34,9 +55,9 @@
(save-excursion
(goto-line (nth 1 post))
(point-marker))
- (save-excursion
- (goto-line (nth 0 xact))
- (point-marker)))))))
+ (save-excursion
+ (goto-line (nth 0 xact))
+ (point-marker)))))))
(insert (format ledger-register-line-format
(format-time-string ledger-register-date-format
(nth 2 post))
@@ -45,8 +66,8 @@
(set-text-properties beg (1- (point))
(list 'face 'ledger-register-pending-face
'where where))
- (set-text-properties beg (1- (point))
- (list 'where where))))
+ (set-text-properties beg (1- (point))
+ (list 'where where))))
(setq index (1+ index)))))
(goto-char (point-min))
)
diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el
index 5a668847..cdef6ded 100644
--- a/lisp/ldg-report.el
+++ b/lisp/ldg-report.el
@@ -1,3 +1,27 @@
+;;; ldg-report.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+(eval-when-compile
+ (require 'cl))
+
(defcustom ledger-reports
'(("bal" "ledger -f %(ledger-file) bal")
("reg" "ledger -f %(ledger-file) reg")
@@ -15,7 +39,7 @@ the substitution. See the documentation of the individual functions
in that variable for more information on the behavior of each
specifier."
:type '(repeat (list (string :tag "Report Name")
- (string :tag "Command Line")))
+ (string :tag "Command Line")))
:group 'ledger)
(defcustom ledger-report-format-specifiers
@@ -49,24 +73,40 @@ text that should replace the format specifier."
(defvar ledger-report-mode-abbrev-table)
(define-derived-mode ledger-report-mode text-mode "Ledger-Report"
- "A mode for viewing ledger reports."
- (let ((map (make-sparse-keymap)))
- (define-key map [? ] 'scroll-up)
- (define-key map [backspace] 'scroll-down)
- (define-key map [?r] 'ledger-report-redo)
- (define-key map [?s] 'ledger-report-save)
- (define-key map [?k] 'ledger-report-kill)
- (define-key map [?e] 'ledger-report-edit)
- (define-key map [?q] 'ledger-report-quit)
- (define-key map [(control ?c) (control ?l) (control ?r)]
- 'ledger-report-redo)
- (define-key map [(control ?c) (control ?l) (control ?S)]
- 'ledger-report-save)
- (define-key map [(control ?c) (control ?l) (control ?k)]
- 'ledger-report-kill)
- (define-key map [(control ?c) (control ?l) (control ?e)]
- 'ledger-report-edit)
- (use-local-map map)))
+ "A mode for viewing ledger reports."
+ (let ((map (make-sparse-keymap)))
+ (define-key map [? ] 'scroll-up)
+ (define-key map [backspace] 'scroll-down)
+ (define-key map [?r] 'ledger-report-redo)
+ (define-key map [?s] 'ledger-report-save)
+ (define-key map [?k] 'ledger-report-kill)
+ (define-key map [?e] 'ledger-report-edit)
+ (define-key map [?q] 'ledger-report-quit)
+ (define-key map [(control ?c) (control ?l) (control ?r)]
+ 'ledger-report-redo)
+ (define-key map [(control ?c) (control ?l) (control ?S)]
+ 'ledger-report-save)
+ (define-key map [(control ?c) (control ?l) (control ?k)]
+ 'ledger-report-kill)
+ (define-key map [(control ?c) (control ?l) (control ?e)]
+ 'ledger-report-edit)
+ (define-key map [(control ?c) (control ?c)] 'ledger-report-visit-source)
+
+
+ (define-key map [menu-bar] (make-sparse-keymap "ldg-rep"))
+ (define-key map [menu-bar ldg-rep] (cons "Reports" map))
+
+ (define-key map [menu-bar ldg-rep lrq] '("Quit" . ledger-report-quit))
+ (define-key map [menu-bar ldg-rep s2] '("--"))
+ (define-key map [menu-bar ldg-rep lrd] '("Scroll Down" . scroll-down))
+ (define-key map [menu-bar ldg-rep lru] '("Scroll Up" . scroll-up))
+ (define-key map [menu-bar ldg-rep s1] '("--"))
+ (define-key map [menu-bar ldg-rep lrk] '("Kill Report" . ledger-report-kill))
+ (define-key map [menu-bar ldg-rep lrr] '("Re-run Report" . ledger-report-redo))
+ (define-key map [menu-bar ldg-rep lre] '("Edit Report" . ledger-report-edit))
+ (define-key map [menu-bar ldg-rep lrs] '("Save Report" . ledger-report-save))
+
+ (use-local-map map)))
(defun ledger-report-read-name ()
"Read the name of a ledger report to use, with completion.
@@ -161,13 +201,13 @@ this variable would be set in a file local variable comment block at the
end of a ledger file which is included in some other file."
(if ledger-master-file
(expand-file-name ledger-master-file)
- (buffer-file-name)))
+ (buffer-file-name)))
(defun ledger-read-string-with-default (prompt default)
(let ((default-prompt (concat prompt
(if default
(concat " (" default "): ")
- ": "))))
+ ": "))))
(read-string default-prompt nil nil default)))
(defun ledger-report-payee-format-specifier ()
@@ -194,7 +234,7 @@ the default."
(default
(if (eq (ledger-context-line-type context) 'acct-transaction)
(regexp-quote (ledger-context-field-value context 'account))
- nil)))
+ nil)))
(ledger-read-string-with-default "Account" default)))
(defun ledger-report-expand-format-specifiers (report-cmd)
@@ -208,9 +248,9 @@ the default."
(with-current-buffer ledger-buf
(shell-quote-argument (funcall f))))
t t expanded-cmd))
- (progn
- (set-window-configuration ledger-original-window-cfg)
- (error "Invalid ledger report format specifier '%s'" specifier)))))
+ (progn
+ (set-window-configuration ledger-original-window-cfg)
+ (error "Invalid ledger report format specifier '%s'" specifier)))))
expanded-cmd))
(defun ledger-report-cmd (report-name edit)
@@ -233,8 +273,48 @@ the default."
(insert (format "Report: %s\n" ledger-report-name)
(format "Command: %s\n" cmd)
(make-string (- (window-width) 1) ?=)
- "\n")
- (shell-command cmd t nil))
+ "\n\n")
+ (let ((data-pos (point))
+ (register-report (string-match " reg\\(ister\\)? " cmd))
+ files-in-report)
+ (shell-command
+ (if register-report
+ (concat cmd " --prepend-format='%(filename):%(beg_line):'")
+ cmd) t nil)
+ (when register-report
+ (goto-char data-pos)
+ (while (re-search-forward "^\\([^:]+\\)?:\\([0-9]+\\)?:" nil t)
+ (let ((file (match-string 1))
+ (line (string-to-number (match-string 2))))
+ (delete-region (match-beginning 0) (match-end 0))
+ (set-text-properties (line-beginning-position) (line-end-position)
+ (list 'ledger-source (cons file (save-window-excursion
+ (save-excursion
+ (find-file file)
+ (widen)
+ (goto-char (point-min))
+ (forward-line (1- line))
+ (point-marker))))))
+ (end-of-line))))
+ (goto-char data-pos)))
+
+
+(defun ledger-report-visit-source ()
+ (interactive)
+ (let ((prop (get-text-property (point) 'ledger-source)))
+ (destructuring-bind (file . line-or-marker) prop
+ (find-file-other-window file)
+ (widen)
+ (if (markerp line-or-marker)
+ (goto-char line-or-marker)
+ (goto-char (point-min))
+ (forward-line (1- line-or-marker))
+ (re-search-backward "^[0-9]+")
+ (beginning-of-line)
+ (let ((start-of-txn (point)))
+ (forward-paragraph)
+ (narrow-to-region start-of-txn (point))
+ (backward-paragraph))))))
(defun ledger-report-goto ()
"Goto the ledger report buffer."
@@ -407,7 +487,7 @@ specified line, returns nil."
(let ((left (forward-line offset)))
(if (not (equal left 0))
nil
- (ledger-context-at-point)))))
+ (ledger-context-at-point)))))
(defun ledger-context-line-type (context-info)
(nth 0 context-info))
@@ -445,4 +525,6 @@ specified line, returns nil."
(let ((context-info (ledger-context-other-line i)))
(if (eq (ledger-context-line-type context-info) 'entry)
(ledger-context-field-value context-info 'payee)
- nil))))
+ nil))))
+
+(provide 'ldg-report)
diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el
new file mode 100644
index 00000000..86e3fa0a
--- /dev/null
+++ b/lisp/ldg-sort.el
@@ -0,0 +1,61 @@
+;;; ldg-xact.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+;; A sample entry sorting function, which works if entry dates are of
+;; the form YYYY/mm/dd.
+
+(defun ledger-next-record-function ()
+ (if (re-search-forward
+ (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
+ "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t)
+ (goto-char (match-beginning 0))
+ (goto-char (point-max))))
+
+(defun ledger-end-record-function ()
+ (forward-paragraph))
+
+(defun ledger-sort-region (beg end)
+ (interactive "r") ;load beg and end from point and mark automagically
+ (let ((new-beg beg)
+ (new-end end))
+ (save-excursion
+ (save-restriction
+ (ledger-next-record-function) ;make sure point is at the beginning of a xact
+ (setq new-beg (point))
+ (goto-char end)
+ (ledger-next-record-function) ;make sure end of region is at the beginning of
+ ;next record after the region
+ (setq new-end (point))
+ (narrow-to-region beg end)
+ (goto-char (point-min))
+
+ (let ((inhibit-field-text-motion t))
+ (sort-subr
+ nil
+ 'ledger-next-record-function
+ 'ledger-end-record-function))))))
+
+(defun ledger-sort-buffer ()
+ (interactive)
+ (ledger-sort-region (point-min) (point-max)))
+
+
+(provide 'ldg-sort) \ No newline at end of file
diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el
index 6a841621..41c0d8f2 100644
--- a/lisp/ldg-state.el
+++ b/lisp/ldg-state.el
@@ -1,3 +1,24 @@
+;;; ldg-state.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
(defcustom ledger-clear-whole-entries nil
"If non-nil, clear whole entries, not individual transactions."
:type 'boolean
@@ -7,9 +28,9 @@
(if (not (null state))
(if (and style (eq style 'cleared))
'cleared)
- (if (and style (eq style 'pending))
- 'pending
- 'cleared)))
+ (if (and style (eq style 'pending))
+ 'pending
+ 'cleared)))
(defun ledger-entry-state ()
(save-excursion
@@ -85,23 +106,23 @@ dropped."
(progn
(insert "* ")
(setq inserted t)))
- (if (and style (eq style 'pending))
- (progn
- (insert "! ")
- (setq inserted t))
- (progn
- (insert "* ")
- (setq inserted t))))
+ (if (and style (eq style 'pending))
+ (progn
+ (insert "! ")
+ (setq inserted t))
+ (progn
+ (insert "* ")
+ (setq inserted t))))
(if (and inserted
(re-search-forward "\\(\t\\| [ \t]\\)"
(line-end-position) t))
(cond
- ((looking-at "\t")
- (delete-char 1))
- ((looking-at " [ \t]")
- (delete-char 2))
- ((looking-at " ")
- (delete-char 1))))
+ ((looking-at "\t")
+ (delete-char 1))
+ ((looking-at " [ \t]")
+ (delete-char 2))
+ ((looking-at " ")
+ (delete-char 1))))
(setq clear inserted)))))
;; Clean up the entry so that it displays minimally
(save-excursion
@@ -114,12 +135,12 @@ dropped."
(skip-chars-forward " \t")
(let ((cleared (if (member (char-after) '(?\* ?\!))
(char-after)
- ? )))
+ ? )))
(if first
(setq state cleared
first nil)
- (if (/= state cleared)
- (setq hetero t))))
+ (if (/= state cleared)
+ (setq hetero t))))
(forward-line))
(when (and (not hetero) (/= state ? ))
(goto-char (car bounds))
@@ -141,12 +162,12 @@ dropped."
(if (re-search-forward "\\(\t\\| [ \t]\\)"
(line-end-position) t)
(cond
- ((looking-at "\t")
- (delete-char 1))
- ((looking-at " [ \t]")
- (delete-char 2))
- ((looking-at " ")
- (delete-char 1)))))))
+ ((looking-at "\t")
+ (delete-char 1))
+ ((looking-at " [ \t]")
+ (delete-char 2))
+ ((looking-at " ")
+ (delete-char 1)))))))
clear))
(defun ledger-toggle-current (&optional style)
@@ -165,7 +186,7 @@ dropped."
(forward-line)
(goto-char (line-beginning-position))))
(ledger-toggle-current-entry style))
- (ledger-toggle-current-transaction style)))
+ (ledger-toggle-current-transaction style)))
(defun ledger-toggle-current-entry (&optional style)
(interactive)
@@ -180,10 +201,10 @@ dropped."
(delete-char 1)
(if (and style (eq style 'cleared))
(insert " *")))
- (if (and style (eq style 'pending))
- (insert " ! ")
- (insert " * "))
- (setq clear t))))
+ (if (and style (eq style 'pending))
+ (insert " ! ")
+ (insert " * "))
+ (setq clear t))))
clear))
(provide 'ldg-state)
diff --git a/lisp/ldg-test.el b/lisp/ldg-test.el
index 478c62d8..7667a05e 100644
--- a/lisp/ldg-test.el
+++ b/lisp/ldg-test.el
@@ -1,3 +1,24 @@
+;;; ldg-test.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
(defcustom ledger-source-directory "~/src/ledger"
"Directory where the Ledger sources are located."
:type 'directory
@@ -46,9 +67,9 @@
(ledger-mode)
(if input
(insert input)
- (insert "2012-03-17 Payee\n")
- (insert " Expenses:Food $20\n")
- (insert " Assets:Cash\n"))
+ (insert "2012-03-17 Payee\n")
+ (insert " Expenses:Food $20\n")
+ (insert " Assets:Cash\n"))
(insert "\ntest reg\n")
(if output
(insert output))
@@ -69,7 +90,7 @@
(let ((prev-directory default-directory))
(cd ledger-source-directory)
(unwind-protect
- (async-shell-command (format "\"%s\" %s" command args))
+ (async-shell-command (format "\"%s\" %s" command args))
(cd prev-directory)))))))
(provide 'ldg-test)
diff --git a/lisp/ldg-texi.el b/lisp/ldg-texi.el
index b0334099..53e050ce 100644
--- a/lisp/ldg-texi.el
+++ b/lisp/ldg-texi.el
@@ -1,3 +1,24 @@
+;;; ldg-texi.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
(defvar ledger-path "/Users/johnw/bin/ledger")
(defvar ledger-sample-doc-path "/Users/johnw/src/ledger/doc/sample.dat")
(defvar ledger-normalization-args "--args-only --columns 80")
@@ -73,17 +94,17 @@
(if (string-match "\\$LEDGER" command)
(replace-match (format "%s -f \"%s\" %s" ledger-path
data-file ledger-normalization-args) t t command)
- (concat (format "%s -f \"%s\" %s " ledger-path
- data-file ledger-normalization-args) command)))
+ (concat (format "%s -f \"%s\" %s " ledger-path
+ data-file ledger-normalization-args) command)))
(defun ledger-texi-invoke-command (command)
(with-temp-buffer (shell-command command t (current-buffer))
- (if (= (point-min) (point-max))
- (progn
- (push-mark nil t)
- (message "Command '%s' yielded no result at %d" command (point))
- (ding))
- (buffer-string))))
+ (if (= (point-min) (point-max))
+ (progn
+ (push-mark nil t)
+ (message "Command '%s' yielded no result at %d" command (point))
+ (ding))
+ (buffer-string))))
(defun ledger-texi-write-test-data (name input)
(let ((path (expand-file-name name temporary-file-directory)))
@@ -128,7 +149,7 @@
(let ((section-name (if (string= section "smex")
"smallexample"
- "example"))
+ "example"))
(output (ledger-texi-invoke-command
(ledger-texi-expand-command command data-file))))
(insert "@" section-name ?\n output
diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el
index e1f165a7..1df7d79a 100644
--- a/lisp/ldg-xact.el
+++ b/lisp/ldg-xact.el
@@ -1,20 +1,27 @@
+;;; ldg-xact.el --- Helper code for use with the "ledger" command-line tool
+
+;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
+
+;; This file is not part of GNU Emacs.
+
+;; This 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 2, or (at your option) any later
+;; version.
+;;
+;; This 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., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
;; A sample entry sorting function, which works if entry dates are of
;; the form YYYY/mm/dd.
-(defun ledger-sort ()
- (interactive)
- (save-excursion
- (goto-char (point-min))
- (sort-subr
- nil
- (function
- (lambda ()
- (if (re-search-forward
- (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
- "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t)
- (goto-char (match-beginning 0))
- (goto-char (point-max)))))
- (function
- (lambda ()
- (forward-paragraph))))))
+
+(provide 'ldg-xact) \ No newline at end of file