From 24b791ad078e36cfd8f895544636320467aa70ce Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 16 Jan 2013 17:50:31 -0600 Subject: Apply patch to update ldg-reconcile.el --- lisp/ldg-reconcile.el | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index baeadc33..d3dda60f 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -105,7 +105,45 @@ (ledger-reconcile-save)) (defun ledger-do-reconcile () - ) + (let* ((buf ledger-buf) + (account ledger-acct) + (items + (with-current-buffer + (apply #'ledger-exec-ledger + buf nil "emacs" account "--uncleared" '("--real")) + (goto-char (point-min)) + (unless (eobp) + (unless (looking-at "(") + (error (buffer-string))) + (read (current-buffer)))))) + (dolist (item items) + (let ((index 1)) + (dolist (xact (nthcdr 5 item)) + (let ((beg (point)) + (where + (with-current-buffer buf + (cons + (nth 0 item) + (if ledger-clear-whole-entries + (save-excursion + (goto-line (nth 1 item)) + (point-marker)) + (save-excursion + (goto-line (nth 0 xact)) + (point-marker))))))) + (insert (format "%s %-30s %-25s %15s\n" + (format-time-string "%m/%d" (nth 2 item)) + (nth 4 item) (nth 1 xact) (nth 2 xact))) + (if (nth 3 xact) + (set-text-properties beg (1- (point)) + (list 'face 'bold + 'where where)) + (set-text-properties beg (1- (point)) + (list 'where where)))) + (setq index (1+ index))))) + (goto-char (point-min)) + (set-buffer-modified-p nil) + (toggle-read-only t))) (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") -- cgit v1.2.3 From 0bbff75f43a096823c2838ae3b7330cf86a54b78 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 29 Jan 2013 08:50:50 -0700 Subject: fixes the reconcile mode, adds menus for all modes thanks to dk for the is-std defun. --- lisp/ldg-mode.el | 38 +++++++++++++- lisp/ldg-reconcile.el | 136 ++++++++++++++++++++++++++++++-------------------- lisp/ldg-report.el | 15 ++++++ 3 files changed, 132 insertions(+), 57 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 04c6ee1b..caa57e8e 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -19,6 +19,7 @@ (defvar ledger-mode-abbrev-table) + ;;;###autoload (define-derived-mode ledger-mode text-mode "Ledger" "A mode for editing ledger data files." @@ -51,8 +52,41 @@ (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 ?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 [menu-bar] (make-sparse-keymap "ldg-menu")) + (define-key map [menu-bar ldg-menu] (cons "Ledger" map)) + + (define-key map [menu-bar ldg-menu lrk] '("Kill Report" . ledger-report-kill)) + (define-key map [menu-bar ldg-menu lre] '("Edit Report" . ledger-report-edit)) + (define-key map [menu-bar ldg-menu lrs] '("Save Report" . ledger-report-save)) + (define-key map [menu-bar ldg-menu lrr] '("Re-run Report" . ledger-report-redo)) + (define-key map [menu-bar ldg-menu lrg] '("Goto Report" . ledger-report-goto)) + (define-key map [menu-bar ldg-menu lr] '("Run Report" . ledger-report)) + (define-key map [menu-bar ldg-menu s5] '("--")) + (define-key map [menu-bar ldg-menu sm] '("Set Month" . ledger-set-month)) + (define-key map [menu-bar ldg-menu sy] '("Set Year" . ledger-set-year)) + (define-key map [menu-bar ldg-menu s1] '("--")) + (define-key map [menu-bar ldg-menu so] '("Sort Buffer" . ledger-sort)) + (define-key map [menu-bar ldg-menu s2] '("--")) + (define-key map [menu-bar ldg-menu te] '("Toggle Current Posting" . ledger-toggle-current)) + (define-key map [menu-bar ldg-menu tt] '("Toggle Current Transaction" . ledger-toggle-current-entry)) + (define-key map [menu-bar ldg-menu s4] '("--")) + (define-key map [menu-bar ldg-menu de] '("Delete Entry" . ledger-delete-current-entry)) + (define-key map [menu-bar ldg-menu ae] '("Add Entry" . ledger-add-entry)) + (define-key map [menu-bar ldg-menu s3] '("--")) + (define-key map [menu-bar ldg-menu re] '("Reconcile Account" . ledger-reconcile))) + + + + (ledger-report-patch-reports (current-buffer))) (defun ledger-time-less-p (t1 t2) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index d3dda60f..73409e66 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -4,18 +4,24 @@ (defvar ledger-acct nil) (defun ledger-display-balance () + "Calculate the cleared balance of the account being reconciled" (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 "") + (equal file "/dev/stdin"))) (defun ledger-reconcile-toggle () (interactive) @@ -23,18 +29,19 @@ (account ledger-acct) (inhibit-read-only t) cleared) - (when (or (equal (car where) "") (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))) (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 'bold)) + (remove-text-properties (line-beginning-position) + (line-end-position) + (list 'face)))) + (forward-line) + (ledger-display-balance))) (defun ledger-reconcile-refresh () (interactive) @@ -62,7 +69,7 @@ (defun ledger-reconcile-delete () (interactive) (let ((where (get-text-property (point) 'where))) - (when (or (equal (car where) "") (equal (car where) "/dev/stdin")) + (when (is-stdin (car where)) (with-current-buffer ledger-buf (goto-char (cdr where)) (ledger-delete-current-entry)) @@ -74,7 +81,7 @@ (defun ledger-reconcile-visit () (interactive) (let ((where (get-text-property (point) 'where))) - (when (or (equal (car where) "") (equal (car where) "/dev/stdin")) + (when (is-stdin (car where)) (switch-to-buffer-other-window ledger-buf) (goto-char (cdr where))))) @@ -97,7 +104,7 @@ (let ((where (get-text-property (point) 'where)) (face (get-text-property (point) 'face))) (if (and (eq face 'bold) - (or (equal (car where) "") (equal (car where) "/dev/stdin"))) + (when (is-stdin (car where)))) (with-current-buffer ledger-buf (goto-char (cdr where)) (ledger-toggle-current 'cleared)))) @@ -105,45 +112,48 @@ (ledger-reconcile-save)) (defun ledger-do-reconcile () - (let* ((buf ledger-buf) + "get the uncleared transactions in the account and display them in the *Reconcile* buffer" + (let* ((buf ledger-buf) (account ledger-acct) (items - (with-current-buffer - (apply #'ledger-exec-ledger - buf nil "emacs" account "--uncleared" '("--real")) + (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)))))) - (dolist (item items) - (let ((index 1)) - (dolist (xact (nthcdr 5 item)) - (let ((beg (point)) - (where - (with-current-buffer buf - (cons - (nth 0 item) - (if ledger-clear-whole-entries - (save-excursion - (goto-line (nth 1 item)) - (point-marker)) - (save-excursion - (goto-line (nth 0 xact)) - (point-marker))))))) - (insert (format "%s %-30s %-25s %15s\n" - (format-time-string "%m/%d" (nth 2 item)) - (nth 4 item) (nth 1 xact) (nth 2 xact))) - (if (nth 3 xact) - (set-text-properties beg (1- (point)) - (list 'face 'bold - 'where where)) - (set-text-properties beg (1- (point)) - (list 'where where)))) - (setq index (1+ index))))) - (goto-char (point-min)) - (set-buffer-modified-p nil) - (toggle-read-only t))) + (read (current-buffer)))))) + (dolist (item items) + (let ((index 1)) + (dolist (xact (nthcdr 5 item)) + (let ((beg (point)) + (where + (with-current-buffer buf + (cons + (nth 0 item) + (if ledger-clear-whole-entries + (save-excursion + (goto-line (nth 1 item)) + (point-marker)) + (save-excursion + (goto-line (nth 0 xact)) + (point-marker))))))) + (insert (format "%s %-4s %-30s %-30s %15s\n" + (format-time-string "%Y/%m/%d" (nth 2 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 'bold + 'where where)) + (set-text-properties beg (1- (point)) + (list 'where where)))) + (setq index (1+ index))))) + (goto-char (point-min)) + (set-buffer-modified-p nil) + (toggle-read-only t))) + (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") @@ -176,4 +186,20 @@ (define-key map [?p] 'previous-line) (define-key map [?s] 'ledger-reconcile-save) (define-key map [?q] 'ledger-reconcile-quit) + + (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 ref] '("Refresh" . ledger-reconcile-refresh)) + (define-key map [menu-bar ldg-recon-menu sav] '("Save" . ledger-reconcile-save)) + (use-local-map map))) diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index f9c6afca..efd9bdb4 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -70,6 +70,21 @@ text that should replace the format specifier." (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 () -- cgit v1.2.3 From 426e1056518301456959e27fd0bbb16829274a1b Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 29 Jan 2013 12:16:47 -0700 Subject: Fixed the new ledger mod so that loading leg-new.el is sufficient The reconcile package and the xact package didn't provide themselves, and the leg-new module didn't load up everything it needed. --- lisp/ldg-new.el | 13 +++++++++---- lisp/ldg-reconcile.el | 2 ++ lisp/ldg-xact.el | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index 8505fe4a..d9e0fc60 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -32,12 +32,17 @@ ;;; Commentary: -(require 'ldg-post) -(require 'ldg-mode) (require 'ldg-complete) -(require 'ldg-state) +(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) ;(autoload #'ledger-mode "ldg-mode" nil t) ;(autoload #'ledger-fully-complete-entry "ldg-complete" nil t) ;(autoload #'ledger-toggle-current "ldg-state" nil t) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 73409e66..08dbc587 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -203,3 +203,5 @@ (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-xact.el b/lisp/ldg-xact.el index e1f165a7..6e14a14c 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -18,3 +18,4 @@ (lambda () (forward-paragraph)))))) +(provide 'ldg-xact) \ No newline at end of file -- cgit v1.2.3 From eff14723378133469238a9e302677b84c3f7b63e Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 29 Jan 2013 13:57:22 -0700 Subject: Added GPL licensing information to lisp files --- lisp/ldg-complete.el | 21 +++++++++++++++++++++ lisp/ldg-exec.el | 21 +++++++++++++++++++++ lisp/ldg-mode.el | 22 ++++++++++++++++++++++ lisp/ldg-post.el | 21 +++++++++++++++++++++ lisp/ldg-reconcile.el | 21 +++++++++++++++++++++ lisp/ldg-regex.el | 21 +++++++++++++++++++++ lisp/ldg-register.el | 21 +++++++++++++++++++++ lisp/ldg-report.el | 21 +++++++++++++++++++++ lisp/ldg-state.el | 21 +++++++++++++++++++++ lisp/ldg-test.el | 21 +++++++++++++++++++++ lisp/ldg-texi.el | 21 +++++++++++++++++++++ lisp/ldg-xact.el | 21 +++++++++++++++++++++ 12 files changed, 253 insertions(+) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index 7b4b0471..85546156 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) diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el index bf3565b4..ab041fec 100644 --- a/lisp/ldg-exec.el +++ b/lisp/ldg-exec.el @@ -1,3 +1,24 @@ +;;; 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. + (defgroup ledger-exec nil "Interface to the Ledger command-line accounting program." :group 'ledger) diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index e36dc969..842cd582 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -1,3 +1,25 @@ +;;; 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 () diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 05b9d352..7cb525a7 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 diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 08dbc587..011bf400 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -1,3 +1,24 @@ +;;; 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) diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el index 1c6b8f06..f2f83937 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 diff --git a/lisp/ldg-register.el b/lisp/ldg-register.el index 7b5c0d0a..4c397049 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) diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index a1ffe3b0..394c12e7 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -1,3 +1,24 @@ +;;; 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)) diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index 6a841621..03017b25 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 diff --git a/lisp/ldg-test.el b/lisp/ldg-test.el index 478c62d8..2036ea7b 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 diff --git a/lisp/ldg-texi.el b/lisp/ldg-texi.el index b0334099..fefa7d2b 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") diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index 6e14a14c..11e6fbaf 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -1,3 +1,24 @@ +;;; 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. -- cgit v1.2.3 From 0e16ce75f0c219cb83568c1a5b2362bd5028768d Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 30 Jan 2013 21:50:23 -0700 Subject: Add ability to reconcile new account without switching recon buffers Show cleared balance on command Update documentation --- doc/ledger3.texi | 6 +++++- lisp/ldg-reconcile.el | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/doc/ledger3.texi b/doc/ledger3.texi index ee4c990b..79ce0b0d 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -2502,13 +2502,17 @@ all of the uncleared transactions. The reconcile buffer has several functions: @item C-x C-s to save changes (to the ledger file as well). @item q - quite the reconcile mode + quit the reconcile mode @item n p next line or previous line @item A add entry @item D delete entry + @item g + reconcile new account + @item b + show cleared balance in mini-buffer @item C-l refresh display @end table diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 011bf400..aaccfb07 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -26,6 +26,7 @@ (defun ledger-display-balance () "Calculate the cleared balance of the account being reconciled" + (interactive) (let ((buffer ledger-buf) (account ledger-acct)) (with-temp-buffer @@ -64,6 +65,11 @@ (forward-line) (ledger-display-balance))) +(defun ledger-reconcile-new-account (account) + (interactive "sAccount to reconcile: ") + (set (make-local-variable 'ledger-acct) account) + (ledger-reconcile-refresh)) + (defun ledger-reconcile-refresh () (interactive) (let ((inhibit-read-only t) @@ -203,10 +209,12 @@ (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)) @@ -220,6 +228,9 @@ (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)) -- cgit v1.2.3 From edd82b2639e8a4d1f865dfae898caf678a9e7cbd Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 1 Feb 2013 11:39:48 -0700 Subject: Add custom faces to the reconciler --- lisp/ldg-fonts.el | 15 +++++++++++++++ lisp/ldg-reconcile.el | 17 +++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-fonts.el b/lisp/ldg-fonts.el index 9f98a9fd..2b7717c6 100644 --- a/lisp/ldg-fonts.el +++ b/lisp/ldg-fonts.el @@ -56,6 +56,21 @@ "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) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index aaccfb07..02d0662a 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -55,13 +55,17 @@ (with-current-buffer ledger-buf (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)))) + (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))) @@ -172,10 +176,11 @@ (nth 4 item) (nth 1 xact) (nth 2 xact))) (if (nth 3 xact) (set-text-properties beg (1- (point)) - (list 'face 'bold + (list 'face 'ledger-font-reconciler-cleared-face 'where where)) (set-text-properties beg (1- (point)) - (list 'where where)))) + (list 'face 'ledger-font-reconciler-uncleared-face + 'where where)))) (setq index (1+ index))))) (goto-char (point-min)) (set-buffer-modified-p nil) -- cgit v1.2.3 From cf76c2559904740e7ea7f99965c01814d3799349 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sat, 2 Feb 2013 09:15:03 -0700 Subject: If there is no XACT code print blank, not "nil" --- lisp/ldg-reconcile.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 02d0662a..753c2fa5 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -172,7 +172,9 @@ (point-marker))))))) (insert (format "%s %-4s %-30s %-30s %15s\n" (format-time-string "%Y/%m/%d" (nth 2 item)) - (nth 3 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)) -- cgit v1.2.3 From 71de1e6cdcdea280f5bf63a8a2e3d7a22411c663 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 5 Feb 2013 11:07:36 -0700 Subject: Enh 246 add code folding to ledger mode Based on loccur. Hides everything but the xacts that match a regex. Linked to reconcile mode so that when you reconcile an account on xacts with that account are shown. Documentation updated --- doc/ledger3.texi | 51 +++++++++- lisp/ldg-mode.el | 5 +- lisp/ldg-new.el | 2 + lisp/ldg-occur.el | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/ldg-reconcile.el | 165 ++++++++++++++++++--------------- 5 files changed, 394 insertions(+), 81 deletions(-) create mode 100644 lisp/ldg-occur.el (limited to 'lisp/ldg-reconcile.el') diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 815c770b..ce062104 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -2367,6 +2367,8 @@ add a new entry, based on previous entries toggle cleared status of an entire entry @item C-c C-c toggle cleared status of an individual posting +@item C-c C-f +toggle folding mode. When on shows only transactions that meet a given REGEX @item C-c C-y set default year for entry mode @item C-c C-m @@ -2401,12 +2403,13 @@ kill the ledger report buffer @subsection Working with entries @menu * Manual Entry Support:: +* Hiding Transactions:: * Automagically Adding new entries:: * Clearing Transactions:: * Calculating Values with EMACS Calc:: @end menu -@node Manual Entry Support, Automagically Adding new entries, Working with entries, Working with entries +@node Manual Entry Support, Hiding Transactions, Working with entries, Working with entries @subsubsection Manual Entry Support @cindex completion @@ -2427,8 +2430,38 @@ habit to get in to prevent misspellings of accounts. Remember Ledger does not validate the names of payees or account so a misspelled account will be interpreted as a new account by ledger. +@node Hiding Transactions, Automagically Adding new entries, Manual Entry Support, Working with entries +@subsubsection Hiding Transactions + +There are several ways to organize Ledger data files. You can use a +master file and @code{include} one file for each real bank or brokerage +account, separate files for major expense categories, a mix of those +ideas, or throw every transaction in to one giant file. The biggest +drawback to uing one file is that it can get confusing finding specific +transactions in the file. + +Ledger mode has a special transaction hiding mode that you can use to +hide all transactions except those that meet a regular expression you +provide. By default this command is bound to @code{C-c C-f}. EMACS +will ask for a regular expression, which at its simplest is just text +you want to match. For example, lets say you want to review the +transactions in your checking account named @code{"Assets:Checking"}. +Type @code{C-c C-f}, then type @code{Checking} in the minibuffer. EMACS +will hide all other transactions and highlight the remaining +transactions. You can edit them without fear that your other +transaction have had anything done, they are only hidden from view. + +The color used to highlight the xaction can be customized in the EMACS +customization menu. It is called @code{ledger-occur-xact-face}, and can +be changed to alter any charactistic of a font that you want. If you +don't want any highlighting, simply set +@code{ledger-occur-use-face-unfolded} to @code{nil} in the customization +menu. + +To clear the highlighting and show all transactions, type @code{C-c C-f} +again. -@node Automagically Adding new entries, Clearing Transactions, Manual Entry Support, Working with entries +@node Automagically Adding new entries, Clearing Transactions, Hiding Transactions, Working with entries @subsubsection Automagically Adding new entries @cindex new transactions in EMACS @cindex EMACS, adding new transactions @@ -2463,7 +2496,7 @@ ordered by date, not at the bottom of the file. If you need to include spaces in the payee name, then surrond the name of the payee with double quotes, otherwise ledger will interpret the second part of the name as an account. -@node Clearing Transactions, , Automagically Adding new entries, Working with entries +@node Clearing Transactions, Calculating Values with EMACS Calc, Automagically Adding new entries, Working with entries @subsubsection Clearing Transactions and Postings @cindex clearing transactions in EMACS @cindex EMACS, clear transaction @@ -2491,7 +2524,7 @@ toggled. @node Calculating Values with EMACS Calc, , Clearing Transactions, Working with entries @subsubsection Calculating Values with EMACS Calc -EMACS come with a very power calculator built in. You can use it to +EMACS come with a very powerful calculator built in. You can use it to easily insert calculated amounts directly into your ledger buffer. From the menu, select @code{Calc on Amount}. Calc will pull the current amount to the top of the calc stack. Calulate the value as you normally @@ -2529,6 +2562,14 @@ all of the uncleared transactions. The reconcile buffer has several functions: @item C-l refresh display @end table + +By default the reconcile mode uses transaction hiding to show only +transaction eligible for your reconcile. Th reconcile widow itself will +only show a summary of uncleared transaction while the main buffer will +show all transaction meeting the regex, cleared or not. This behavior +can be disabled by setting @code{ledger-fold-on-reconcile} to nil in the +emacs customization menus. + @node Generating Reports, , Reconciling accounts, Using EMACS @subsection Generating Reports @@ -2539,7 +2580,7 @@ retyping the command line, or writing shell scripts for simple one line commands. To generate a report, select the @code{Run Reports} menu, or type -@code{C-c C-o C-r}. Emacs will prompt for a report name. If it +@code{C-c C-o C-r}. EMACS will prompt for a report name. If it recognizes the name it will run the report again. If it is a new name, or blank it will respond by giving you an example command line to edit. Hitting return willrun the report and present it in a new buffer. diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index c185c198..4c55cdc0 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -72,6 +72,7 @@ customizable to ease retro-entry.") (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) @@ -110,7 +111,9 @@ customizable to ease retro-entry.") (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 "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." diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index c885cf21..1d7d5cac 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -45,6 +45,8 @@ (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) diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el new file mode 100644 index 00000000..9cf7f3b1 --- /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 +;; +;; Adapted to ledger mode by Craig Earls + +;;; 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) + (save-excursion + (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 + (mapcar (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) + (next-line) + (beginning-of-line) + (setq beg-pos (point)) + (forward-paragraph) + (previous-line) + (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-reconcile.el b/lisp/ldg-reconcile.el index 753c2fa5..0cac33c5 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -24,6 +24,12 @@ (defvar ledger-buf nil) (defvar ledger-acct nil) +(defcustom ledger-fold-on-reconcile t + "if t, limit transactions shown in main buffer to those + matching the reconcile regex" + :group 'ledger) +(make-variable-buffer-local 'ledger-fold-on-reconcilex) + (defun ledger-display-balance () "Calculate the cleared balance of the account being reconciled" (interactive) @@ -55,10 +61,10 @@ (with-current-buffer ledger-buf (goto-char (cdr where)) (setq cleared (ledger-toggle-current-entry))) - ;remove the existing face and add the new face + ;remove the existing face and add the new face (remove-text-properties (line-beginning-position) - (line-end-position) - (list 'face)) + (line-end-position) + (list 'face)) (if cleared (add-text-properties (line-beginning-position) (line-end-position) @@ -72,7 +78,11 @@ (defun ledger-reconcile-new-account (account) (interactive "sAccount to reconcile: ") (set (make-local-variable 'ledger-acct) account) - (ledger-reconcile-refresh)) + (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) @@ -125,7 +135,10 @@ (defun ledger-reconcile-quit () (interactive) - (kill-buffer (current-buffer))) + (let ((buf ledger-buf)) + (kill-buffer (current-buffer)) + (if ledger-fold-on-reconcile + (ledger-occur-quit-buffer buf)))) (defun ledger-reconcile-finish () (interactive) @@ -144,49 +157,49 @@ (defun ledger-do-reconcile () "get the uncleared transactions in the account and display them in the *Reconcile* buffer" - (let* ((buf ledger-buf) + (let* ((buf ledger-buf) (account ledger-acct) (items (with-temp-buffer (ledger-exec-ledger buf (current-buffer) "--uncleared" "--real" - "emacs" account) + "emacs" account) (goto-char (point-min)) (unless (eobp) (unless (looking-at "(") (error (buffer-string))) (read (current-buffer)))))) - (dolist (item items) - (let ((index 1)) - (dolist (xact (nthcdr 5 item)) - (let ((beg (point)) - (where - (with-current-buffer buf - (cons - (nth 0 item) - (if ledger-clear-whole-entries - (save-excursion - (goto-line (nth 1 item)) - (point-marker)) - (save-excursion - (goto-line (nth 0 xact)) - (point-marker))))))) - (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))))) - (goto-char (point-min)) - (set-buffer-modified-p nil) - (toggle-read-only t))) + (dolist (item items) + (let ((index 1)) + (dolist (xact (nthcdr 5 item)) + (let ((beg (point)) + (where + (with-current-buffer buf + (cons + (nth 0 item) + (if ledger-clear-whole-entries + (save-excursion + (goto-line (nth 1 item)) + (point-marker)) + (save-excursion + (goto-line (nth 0 xact)) + (point-marker))))))) + (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))))) + (goto-char (point-min)) + (set-buffer-modified-p nil) + (toggle-read-only t))) (defun ledger-reconcile (account) @@ -196,6 +209,8 @@ (if rbuf (kill-buffer rbuf)) (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save) + (if ledger-fold-on-reconcile + (ledger-occur-mode account buf)) (with-current-buffer (pop-to-buffer (get-buffer-create "*Reconcile*")) (ledger-reconcile-mode) @@ -206,41 +221,41 @@ (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 [?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))) + "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 -- cgit v1.2.3 From e3431c4bffd57c39e96779a8449fe08679857448 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 7 Feb 2013 09:12:44 -0700 Subject: reconcile mode windowing improvements * reconcile mode now places its window at the bottom of the ledger window it was called form and minimizes its height to the size of the recon buffer. * It all specifically informs the user if there are no uncleared items. * When reconcile mode is entered it sets the ledger-occur mode and scrolls the bottom of the visible buffer to the bottom of the ledger window ensuring transactions are visible. --- lisp/ldg-reconcile.el | 191 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 115 insertions(+), 76 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 0cac33c5..22ad5bc1 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -23,12 +23,14 @@ (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) -(make-variable-buffer-local 'ledger-fold-on-reconcilex) (defun ledger-display-balance () "Calculate the cleared balance of the account being reconciled" @@ -95,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) @@ -136,6 +138,9 @@ (defun ledger-reconcile-quit () (interactive) (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)))) @@ -155,107 +160,141 @@ (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" + "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) + (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)))))) - (dolist (item items) - (let ((index 1)) - (dolist (xact (nthcdr 5 item)) - (let ((beg (point)) - (where - (with-current-buffer buf - (cons - (nth 0 item) - (if ledger-clear-whole-entries - (save-excursion - (goto-line (nth 1 item)) - (point-marker)) - (save-excursion - (goto-line (nth 0 xact)) - (point-marker))))))) - (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))))) + (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))) + (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 [?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)) + "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))) + (use-local-map map))) (provide 'ldg-reconcile) \ No newline at end of file -- cgit v1.2.3 From 869c40c070a1abd8a02f8817a43cfc1488c0b1bc Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 7 Feb 2013 10:16:31 -0700 Subject: Reconcile visit now recanters on the xact selected --- lisp/ldg-reconcile.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 22ad5bc1..2d591de5 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -126,7 +126,8 @@ (let ((where (get-text-property (point) 'where))) (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) -- cgit v1.2.3 From 3b44a9fd2aec421eee2136088edd07efeb330f92 Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Fri, 8 Feb 2013 18:05:29 +0100 Subject: In ledger-reconcile, use a function to get where the transaction is. --- lisp/ldg-reconcile.el | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 2d591de5..04c84e63 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -53,14 +53,18 @@ (equal file "") (equal file "/dev/stdin"))) +(defun ledger-reconcile-get-buffer (where) + (when (is-stdin (car where)) + ledger-buf)) + (defun ledger-reconcile-toggle () (interactive) (let ((where (get-text-property (point) 'where)) (account ledger-acct) (inhibit-read-only t) cleared) - (when (is-stdin (car where)) - (with-current-buffer ledger-buf + (when (ledger-reconcile-get-buffer where) + (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (setq cleared (ledger-toggle-current-entry))) ;remove the existing face and add the new face @@ -112,8 +116,8 @@ (defun ledger-reconcile-delete () (interactive) (let ((where (get-text-property (point) 'where))) - (when (is-stdin (car where)) - (with-current-buffer ledger-buf + (when (ledger-reconcile-get-buffer where) + (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (ledger-delete-current-entry)) (let ((inhibit-read-only t)) @@ -124,8 +128,8 @@ (defun ledger-reconcile-visit () (interactive) (let ((where (get-text-property (point) 'where))) - (when (is-stdin (car where)) - (switch-to-buffer-other-window ledger-buf) + (when (ledger-reconcile-get-buffer where) + (switch-to-buffer-other-window (ledger-reconcile-get-buffer where)) (goto-char (cdr where)) (recenter)))) @@ -154,8 +158,8 @@ (let ((where (get-text-property (point) 'where)) (face (get-text-property (point) 'face))) (if (and (eq face 'bold) - (when (is-stdin (car where)))) - (with-current-buffer ledger-buf + (ledger-reconcile-get-buffer where)) + (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (ledger-toggle-current 'cleared)))) (forward-line 1))) @@ -298,4 +302,4 @@ (use-local-map map))) -(provide 'ldg-reconcile) \ No newline at end of file +(provide 'ldg-reconcile) -- cgit v1.2.3 From 21968b1e126df258842a6a45d2141f2923f7b023 Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Fri, 8 Feb 2013 18:16:57 +0100 Subject: In ledger-reconcile, open file where transaction are, and store it. --- lisp/ldg-reconcile.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 04c84e63..ae8de63f 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -169,10 +169,12 @@ "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)) + (let ((buf (if (is-stdin emacs-xact) + ledger-buf + (find-file-noselect (nth 0 item))))) (with-current-buffer buf ;use the ledger-buf buffer (cons - (nth 0 item) + buf (if ledger-clear-whole-entries ;determines whether to ;clear on the payee line ;or posting line -- cgit v1.2.3 From 0b63dc0f84236b30e771a7c3b9867cfc5a3965be Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Fri, 8 Feb 2013 18:17:55 +0100 Subject: In ledger-reconcile-get-buffer, return the stored buffer --- lisp/ldg-reconcile.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ae8de63f..2bdd6026 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -54,8 +54,8 @@ (equal file "/dev/stdin"))) (defun ledger-reconcile-get-buffer (where) - (when (is-stdin (car where)) - ledger-buf)) + (when (bufferp (car where)) + (car where))) (defun ledger-reconcile-toggle () (interactive) -- cgit v1.2.3 From e304cdfdbbd081e36925135f90b9ec052e8478ce Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Fri, 8 Feb 2013 18:35:14 +0100 Subject: After reconciling, save all buffer that need to be saved. --- lisp/ldg-reconcile.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 2bdd6026..ee87b1b8 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -22,6 +22,7 @@ ;; Reconcile mode (defvar ledger-buf nil) +(defvar ledger-bufs nil) (defvar ledger-acct nil) (defcustom ledger-recon-buffer-name "*Reconcile*" "Name to use for reconciliation window" @@ -135,8 +136,9 @@ (defun ledger-reconcile-save () (interactive) - (with-current-buffer ledger-buf - (save-buffer)) + (dolist (buf (cons ledger-buf ledger-bufs)) + (with-current-buffer buf + (save-buffer))) (set-buffer-modified-p nil) (ledger-display-balance)) @@ -199,12 +201,14 @@ (unless (looking-at "(") (error (buffer-string))) (read (current-buffer)))))) + (setq ledger-bufs ()) (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))) + (add-to-list 'ledger-bufs (car where)) (insert (format "%s %-4s %-30s %-30s %15s\n" (format-time-string "%Y/%m/%d" (nth 2 item)) (if (nth 3 item) -- cgit v1.2.3 From 8f214f38305d5b0b20ddb5da36bc9e4b8c183e23 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 8 Feb 2013 15:24:00 -0700 Subject: Revert "Merge pull request #147 from vanicat/t/where-are-transaction" This reverts commit 9a411e898acdd52e432ea84914467233e740c67e, reversing changes made to bdf404112e81b74a0cec668222c373150a0bc5ce. --- lisp/ldg-reconcile.el | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ee87b1b8..2d591de5 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -22,7 +22,6 @@ ;; Reconcile mode (defvar ledger-buf nil) -(defvar ledger-bufs nil) (defvar ledger-acct nil) (defcustom ledger-recon-buffer-name "*Reconcile*" "Name to use for reconciliation window" @@ -54,18 +53,14 @@ (equal file "") (equal file "/dev/stdin"))) -(defun ledger-reconcile-get-buffer (where) - (when (bufferp (car where)) - (car where))) - (defun ledger-reconcile-toggle () (interactive) (let ((where (get-text-property (point) 'where)) (account ledger-acct) (inhibit-read-only t) cleared) - (when (ledger-reconcile-get-buffer where) - (with-current-buffer (ledger-reconcile-get-buffer where) + (when (is-stdin (car where)) + (with-current-buffer ledger-buf (goto-char (cdr where)) (setq cleared (ledger-toggle-current-entry))) ;remove the existing face and add the new face @@ -117,8 +112,8 @@ (defun ledger-reconcile-delete () (interactive) (let ((where (get-text-property (point) 'where))) - (when (ledger-reconcile-get-buffer where) - (with-current-buffer (ledger-reconcile-get-buffer where) + (when (is-stdin (car where)) + (with-current-buffer ledger-buf (goto-char (cdr where)) (ledger-delete-current-entry)) (let ((inhibit-read-only t)) @@ -129,16 +124,15 @@ (defun ledger-reconcile-visit () (interactive) (let ((where (get-text-property (point) 'where))) - (when (ledger-reconcile-get-buffer where) - (switch-to-buffer-other-window (ledger-reconcile-get-buffer where)) + (when (is-stdin (car where)) + (switch-to-buffer-other-window ledger-buf) (goto-char (cdr where)) (recenter)))) (defun ledger-reconcile-save () (interactive) - (dolist (buf (cons ledger-buf ledger-bufs)) - (with-current-buffer buf - (save-buffer))) + (with-current-buffer ledger-buf + (save-buffer)) (set-buffer-modified-p nil) (ledger-display-balance)) @@ -160,8 +154,8 @@ (let ((where (get-text-property (point) 'where)) (face (get-text-property (point) 'face))) (if (and (eq face 'bold) - (ledger-reconcile-get-buffer where)) - (with-current-buffer (ledger-reconcile-get-buffer where) + (when (is-stdin (car where)))) + (with-current-buffer ledger-buf (goto-char (cdr where)) (ledger-toggle-current 'cleared)))) (forward-line 1))) @@ -171,12 +165,10 @@ "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 (if (is-stdin emacs-xact) - ledger-buf - (find-file-noselect (nth 0 item))))) + (let ((buf ledger-buf)) (with-current-buffer buf ;use the ledger-buf buffer (cons - buf + (nth 0 item) (if ledger-clear-whole-entries ;determines whether to ;clear on the payee line ;or posting line @@ -201,14 +193,12 @@ (unless (looking-at "(") (error (buffer-string))) (read (current-buffer)))))) - (setq ledger-bufs ()) (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))) - (add-to-list 'ledger-bufs (car where)) (insert (format "%s %-4s %-30s %-30s %15s\n" (format-time-string "%Y/%m/%d" (nth 2 item)) (if (nth 3 item) @@ -308,4 +298,4 @@ (use-local-map map))) -(provide 'ldg-reconcile) +(provide 'ldg-reconcile) \ No newline at end of file -- cgit v1.2.3 From e3be9686e4780778fe26124e37151009c8f66446 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 8 Feb 2013 17:02:58 -0700 Subject: Added vanicat's multii file extensions. There was a strange interact with some more recent parts of the code that exposed bugs I hadn't seen before. --- lisp/ldg-reconcile.el | 76 ++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 40 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 2d591de5..ed974a1e 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -22,6 +22,7 @@ ;; Reconcile mode (defvar ledger-buf nil) +(defvar ledger-bufs nil) (defvar ledger-acct nil) (defcustom ledger-recon-buffer-name "*Reconcile*" "Name to use for reconciliation window" @@ -53,17 +54,27 @@ (equal file "") (equal file "/dev/stdin"))) +(defun ledger-reconcile-get-buffer (where) +; (when (is-stdin (car where)) +; ledger-buf)) + (if (bufferp (car where)) + (car where) + (error "buffer not set"))) + + (defun ledger-reconcile-toggle () (interactive) (let ((where (get-text-property (point) 'where)) (account ledger-acct) (inhibit-read-only t) cleared) - (when (is-stdin (car where)) - (with-current-buffer ledger-buf +; (when (is-stdin (car where)) +; (with-current-buffer ledger-buf + (when (ledger-reconcile-get-buffer where) + (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (setq cleared (ledger-toggle-current-entry))) - ;remove the existing face and add the new face + ;remove the existing face and add the new face (remove-text-properties (line-beginning-position) (line-end-position) (list 'face)) @@ -112,8 +123,8 @@ (defun ledger-reconcile-delete () (interactive) (let ((where (get-text-property (point) 'where))) - (when (is-stdin (car where)) - (with-current-buffer ledger-buf + (when (ledger-reconcile-get-buffer where) + (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (ledger-delete-current-entry)) (let ((inhibit-read-only t)) @@ -123,16 +134,21 @@ (defun ledger-reconcile-visit () (interactive) - (let ((where (get-text-property (point) 'where))) - (when (is-stdin (car where)) - (switch-to-buffer-other-window ledger-buf) + (let* ((where (get-text-property (point) 'where)) + (target-buffer (ledger-reconcile-get-buffer + where))) + (when target-buffer + (switch-to-buffer-other-window target-buffer) (goto-char (cdr where)) (recenter)))) (defun ledger-reconcile-save () (interactive) - (with-current-buffer ledger-buf - (save-buffer)) +; (with-current-buffer ledger-buf +; (save-buffer)) + (dolist (buf (cons ledger-buf ledger-bufs)) + (with-current-buffer buf + (save-buffer))) (set-buffer-modified-p nil) (ledger-display-balance)) @@ -146,38 +162,19 @@ (if ledger-fold-on-reconcile (ledger-occur-quit-buffer buf)))) -(defun ledger-reconcile-finish () - (interactive) - (save-excursion - (goto-char (point-min)) - (while (not (eobp)) - (let ((where (get-text-property (point) 'where)) - (face (get-text-property (point) 'face))) - (if (and (eq face 'bold) - (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 + the emacs output from ledger, return the buffer and a marker + to the beginning of the xact in that buffer" + (let ((buf (if (is-stdin (nth 0 emacs-xact)) + ledger-buf + (find-file-noselect (nth 0 emacs-xact))))) + (with-current-buffer buf (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))))))) + buf + (save-excursion + (goto-line (nth 1 emacs-xact)) + (point-marker)))))) (defun ledger-do-reconcile () "get the uncleared transactions in the account and display them @@ -265,7 +262,6 @@ (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) -- cgit v1.2.3 From 5f67cfbec73863608639a7b8507191236cbac800 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 8 Feb 2013 17:16:12 -0700 Subject: Added ability to have ledger buffer track the xact under point in recon window controllable using ledger-buffer-tracks-reconcile-buffer --- lisp/ldg-reconcile.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ed974a1e..395266e3 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -24,6 +24,7 @@ (defvar ledger-buf nil) (defvar ledger-bufs nil) (defvar ledger-acct nil) + (defcustom ledger-recon-buffer-name "*Reconcile*" "Name to use for reconciliation window" :group 'ledger) @@ -33,6 +34,12 @@ matching the reconcile regex" :group 'ledger) +(defcustom ledger-buffer-tracks-reconcile-buffer t + "if t, then when the cursor is moved to a new xact in the recon + window, then that transaction will be shown in its source + buffer." + :group 'ledger) + (defun ledger-display-balance () "Calculate the cleared balance of the account being reconciled" (interactive) @@ -231,6 +238,22 @@ (select-window recon-window)))) +(defun ledger-reconcile-track-xact () + (if (or (eq this-command 'next-line) + (eq this-command 'previous-line) + (eq this-command 'mouse-set-point)) + (let* ((where (get-text-property (point) 'where)) + (target-buffer (ledger-reconcile-get-buffer + where)) + (cur-buf (current-buffer))) + (when target-buffer + (switch-to-buffer-other-window target-buffer) + (goto-char (cdr where)) + (recenter) + (switch-to-buffer-other-window cur-buf) + )))) + + (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") (let ((buf (current-buffer)) @@ -240,6 +263,7 @@ (quit-window (get-buffer-window rbuf)) (kill-buffer rbuf))) (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save) + (add-hook 'post-command-hook 'ledger-reconcile-track-xact) (if ledger-fold-on-reconcile (ledger-occur-mode account buf)) -- cgit v1.2.3 From 73f336ae7c89e6f1b5f38c32fe398f39ad3667b5 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 8 Feb 2013 22:49:39 -0700 Subject: Improved the visit function. Made the window position configurable. Removed after-save hook on quit --- lisp/ldg-reconcile.el | 115 ++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 54 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 395266e3..463eb9cf 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -40,6 +40,11 @@ buffer." :group 'ledger) +(defcustom ledger-reconcile-force-window-bottom nil + "If t make the reconcile window appear along the bottom of the + register window and resize" + :group 'ledger) + (defun ledger-display-balance () "Calculate the cleared balance of the account being reconciled" (interactive) @@ -62,8 +67,6 @@ (equal file "/dev/stdin"))) (defun ledger-reconcile-get-buffer (where) -; (when (is-stdin (car where)) -; ledger-buf)) (if (bufferp (car where)) (car where) (error "buffer not set"))) @@ -139,15 +142,19 @@ (delete-region (point) (1+ (line-end-position))) (set-buffer-modified-p t))))) -(defun ledger-reconcile-visit () - (interactive) - (let* ((where (get-text-property (point) 'where)) - (target-buffer (ledger-reconcile-get-buffer - where))) - (when target-buffer - (switch-to-buffer-other-window target-buffer) - (goto-char (cdr where)) - (recenter)))) +(defun ledger-reconcile-visit (&optional come-back) + (progn + (beginning-of-line) + (let* ((where (get-text-property (1+ (point)) 'where)) + (target-buffer (ledger-reconcile-get-buffer + where)) + (cur-buf (current-buffer))) + (when target-buffer + (switch-to-buffer-other-window target-buffer) + (goto-char (cdr where)) + (recenter) + (if come-back + (switch-to-buffer-other-window cur-buf)))))) (defun ledger-reconcile-save () (interactive) @@ -162,6 +169,9 @@ (defun ledger-reconcile-quit () (interactive) (let ((buf ledger-buf)) + (with-current-buffer ledger-buf + (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t)) + ;Make sure you delete the window before you delete the buffer, ;otherwise, madness ensues (delete-window (get-buffer-window (current-buffer))) @@ -198,25 +208,28 @@ (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))))) + (progn + (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))))) + (goto-char (point-max)) + (delete-char -1)) (insert (concat "There are no uncleared entries for " account))) (goto-char (point-min)) (set-buffer-modified-p nil) @@ -236,23 +249,16 @@ (goto-char (point-max)) (recenter -1)) - (select-window recon-window)))) + (select-window recon-window) + (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t) + (ledger-reconcile-visit t)))) (defun ledger-reconcile-track-xact () - (if (or (eq this-command 'next-line) - (eq this-command 'previous-line) - (eq this-command 'mouse-set-point)) - (let* ((where (get-text-property (point) 'where)) - (target-buffer (ledger-reconcile-get-buffer - where)) - (cur-buf (current-buffer))) - (when target-buffer - (switch-to-buffer-other-window target-buffer) - (goto-char (cdr where)) - (recenter) - (switch-to-buffer-other-window cur-buf) - )))) - + (if (member this-command (list 'next-line + 'previous-line + 'mouse-set-point + 'ledger-reconcile-toggle)) + (ledger-reconcile-visit t))) (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") @@ -262,18 +268,20 @@ (progn (quit-window (get-buffer-window rbuf)) (kill-buffer rbuf))) - (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save) - (add-hook 'post-command-hook 'ledger-reconcile-track-xact) + (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) (if ledger-fold-on-reconcile (ledger-occur-mode account buf)) - ;create the *Reconcile* window directly below the ledger buffer. (with-current-buffer - (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)) + (if ledger-reconcile-force-window-bottom + ;create the *Reconcile* window directly below the ledger + ;buffer. + (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)) + (pop-to-buffer (get-buffer-create ledger-recon-buffer-name))) (ledger-reconcile-mode) (set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-acct) account) @@ -286,7 +294,6 @@ (let ((map (make-sparse-keymap))) (define-key map [(control ?m)] 'ledger-reconcile-visit) (define-key map [return] 'ledger-reconcile-visit) - (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) -- cgit v1.2.3 From 73f8c10d8e65de56a5708f6a93da340861bd9646 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 8 Feb 2013 23:42:52 -0700 Subject: More reconcile-visit bug squashing. --- lisp/ldg-reconcile.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 463eb9cf..5314f554 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -32,17 +32,20 @@ (defcustom ledger-fold-on-reconcile t "if t, limit transactions shown in main buffer to those matching the reconcile regex" + :type 'boolean :group 'ledger) (defcustom ledger-buffer-tracks-reconcile-buffer t "if t, then when the cursor is moved to a new xact in the recon window, then that transaction will be shown in its source buffer." + :type 'boolean :group 'ledger) (defcustom ledger-reconcile-force-window-bottom nil "If t make the reconcile window appear along the bottom of the register window and resize" + :type 'boolean :group 'ledger) (defun ledger-display-balance () @@ -146,8 +149,9 @@ (progn (beginning-of-line) (let* ((where (get-text-property (1+ (point)) 'where)) - (target-buffer (ledger-reconcile-get-buffer - where)) + (target-buffer (if where + (ledger-reconcile-get-buffer where) + nil)) (cur-buf (current-buffer))) (when target-buffer (switch-to-buffer-other-window target-buffer) -- cgit v1.2.3 From 0f83f779a627964f7f9044afd383b7a9152545b9 Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Sat, 9 Feb 2013 14:42:52 +0100 Subject: On move event, save excursion before calling ledger-reconcile-visit Otherwise, ledger-reconcile-visit might undo last move --- lisp/ldg-reconcile.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 5314f554..e0ba1ea7 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -262,7 +262,8 @@ 'previous-line 'mouse-set-point 'ledger-reconcile-toggle)) - (ledger-reconcile-visit t))) + (save-excursion + (ledger-reconcile-visit t)))) (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") -- cgit v1.2.3 From 69efea6c543bb128422633239e7618f0d0eda6cf Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Sat, 9 Feb 2013 19:29:04 +0100 Subject: Take care to not delete some random buffer when exiting reconcile --- lisp/ldg-reconcile.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index e0ba1ea7..b475ebb7 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -172,14 +172,15 @@ (defun ledger-reconcile-quit () (interactive) - (let ((buf ledger-buf)) + (let ((buf ledger-buf) + (reconcile-buf (current-buffer))) (with-current-buffer ledger-buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t)) ;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)) + (delete-window (get-buffer-window reconcile-buf)) + (kill-buffer (reconcile-buf)) (if ledger-fold-on-reconcile (ledger-occur-quit-buffer buf)))) -- cgit v1.2.3 From 114be62d248723bfae12e383b168f364857d8793 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sat, 9 Feb 2013 17:47:09 -0700 Subject: Correct error that prevented clearing postings if ledger--clear-whole-entires was nil --- lisp/ldg-reconcile.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index e0ba1ea7..e5048a8c 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -81,12 +81,10 @@ (account ledger-acct) (inhibit-read-only t) cleared) -; (when (is-stdin (car where)) -; (with-current-buffer ledger-buf (when (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) - (setq cleared (ledger-toggle-current-entry))) + (setq cleared (ledger-toggle-current))) ;remove the existing face and add the new face (remove-text-properties (line-beginning-position) (line-end-position) @@ -146,6 +144,7 @@ (set-buffer-modified-p t))))) (defun ledger-reconcile-visit (&optional come-back) + (interactive) (progn (beginning-of-line) (let* ((where (get-text-property (1+ (point)) 'where)) @@ -162,8 +161,6 @@ (defun ledger-reconcile-save () (interactive) -; (with-current-buffer ledger-buf -; (save-buffer)) (dolist (buf (cons ledger-buf ledger-bufs)) (with-current-buffer buf (save-buffer))) @@ -194,7 +191,9 @@ (cons buf (save-excursion - (goto-line (nth 1 emacs-xact)) + (if ledger-clear-whole-entries + (goto-line (nth 1 emacs-xact)) + (goto-line (nth 0 (nth 5 emacs-xact)))) (point-marker)))))) (defun ledger-do-reconcile () @@ -262,8 +261,9 @@ 'previous-line 'mouse-set-point 'ledger-reconcile-toggle)) - (save-excursion - (ledger-reconcile-visit t)))) + (if ledger-buffer-tracks-reconcile-buffer + (save-excursion + (ledger-reconcile-visit t))))) (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") -- cgit v1.2.3 From 6fce572806eb39b5ba607bd5336adb6ca3ac2295 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sat, 9 Feb 2013 21:03:58 -0700 Subject: ledger-mode now highlights the xact under point. This can be configured with ledger-highlight-xact-under-point and ledger-font-highlight-face --- lisp/ldg-fonts.el | 5 +++++ lisp/ldg-mode.el | 6 ++++-- lisp/ldg-occur.el | 19 +------------------ lisp/ldg-reconcile.el | 1 + 4 files changed, 11 insertions(+), 20 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-fonts.el b/lisp/ldg-fonts.el index 6032e361..62192881 100644 --- a/lisp/ldg-fonts.el +++ b/lisp/ldg-fonts.el @@ -31,6 +31,11 @@ "Default face for cleared (*) transactions" :group 'ledger-faces) +(defface ledger-font-highlight-face + `((t :background "#003366" :weight normal )) + "Default face for transaction under point" + :group 'ledger-faces) + (defface ledger-font-pending-face `((t :foreground "yellow" :weight normal )) "Default face for pending (!) transactions" diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 83b5e5b4..a2c87048 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -60,6 +60,9 @@ customizable to ease retro-entry.") 'ledger-complete-at-point) (set (make-local-variable 'pcomplete-termination-string) "") + (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) + (make-variable-buffer-local 'highlight-overlay) + (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) @@ -114,8 +117,7 @@ customizable to ease retro-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)) - )) + (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." diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index d498b9e4..1afb0e90 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -208,23 +208,6 @@ When REGEX is nil, unhide everything, and remove higlight" 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 @@ -241,7 +224,7 @@ When REGEX is nil, unhide everything, and remove higlight" ;; if something found (when (setq endpoint (re-search-forward regex nil 'end)) (save-excursion - (let ((bounds (ledger-occur-find-xact-extents (match-beginning 0)))) + (let ((bounds (ledger-find-xact-extents (match-beginning 0)))) (push bounds lines) (setq curpoint (cadr bounds)))) ;move to the end of the ;xact, no need to search diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index e5048a8c..ed3fbcb5 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -156,6 +156,7 @@ (switch-to-buffer-other-window target-buffer) (goto-char (cdr where)) (recenter) + (ledger-highlight-xact-under-point) (if come-back (switch-to-buffer-other-window cur-buf)))))) -- cgit v1.2.3 From e757b969efd3dba04e2f0fbe21e88f4081f785b2 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 10 Feb 2013 09:47:56 -0700 Subject: fixe minor error in merge from vanicat --- lisp/ldg-reconcile.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index afecf2eb..3c258d13 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -178,7 +178,7 @@ ;Make sure you delete the window before you delete the buffer, ;otherwise, madness ensues (delete-window (get-buffer-window reconcile-buf)) - (kill-buffer (reconcile-buf)) + (kill-buffer reconcile-buf) (if ledger-fold-on-reconcile (ledger-occur-quit-buffer buf)))) -- cgit v1.2.3 From e245e41d6bfb1ef8799d9174e2bc5c6687880aa8 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 11 Feb 2013 10:50:13 -0700 Subject: Bug 887. Remove folding if the reconcile buffer is killed This ensure adequate cleanup if the reconciliation buffer is killed vice quit from. --- lisp/ldg-reconcile.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 3c258d13..5f023eb5 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -170,17 +170,25 @@ (defun ledger-reconcile-quit () (interactive) + ;(ledger-reconcile-quit-cleanup) (let ((buf ledger-buf) - (reconcile-buf (current-buffer))) - (with-current-buffer ledger-buf + (recon-buf (get-buffer ledger-recon-buffer-name))) + ;Make sure you delete the window before you delete the buffer, + ;otherwise, madness ensues + (with-current-buffer recon-buf + (delete-window (get-buffer-window recon-buf)) + (kill-buffer recon-buf)) + (set-window-buffer (selected-window) buf))) + +(defun ledger-reconcile-quit-cleanup () + (interactive) + (let ((buf ledger-buf) + (reconcile-buf (get-buffer ledger-recon-buffer-name))) + (with-current-buffer buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t)) - - ;Make sure you delete the window before you delete the buffer, - ;otherwise, madness ensues - (delete-window (get-buffer-window reconcile-buf)) - (kill-buffer reconcile-buf) (if ledger-fold-on-reconcile - (ledger-occur-quit-buffer buf)))) + (ledger-occur-quit-buffer buf)))) + (defun ledger-marker-where-xact-is (emacs-xact) "find the position of the xact in the ledger-buf buffer using @@ -330,6 +338,8 @@ (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))) + (use-local-map map) + + (add-hook 'kill-buffer-hook 'ledger-reconcile-quit-cleanup nil t))) (provide 'ldg-reconcile) \ No newline at end of file -- cgit v1.2.3 From fa1702d68458e400d57d61b5cbec20ec4027dbb7 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 11 Feb 2013 11:12:50 -0700 Subject: Bug 886 Cannot unclear transaction on last line reconciliation buffer --- lisp/ldg-reconcile.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 5f023eb5..a53f2ade 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -97,6 +97,7 @@ (line-end-position) (list 'face 'ledger-font-reconciler-uncleared-face )))) (forward-line) + (beginning-of-line) (ledger-display-balance))) (defun ledger-reconcile-new-account (account) -- cgit v1.2.3 From d243f00b914ba68380a51696f4ac68e066119a99 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 11 Feb 2013 12:49:51 -0700 Subject: Bug 878 Cannot reconcile two posting with the same account in one xact --- lisp/ldg-reconcile.el | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index a53f2ade..d00abe1a 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -190,8 +190,7 @@ (if ledger-fold-on-reconcile (ledger-occur-quit-buffer buf)))) - -(defun ledger-marker-where-xact-is (emacs-xact) +(defun ledger-marker-where-xact-is (emacs-xact posting) "find the position of the xact in the ledger-buf buffer using the emacs output from ledger, return the buffer and a marker to the beginning of the xact in that buffer" @@ -204,15 +203,15 @@ (save-excursion (if ledger-clear-whole-entries (goto-line (nth 1 emacs-xact)) - (goto-line (nth 0 (nth 5 emacs-xact)))) - (point-marker)))))) + (goto-line (nth 0 posting))) + (1+ (point-marker))))))) ;Add 1 to make sure the marker is within the transaction (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 + (xacts (with-temp-buffer (ledger-exec-ledger buf (current-buffer) "--uncleared" "--real" "emacs" account) @@ -221,20 +220,20 @@ (unless (looking-at "(") (error (buffer-string))) (read (current-buffer)))))) - (if (> (length items) 0) + (if (> (length xacts) 0) (progn - (dolist (item items) + (dolist (xact xacts) (let ((index 1)) - (dolist (xact (nthcdr 5 item)) + (dolist (posting (nthcdr 5 xact)) (let ((beg (point)) - (where (ledger-marker-where-xact-is item))) + (where (ledger-marker-where-xact-is xact posting))) (insert (format "%s %-4s %-30s %-30s %15s\n" - (format-time-string "%Y/%m/%d" (nth 2 item)) - (if (nth 3 item) - (nth 3 item) + (format-time-string "%Y/%m/%d" (nth 2 xact)) + (if (nth 3 xact) + (nth 3 xact) "") - (nth 4 item) (nth 1 xact) (nth 2 xact))) - (if (nth 3 xact) + (nth 4 xact) (nth 1 posting) (nth 2 posting))) + (if (nth 3 posting) (set-text-properties beg (1- (point)) (list 'face 'ledger-font-reconciler-cleared-face 'where where)) -- cgit v1.2.3 From 36a00113d9fbe8fe18ff3adb4c4be80291f7066d Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 11 Feb 2013 16:26:41 -0700 Subject: Bug 879 cannot reconcile two ledger buffers --- lisp/ldg-reconcile.el | 101 +++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 50 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index d00abe1a..d59185b1 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -74,7 +74,6 @@ (car where) (error "buffer not set"))) - (defun ledger-reconcile-toggle () (interactive) (let ((where (get-text-property (point) 'where)) @@ -100,15 +99,6 @@ (beginning-of-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) (let ((inhibit-read-only t) @@ -152,7 +142,7 @@ (target-buffer (if where (ledger-reconcile-get-buffer where) nil)) - (cur-buf (current-buffer))) + (cur-buf (get-buffer ledger-recon-buffer-name))) (when target-buffer (switch-to-buffer-other-window target-buffer) (goto-char (cdr where)) @@ -171,11 +161,11 @@ (defun ledger-reconcile-quit () (interactive) - ;(ledger-reconcile-quit-cleanup) + (ledger-reconcile-quit-cleanup) (let ((buf ledger-buf) (recon-buf (get-buffer ledger-recon-buffer-name))) - ;Make sure you delete the window before you delete the buffer, - ;otherwise, madness ensues + ;Make sure you delete the window before you delete the buffer, + ;otherwise, madness ensues (with-current-buffer recon-buf (delete-window (get-buffer-window recon-buf)) (kill-buffer recon-buf)) @@ -186,9 +176,9 @@ (let ((buf ledger-buf) (reconcile-buf (get-buffer ledger-recon-buffer-name))) (with-current-buffer buf - (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t)) - (if ledger-fold-on-reconcile - (ledger-occur-quit-buffer buf)))) + (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) + (if ledger-fold-on-reconcile + (ledger-occur-quit-buffer buf))))) (defun ledger-marker-where-xact-is (emacs-xact posting) "find the position of the xact in the ledger-buf buffer using @@ -219,11 +209,10 @@ (unless (eobp) (unless (looking-at "(") (error (buffer-string))) - (read (current-buffer)))))) + (read (current-buffer)))))) ;current-buffer is the *temp* created above (if (> (length xacts) 0) (progn (dolist (xact xacts) - (let ((index 1)) (dolist (posting (nthcdr 5 xact)) (let ((beg (point)) (where (ledger-marker-where-xact-is xact posting))) @@ -239,18 +228,17 @@ 'where where)) (set-text-properties beg (1- (point)) (list 'face 'ledger-font-reconciler-uncleared-face - 'where where)))) - (setq index (1+ index))))) + 'where where)))) )) (goto-char (point-max)) - (delete-char -1)) + (delete-char -1)) ;gets rid of the extra line feed at the bottom of the list (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 + ; 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. @@ -278,32 +266,44 @@ (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") (let ((buf (current-buffer)) - (rbuf (get-buffer ledger-recon-buffer-name))) - (if rbuf - (progn - (quit-window (get-buffer-window rbuf)) - (kill-buffer rbuf))) - (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) - (if ledger-fold-on-reconcile - (ledger-occur-mode account buf)) - - (with-current-buffer - (if ledger-reconcile-force-window-bottom - ;create the *Reconcile* window directly below the ledger - ;buffer. - (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)) - (pop-to-buffer (get-buffer-create ledger-recon-buffer-name))) - (ledger-reconcile-mode) - (set (make-local-variable 'ledger-buf) buf) - (set (make-local-variable 'ledger-acct) account) - (ledger-do-reconcile)))) + (rbuf (get-buffer ledger-recon-buffer-name))) ;this means only one *Reconcile* buffer, ever + (if rbuf ; *Reconcile* already exists + (with-current-buffer rbuf + (set 'ledger-acct account) ; already buffer local + (if (not (eq buf rbuf)) + (progn ; called from some other ledger-mode buffer + (ledger-reconcile-quit-cleanup) + (set 'ledger-buf buf))) ; should already be buffer-local + (if ledger-fold-on-reconcile + (ledger-occur-change-regex account ledger-buf)) + (set-buffer (get-buffer ledger-recon-buffer-name)) + (ledger-reconcile-refresh)) + + (progn ; no recon-buffer, starting from scratch. + (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) + (if ledger-fold-on-reconcile + (ledger-occur-mode account buf)) + + (with-current-buffer + (if ledger-reconcile-force-window-bottom + ;create the *Reconcile* window directly below the ledger buffer. + (progn + (set-window-buffer + (split-window (get-buffer-window buf) nil nil) + (get-buffer-create ledger-recon-buffer-name)) + (get-buffer ledger-recon-buffer-name)) + (pop-to-buffer (get-buffer-create ledger-recon-buffer-name))) + (ledger-reconcile-mode) + (set (make-local-variable 'ledger-buf) buf) + (set (make-local-variable 'ledger-acct) account) + (ledger-do-reconcile)))))) (defvar ledger-reconcile-mode-abbrev-table) +(defun ledger-reconcile-display-internals () + (interactive) + (message "%S %S" ledger-acct ledger-buf)) + (define-derived-mode ledger-reconcile-mode text-mode "Reconcile" "A mode for reconciling ledger entries." (let ((map (make-sparse-keymap))) @@ -313,12 +313,13 @@ (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 [?g] 'ledger-reconcile); (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 [?i] 'ledger-reconcile-display-internals) (define-key map [menu-bar] (make-sparse-keymap "ldg-recon-menu")) (define-key map [menu-bar ldg-recon-menu] (cons "Reconcile" map)) @@ -334,10 +335,10 @@ (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 rna] '("Reconcile New Account" . ledger-reconcile)) (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) (add-hook 'kill-buffer-hook 'ledger-reconcile-quit-cleanup nil t))) -- cgit v1.2.3 From e3b37ac19edfa5ff8e766258f38d1632b667848e Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 12 Feb 2013 10:35:27 -0700 Subject: Lisp code cleanup. Mostly went through and clarified variable names. Rather than "entry" for everything, use "transaction" and "posting" as appropriate to improve readability. --- lisp/ldg-complete.el | 28 +++++++++++++++------------- lisp/ldg-mode.el | 26 +++++++++++++------------- lisp/ldg-new.el | 4 ---- lisp/ldg-post.el | 5 ++--- lisp/ldg-reconcile.el | 23 ++++++++++++++++++++--- lisp/ldg-register.el | 2 +- lisp/ldg-report.el | 2 +- lisp/ldg-state.el | 16 ++++++++-------- 8 files changed, 60 insertions(+), 46 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index 996df558..b56a85ed 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -30,10 +30,10 @@ (goto-char (line-beginning-position)) (cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+") (goto-char (match-end 0)) - 'entry) + 'transaction) ((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\(.\\)") (goto-char (match-beginning 2)) - 'transaction) + 'posting) ((looking-at "^\\(sun\\|mon\\|tue\\|wed\\|thu\\|fri\\|sat\\)\\s-+") (goto-char (match-end 0)) 'entry) @@ -57,24 +57,26 @@ args))) (cons (reverse args) (reverse begins))))) -(defun ledger-entries () +(defun ledger-payees () (let ((origin (point)) - entries-list) + payees-list) (save-excursion (goto-char (point-min)) (while (re-search-forward (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" - "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) + "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) ;matches first line of transaction (unless (and (>= origin (match-beginning 0)) (< origin (match-end 0))) - (setq entries-list (cons (match-string-no-properties 3) - entries-list))))) - (pcomplete-uniqify-list (nreverse entries-list)))) + (setq payees-list (cons (match-string-no-properties 3) + payees-list))))) ;add the payee to the list + (pcomplete-uniqify-list (nreverse payees-list)))) (defvar ledger-account-tree nil) (defun ledger-find-accounts () - (let ((origin (point)) account-path elements) + (let ((origin (point)) + account-path + elements) (save-excursion (setq ledger-account-tree (list t)) (goto-char (point-min)) @@ -126,16 +128,16 @@ (interactive) (while (pcomplete-here (if (eq (save-excursion - (ledger-thing-at-point)) 'entry) + (ledger-thing-at-point)) 'transaction) (if (null current-prefix-arg) - (ledger-entries) ; this completes against entry names + (ledger-payees) ; this completes against payee 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) + (ledger-add-transaction text t) ((error) (insert text)))) (forward-line) @@ -151,7 +153,7 @@ (let ((name (caar (ledger-parse-arguments))) xacts) (save-excursion - (when (eq 'entry (ledger-thing-at-point)) + (when (eq 'transaction (ledger-thing-at-point)) (when (re-search-backward (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" (regexp-quote name) "\\(\t\\|\n\\| [ \t]\\)") nil t) diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 0ff22417..628b4b8a 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -70,8 +70,8 @@ customizable to ease retro-entry.") (make-variable-buffer-local 'highlight-overlay) (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 ?a)] 'ledger-add-transaction) + (define-key map [(control ?c) (control ?d)] 'ledger-delete-current-transaction) (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) @@ -119,8 +119,8 @@ customizable to ease retro-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 [delete-xact] '(menu-item "Delete Entry" ledger-delete-current-transaction)) + (define-key map [add-xact] '(menu-item "Add Transaction" ledger-add-transaction :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)))) @@ -140,13 +140,13 @@ Return the difference in the format of a time value." (defun ledger-find-slot (moment) (catch 'found - (ledger-iterate-entries + (ledger-iterate-transactions (function (lambda (start date mark desc) (if (ledger-time-less-p moment date) (throw 'found t))))))) -(defun ledger-iterate-entries (callback) +(defun ledger-iterate-transactions (callback) (goto-char (point-min)) (let* ((now (current-time)) (current-year (nth 5 (decode-time now)))) @@ -187,11 +187,11 @@ Return the difference in the format of a time value." (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) +(defun ledger-add-transaction (transaction-text &optional insert-at-point) (interactive (list - (read-string "Entry: " (concat ledger-year "/" ledger-month "/")))) + (read-string "Transaction: " (concat ledger-year "/" ledger-month "/")))) (let* ((args (with-temp-buffer - (insert entry-text) + (insert transaction-text) (eshell-parse-arguments (point-min) (point-max)))) (ledger-buf (current-buffer)) exit-code) @@ -208,7 +208,7 @@ Return the difference in the format of a time value." (insert (with-temp-buffer (setq exit-code - (apply #'ledger-exec-ledger ledger-buf ledger-buf "entry" + (apply #'ledger-exec-ledger ledger-buf ledger-buf "xact" (mapcar 'eval args))) (goto-char (point-min)) (if (looking-at "Error: ") @@ -219,7 +219,7 @@ Return the difference in the format of a time value." (insert (car args) " \n\n") (end-of-line -1))))) -(defun ledger-current-entry-bounds () +(defun ledger-current-transaction-bounds () (save-excursion (when (or (looking-at "^[0-9]") (re-search-backward "^[0-9]" nil t)) @@ -228,9 +228,9 @@ Return the difference in the format of a time value." (forward-line)) (cons (copy-marker beg) (point-marker)))))) -(defun ledger-delete-current-entry () +(defun ledger-delete-current-transaction () (interactive) - (let ((bounds (ledger-current-entry-bounds))) + (let ((bounds (ledger-current-transaction-bounds))) (delete-region (car bounds) (cdr bounds)))) (provide 'ldg-mode) diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index 3ee48897..ad21564a 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -47,10 +47,6 @@ (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-texi-update-test "ldg-texi" nil t) (autoload #'ledger-texi-update-examples "ldg-texi" nil t) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index ff664b1d..7b6ac9d5 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -158,7 +158,7 @@ This is done so that the last digit falls in COLUMN, which defaults to 52." (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)) ;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 + (let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;determine if there is an amount to edit (if end-of-amount (let ((val (match-string 0))) (goto-char (match-beginning 0)) @@ -171,8 +171,7 @@ This is done so that the last digit falls in COLUMN, which defaults to 52." (if (search-backward " " (- (point) 3) t) (goto-char (line-end-position)) (insert " ")) - (calc)) - )))) + (calc)))))) (defun ledger-post-prev-xact () (interactive) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index d59185b1..6179428f 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -119,7 +119,7 @@ (defun ledger-reconcile-add () (interactive) (with-current-buffer ledger-buf - (call-interactively #'ledger-add-entry)) + (call-interactively #'ledger-add-transaction)) (ledger-reconcile-refresh)) (defun ledger-reconcile-delete () @@ -128,7 +128,7 @@ (when (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) - (ledger-delete-current-entry)) + (ledger-delete-current-transaction)) (let ((inhibit-read-only t)) (goto-char (line-beginning-position)) (delete-region (point) (1+ (line-end-position))) @@ -159,6 +159,23 @@ (set-buffer-modified-p nil) (ledger-display-balance)) +(defun ledger-reconcile-finish () + "Mark all pending transactions as cleared, save the buffers and exit reconcile mode" + (interactive) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (let ((where (get-text-property (point) 'where)) + (face (get-text-property (point) 'face))) + (if (and (eq face 'bold) + (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-reconcile-quit () (interactive) (ledger-reconcile-quit-cleanup) @@ -191,7 +208,7 @@ (cons buf (save-excursion - (if ledger-clear-whole-entries + (if ledger-clear-whole-transactions (goto-line (nth 1 emacs-xact)) (goto-line (nth 0 posting))) (1+ (point-marker))))))) ;Add 1 to make sure the marker is within the transaction diff --git a/lisp/ldg-register.el b/lisp/ldg-register.el index adb37a1a..6e98f20d 100644 --- a/lisp/ldg-register.el +++ b/lisp/ldg-register.el @@ -51,7 +51,7 @@ (with-current-buffer data-buffer (cons (nth 0 post) - (if ledger-clear-whole-entries + (if ledger-clear-whole-transactions (save-excursion (goto-line (nth 1 post)) (point-marker)) diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index cdef6ded..2bb83516 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -216,7 +216,7 @@ end of a ledger file which is included in some other file." The user is prompted to enter a payee and that is substitued. If point is in an entry, the payee for that entry is used as the default." - ;; It is intended copmletion should be available on existing + ;; It is intended completion should be available on existing ;; payees, but the list of possible completions needs to be ;; developed to allow this. (ledger-read-string-with-default "Payee" (regexp-quote (ledger-entry-payee)))) diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index 41c0d8f2..ac0511f8 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -19,8 +19,8 @@ ;; 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." +(defcustom ledger-clear-whole-transactions nil + "If non-nil, clear whole transactions, not individual postings." :type 'boolean :group 'ledger) @@ -32,7 +32,7 @@ 'pending 'cleared))) -(defun ledger-entry-state () +(defun ledger-transaction-state () (save-excursion (when (or (looking-at "^[0-9]") (re-search-backward "^[0-9]" nil t)) @@ -42,13 +42,13 @@ ((looking-at "\\*\\s-*") 'cleared) (t nil))))) -(defun ledger-transaction-state () +(defun ledger-posting-state () (save-excursion (goto-char (line-beginning-position)) (skip-syntax-forward " ") (cond ((looking-at "!\\s-*") 'pending) ((looking-at "\\*\\s-*") 'cleared) - (t (ledger-entry-state))))) + (t (ledger-transaction-state))))) (defun ledger-toggle-current-transaction (&optional style) "Toggle the cleared status of the transaction under point. @@ -172,15 +172,15 @@ dropped." (defun ledger-toggle-current (&optional style) (interactive) - (if (or ledger-clear-whole-entries - (eq 'entry (ledger-thing-at-point))) + (if (or ledger-clear-whole-transactions + (eq 'transaction (ledger-thing-at-point))) (progn (save-excursion (forward-line) (goto-char (line-beginning-position)) (while (and (not (eolp)) (save-excursion - (not (eq 'entry (ledger-thing-at-point))))) + (not (eq 'transaction (ledger-thing-at-point))))) (if (looking-at "\\s-+[*!]") (ledger-toggle-current-transaction nil)) (forward-line) -- cgit v1.2.3 From 28659c58c3b0531e0f5fb01b298fcb8a8f63991e Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 12 Feb 2013 15:11:36 -0700 Subject: Bug 892 re-enable pending mode and reconcile-finish This should do it, and it should work across multiple files. --- lisp/ldg-mode.el | 2 +- lisp/ldg-reconcile.el | 49 ++++++++++++++++++--------- lisp/ldg-state.el | 93 +++++++++++++++++++++++++++++++-------------------- 3 files changed, 91 insertions(+), 53 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 628b4b8a..95b02fdd 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -75,7 +75,7 @@ customizable to ease retro-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 ?e)] 'ledger-toggle-current-transaction) (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) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 6179428f..61db2472 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -48,6 +48,12 @@ :type 'boolean :group 'ledger) +(defcustom ledger-reconcile-toggle-to-pending t + "if true then toggle between uncleared and pending. + reconcile-finish will mark all pending posting cleared. " + :type 'boolean + :group 'ledger) + (defun ledger-display-balance () "Calculate the cleared balance of the account being reconciled" (interactive) @@ -79,22 +85,29 @@ (let ((where (get-text-property (point) 'where)) (account ledger-acct) (inhibit-read-only t) - cleared) + status) (when (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) - (setq cleared (ledger-toggle-current))) + (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending + 'pending + 'cleared)))) ;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 'ledger-font-reconciler-cleared-face )) - (add-text-properties (line-beginning-position) - (line-end-position) - (list 'face 'ledger-font-reconciler-uncleared-face )))) + (cond ((eq status 'pending) + (add-text-properties (line-beginning-position) + (line-end-position) + (list 'face 'ledger-font-reconciler-pending-face ))) + ((eq status 'cleared) + (add-text-properties (line-beginning-position) + (line-end-position) + (list 'face 'ledger-font-reconciler-cleared-face ))) + (t + (add-text-properties (line-beginning-position) + (line-end-position) + (list 'face 'ledger-font-reconciler-uncleared-face ))))) (forward-line) (beginning-of-line) (ledger-display-balance))) @@ -167,9 +180,8 @@ (while (not (eobp)) (let ((where (get-text-property (point) 'where)) (face (get-text-property (point) 'face))) - (if (and (eq face 'bold) - (when (is-stdin (car where)))) - (with-current-buffer ledger-buf + (if (eq face 'ledger-font-reconciler-pending-face) + (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (ledger-toggle-current 'cleared)))) (forward-line 1))) @@ -240,9 +252,13 @@ "") (nth 4 xact) (nth 1 posting) (nth 2 posting))) (if (nth 3 posting) - (set-text-properties beg (1- (point)) - (list 'face 'ledger-font-reconciler-cleared-face - 'where where)) + (if (eq (nth 3 posting) 'pending) + (set-text-properties beg (1- (point)) + (list 'face 'ledger-font-reconciler-pending-face + 'where where)) + (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)))) )) @@ -327,6 +343,7 @@ (define-key map [(control ?m)] 'ledger-reconcile-visit) (define-key map [return] 'ledger-reconcile-visit) (define-key map [(control ?l)] 'ledger-reconcile-refresh) + (define-key map [(control ?c) (control ?c)] 'ledger-reconcile-finish) (define-key map [? ] 'ledger-reconcile-toggle) (define-key map [?a] 'ledger-reconcile-add) (define-key map [?d] 'ledger-reconcile-delete) @@ -353,6 +370,8 @@ (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)) + (define-key map [menu-bar ldg-recon-menu sep5] '("--")) + (define-key map [menu-bar ldg-recon-menu fin] '("Finish" . ledger-reconcile-finish)) (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)) diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index 443cb350..7c499d3e 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -50,11 +50,26 @@ ((looking-at "\\*\\s-*") 'cleared) (t (ledger-transaction-state))))) -(defun ledger-toggle-current-transaction (&optional style) +(defun ledger-char-from-state (state) + (if state + (if (eq state 'pending) + "!" + "*") + "")) + +(defun ledger-state-from-char (state-char) + (cond ((eql state-char ?\!) + 'pending) + ((eql state-char ?\*) + 'cleared) + (t + nil))) + +(defun ledger-toggle-current-posting (&optional style) "Toggle the cleared status of the transaction under point. Optional argument STYLE may be `pending' or `cleared', depending on which type of status the caller wishes to indicate (default is -`cleared'). +`cleared'). Returns the new status as 'pending 'cleared or nil. This function is rather complicated because it must preserve both the overall formatting of the ledger entry, as well as ensuring that the most minimal display format is used. This could be @@ -63,15 +78,16 @@ formatting, but doing so causes inline math expressions to be dropped." (interactive) (let ((bounds (ledger-current-transaction-bounds)) - clear cleared) + new-status cur-status) ;; Uncompact the entry, to make it easier to toggle the ;; transaction - (save-excursion - (goto-char (car bounds)) - (skip-chars-forward "0-9./= \t") - (setq cleared (and (member (char-after) '(?\* ?\!)) - (char-after))) - (when cleared + (save-excursion ;this excursion unclears the posting + (goto-char (car bounds)) ;beginning of xact + (skip-chars-forward "0-9./= \t") ;skip the date + (setq cur-status (and (member (char-after) '(?\* ?\!)) + (ledger-state-from-char (char-after)))) ;if the next char is !, * store it + ;;if cur-status if !, or * then delete the marker + (when cur-status (let ((here (point))) (skip-chars-forward "*! ") (let ((width (- (point) here))) @@ -82,17 +98,19 @@ dropped." (forward-line) (while (looking-at "[ \t]") (skip-chars-forward " \t") - (insert cleared " ") + (insert (ledger-char-from-state cur-status) " ") (if (search-forward " " (line-end-position) t) (delete-char 2)) - (forward-line)))) - ;; Toggle the individual transaction - (save-excursion + (forward-line)) + (setq new-status nil))) + + ;;this excursion marks the posting pending or cleared + (save-excursion (goto-char (line-beginning-position)) (when (looking-at "[ \t]") (skip-chars-forward " \t") (let ((here (point)) - (cleared (member (char-after) '(?\* ?\!)))) + (cur-status (ledger-state-from-char (char-after)))) (skip-chars-forward "*! ") (let ((width (- (point) here))) (when (> width 0) @@ -101,18 +119,18 @@ dropped." (if (search-forward " " (line-end-position) t) (insert (make-string width ? )))))) (let (inserted) - (if cleared + (if cur-status (if (and style (eq style 'cleared)) (progn (insert "* ") - (setq inserted t))) + (setq inserted 'cleared))) (if (and style (eq style 'pending)) (progn (insert "! ") - (setq inserted t)) + (setq inserted 'pending)) (progn (insert "* ") - (setq inserted t)))) + (setq inserted 'cleared)))) (if (and inserted (re-search-forward "\\(\t\\| [ \t]\\)" (line-end-position) t)) @@ -123,26 +141,25 @@ dropped." (delete-char 2)) ((looking-at " ") (delete-char 1)))) - (setq clear inserted))))) - ;; Clean up the entry so that it displays minimally + (setq new-status inserted))))) + + ;; This excursion cleans up the entry so that it displays minimally (save-excursion (goto-char (car bounds)) (forward-line) (let ((first t) - (state ? ) + (state nil) (hetero nil)) (while (and (not hetero) (looking-at "[ \t]")) (skip-chars-forward " \t") - (let ((cleared (if (member (char-after) '(?\* ?\!)) - (char-after) - ? ))) + (let ((cur-status (ledger-state-from-char (char-after)))) (if first - (setq state cleared + (setq state cur-status first nil) - (if (/= state cleared) + (if (not (eq state cur-status)) (setq hetero t)))) (forward-line)) - (when (and (not hetero) (/= state ? )) + (when (and (not hetero) (not (eq state nil))) (goto-char (car bounds)) (forward-line) (while (looking-at "[ \t]") @@ -158,7 +175,8 @@ dropped." (forward-line)) (goto-char (car bounds)) (skip-chars-forward "0-9./= \t") - (insert state " ") + (insert (ledger-char-from-state state) " ") + (setq new-status state) (if (re-search-forward "\\(\t\\| [ \t]\\)" (line-end-position) t) (cond @@ -168,7 +186,7 @@ dropped." (delete-char 2)) ((looking-at " ") (delete-char 1))))))) - clear)) + new-status)) (defun ledger-toggle-current (&optional style) (interactive) @@ -182,21 +200,22 @@ dropped." (save-excursion (not (eq 'transaction (ledger-thing-at-point))))) (if (looking-at "\\s-+[*!]") - (ledger-toggle-current-transaction nil)) + (ledger-toggle-current-transaction style)) (forward-line) (goto-char (line-beginning-position)))) - (ledger-toggle-current-entry style)) - (ledger-toggle-current-transaction style))) + (ledger-toggle-current-transaction style)) + (ledger-toggle-current-posting style))) -(defun ledger-toggle-current-entry (&optional style) +(defun ledger-toggle-current-transaction (&optional style) (interactive) - (let (clear) + (let (status) (save-excursion (when (or (looking-at "^[0-9]") (re-search-backward "^[0-9]" nil t)) (skip-chars-forward "0-9./=") (delete-horizontal-space) - (if (member (char-after) '(?\* ?\!)) + (if (or (eq (ledger-state-from-char (char-after)) 'pending) + (eq (ledger-state-from-char (char-after)) 'cleared)) (progn (delete-char 1) (if (and style (eq style 'cleared)) @@ -204,7 +223,7 @@ dropped." (if (and style (eq style 'pending)) (insert " ! ") (insert " * ")) - (setq clear t)))) - clear)) + (setq status t)))) + status)) (provide 'ldg-state) -- cgit v1.2.3 From 5eb322c0a29bcf2ddaa30bfaab577f18bb1fd922 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 12 Feb 2013 16:04:02 -0700 Subject: Comment and code cleanup --- lisp/ldg-complete.el | 7 ++++--- lisp/ldg-mode.el | 4 ++-- lisp/ldg-occur.el | 21 ++++++++++----------- lisp/ldg-post.el | 18 ++++++++++-------- lisp/ldg-reconcile.el | 35 ++++++++++++++++++++--------------- lisp/ldg-register.el | 3 +-- lisp/ldg-sort.el | 11 +++++++---- lisp/ldg-state.el | 8 ++++---- 8 files changed, 58 insertions(+), 49 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index b56a85ed..b841bae9 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -64,11 +64,12 @@ (goto-char (point-min)) (while (re-search-forward (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" - "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) ;matches first line of transaction + "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) ;; matches first line (unless (and (>= origin (match-beginning 0)) (< origin (match-end 0))) (setq payees-list (cons (match-string-no-properties 3) - payees-list))))) ;add the payee to the list + payees-list))))) ;; add the payee + ;; to the list (pcomplete-uniqify-list (nreverse payees-list)))) (defvar ledger-account-tree nil) @@ -130,7 +131,7 @@ (if (eq (save-excursion (ledger-thing-at-point)) 'transaction) (if (null current-prefix-arg) - (ledger-payees) ; this completes against payee names + (ledger-payees) ;; this completes against payee names (progn (let ((text (buffer-substring (line-beginning-position) (line-end-position)))) diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 95b02fdd..df277ee0 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -132,8 +132,8 @@ customizable to ease retro-entry.") (< (nth 1 t1) (nth 1 t2))))) (defun ledger-time-subtract (t1 t2) - "Subtract two time values. -Return the difference in the format of a time value." + "Subtract two time values. Return the difference in the format + of a time value." (let ((borrow (< (cadr t1) (cadr t2)))) (list (- (car t1) (car t2) (if borrow 1 0)) (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))) diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index bd5a49b1..d53be09b 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -125,14 +125,13 @@ When REGEX is nil, unhide everything, and remove higlight" (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 + (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) @@ -216,9 +215,9 @@ When REGEX is nil, unhide everything, and remove higlight" (save-excursion (let ((bounds (ledger-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 + (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))))) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 7b6ac9d5..099db1c2 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -63,8 +63,8 @@ (defun ledger-post-completing-read (prompt choices) "Use iswitchb as a completing-read replacement to choose from choices. -PROMPT is a string to prompt with. CHOICES is a list of strings -to choose from." + 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) @@ -113,7 +113,8 @@ to choose from." (defun ledger-align-amounts (&optional column) "Align amounts in the current region. -This is done so that the last digit falls in COLUMN, which defaults to 52." + This is done so that the last digit falls in COLUMN, which + defaults to 52." (interactive "p") (if (or (null column) (= column 1)) (setq column ledger-post-amount-alignment-column)) @@ -157,17 +158,18 @@ This is done so that the last digit falls in COLUMN, which defaults to 52." (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)) ;go to the and of the account - (let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;determine if there is an amount to edit + (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 there 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 + (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 " ")) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 61db2472..25d2e981 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -92,7 +92,7 @@ (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending 'pending 'cleared)))) - ;remove the existing face and add the new face + ;; remove the existing face and add the new face (remove-text-properties (line-beginning-position) (line-end-position) (list 'face)) @@ -193,8 +193,8 @@ (ledger-reconcile-quit-cleanup) (let ((buf ledger-buf) (recon-buf (get-buffer ledger-recon-buffer-name))) - ;Make sure you delete the window before you delete the buffer, - ;otherwise, madness ensues + ;; Make sure you delete the window before you delete the buffer, + ;; otherwise, madness ensues (with-current-buffer recon-buf (delete-window (get-buffer-window recon-buf)) (kill-buffer recon-buf)) @@ -223,7 +223,8 @@ (if ledger-clear-whole-transactions (goto-line (nth 1 emacs-xact)) (goto-line (nth 0 posting))) - (1+ (point-marker))))))) ;Add 1 to make sure the marker is within the transaction + (1+ (point-marker))))))) ;;Add 1 to make sure the marker is + ;;within the transaction (defun ledger-do-reconcile () "get the uncleared transactions in the account and display them @@ -269,11 +270,11 @@ (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. + ;; 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)))) @@ -299,20 +300,24 @@ (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") (let ((buf (current-buffer)) - (rbuf (get-buffer ledger-recon-buffer-name))) ;this means only one *Reconcile* buffer, ever - (if rbuf ; *Reconcile* already exists + (rbuf (get-buffer ledger-recon-buffer-name))) ;; this means + ;; only one + ;; *Reconcile* + ;; buffer, ever + (if rbuf ;; *Reconcile* already exists (with-current-buffer rbuf - (set 'ledger-acct account) ; already buffer local + (set 'ledger-acct account) ;; already buffer local (if (not (eq buf rbuf)) - (progn ; called from some other ledger-mode buffer + (progn ;; called from some other ledger-mode buffer (ledger-reconcile-quit-cleanup) - (set 'ledger-buf buf))) ; should already be buffer-local + (set 'ledger-buf buf))) ;; should already be + ;; buffer-local (if ledger-fold-on-reconcile (ledger-occur-change-regex account ledger-buf)) (set-buffer (get-buffer ledger-recon-buffer-name)) (ledger-reconcile-refresh)) - (progn ; no recon-buffer, starting from scratch. + (progn ;; no recon-buffer, starting from scratch. (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) (if ledger-fold-on-reconcile (ledger-occur-mode account buf)) diff --git a/lisp/ldg-register.el b/lisp/ldg-register.el index 6e98f20d..bfd8d360 100644 --- a/lisp/ldg-register.el +++ b/lisp/ldg-register.el @@ -69,8 +69,7 @@ (set-text-properties beg (1- (point)) (list 'where where)))) (setq index (1+ index))))) - (goto-char (point-min)) - ) + (goto-char (point-min))) (defun ledger-register-generate (&optional data-buffer &rest args) (let ((buf (or data-buffer (current-buffer)))) diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el index 86e3fa0a..8a1d9573 100644 --- a/lisp/ldg-sort.el +++ b/lisp/ldg-sort.el @@ -33,16 +33,19 @@ (forward-paragraph)) (defun ledger-sort-region (beg end) - (interactive "r") ;load beg and end from point and mark automagically + (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 + (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 + (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)) diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index 7c499d3e..1ede3312 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -81,11 +81,11 @@ dropped." new-status cur-status) ;; Uncompact the entry, to make it easier to toggle the ;; transaction - (save-excursion ;this excursion unclears the posting - (goto-char (car bounds)) ;beginning of xact - (skip-chars-forward "0-9./= \t") ;skip the date + (save-excursion ;; this excursion unclears the posting + (goto-char (car bounds)) ;; beginning of xact + (skip-chars-forward "0-9./= \t") ;; skip the date (setq cur-status (and (member (char-after) '(?\* ?\!)) - (ledger-state-from-char (char-after)))) ;if the next char is !, * store it + (ledger-state-from-char (char-after)))) ;;if cur-status if !, or * then delete the marker (when cur-status (let ((here (point))) -- cgit v1.2.3 From 24a9e422eb811224d4340905e68867181cb26861 Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Wed, 13 Feb 2013 15:54:01 +0100 Subject: In ledger-do-reconcile, don't act on windows when reconcile hasn't one Ledger-do-reconcile might be called indirectly (in the after-save-hook for example) and one might not want this buffer she has buried to show up again when she is saving another (even related) buffer. --- lisp/ldg-reconcile.el | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 25d2e981..03663b6b 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -276,17 +276,17 @@ ;; 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) - (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t) - (ledger-reconcile-visit t)))) + (let ((recon-window (get-buffer-window (get-buffer ledger-recon-buffer-name)))) + (when recon-window + (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) + (ledger-reconcile-visit t)) + (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t)))) (defun ledger-reconcile-track-xact () (if (member this-command (list 'next-line -- cgit v1.2.3 From 69673748017fdc9cfe99740d80a3184eef7ca163 Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Wed, 13 Feb 2013 17:03:48 +0100 Subject: Ensure that the reconcile buffer is shown when ledger-reconcile is called. --- lisp/ldg-reconcile.el | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 03663b6b..d295fd81 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -297,6 +297,15 @@ (save-excursion (ledger-reconcile-visit t))))) +(defun ledger-reconcile-open-windows (buf rbuf) + "Ensure that the reconcile buffer has its windows + +Spliting the windows of BUF if needed" + (if ledger-reconcile-force-window-bottom + ;;create the *Reconcile* window directly below the ledger buffer. + (set-window-buffer (split-window (get-buffer-window buf) nil nil) rbuf) + (pop-to-buffer rbuf))) + (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") (let ((buf (current-buffer)) @@ -315,6 +324,8 @@ (if ledger-fold-on-reconcile (ledger-occur-change-regex account ledger-buf)) (set-buffer (get-buffer ledger-recon-buffer-name)) + (unless (get-buffer-window rbuf) + (ledger-reconcile-open-windows buf rbuf)) (ledger-reconcile-refresh)) (progn ;; no recon-buffer, starting from scratch. @@ -322,19 +333,12 @@ (if ledger-fold-on-reconcile (ledger-occur-mode account buf)) - (with-current-buffer - (if ledger-reconcile-force-window-bottom - ;create the *Reconcile* window directly below the ledger buffer. - (progn - (set-window-buffer - (split-window (get-buffer-window buf) nil nil) - (get-buffer-create ledger-recon-buffer-name)) - (get-buffer ledger-recon-buffer-name)) - (pop-to-buffer (get-buffer-create ledger-recon-buffer-name))) + (with-current-buffer (get-buffer-create ledger-recon-buffer-name) + (ledger-reconcile-open-windows buf (current-buffer)) (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) -- cgit v1.2.3 From db9ae7dd042ecc49c2390b19a0670029cdb4e5fe Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 13 Feb 2013 09:36:44 -0700 Subject: Fixes workflow for using toggle-pending with clear-whole-transactions --- lisp/ldg-reconcile.el | 5 +++-- lisp/ldg-state.el | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 25d2e981..cae27a01 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -83,7 +83,6 @@ (defun ledger-reconcile-toggle () (interactive) (let ((where (get-text-property (point) 'where)) - (account ledger-acct) (inhibit-read-only t) status) (when (ledger-reconcile-get-buffer where) @@ -173,7 +172,9 @@ (ledger-display-balance)) (defun ledger-reconcile-finish () - "Mark all pending transactions as cleared, save the buffers and exit reconcile mode" + "Mark all pending posting or transactions as cleared, depending + on ledger-reconcile-clear-whole-transactions, save the buffers + and exit reconcile mode" (interactive) (save-excursion (goto-char (point-min)) diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index 1ede3312..fad7d71c 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -219,11 +219,16 @@ dropped." (progn (delete-char 1) (if (and style (eq style 'cleared)) - (insert " *"))) + (progn + (insert " *") + (setq status 'cleared)))) (if (and style (eq style 'pending)) - (insert " ! ") - (insert " * ")) - (setq status t)))) + (progn + (insert " ! ") + (setq status 'pending)) + (progn + (insert " * ") + (setq status 'cleared)))))) status)) (provide 'ldg-state) -- cgit v1.2.3 From 15d838d1f86b41e303e392d78eaac970311594cb Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 13 Feb 2013 13:23:04 -0700 Subject: Bug 893 Ledger reconcile loses alignment An earlier change to multi-file support stored the actual markers to the beginnings of the transaction/postings. When reconcile would insert characters it would invalidate those marker and after many items and been cleared could result in severe misalignment. This change brings back storing the line-numbers as reported by emacs. --- lisp/ldg-reconcile.el | 28 +++++++++++++--------------- lisp/ldg-xact.el | 2 ++ 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 822597f7..63ea522b 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -60,11 +60,11 @@ (let ((buffer ledger-buf) (account ledger-acct)) (with-temp-buffer - (ledger-exec-ledger buffer (current-buffer) "-C" "balance" account) + (ledger-exec-ledger buffer (current-buffer) "balance" "--limit" "cleared or pending" account) (goto-char (1- (point-max))) (goto-char (line-beginning-position)) (delete-horizontal-space) - (message "Cleared balance = %s" + (message "Current pending balance = %s" (buffer-substring-no-properties (point) (line-end-position)))))) @@ -87,7 +87,8 @@ status) (when (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where) - (goto-char (cdr where)) + (ledger-goto-line (cdr where)) + (forward-char) (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending 'pending 'cleared)))) @@ -139,7 +140,7 @@ (let ((where (get-text-property (point) 'where))) (when (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where) - (goto-char (cdr where)) + (ledger-goto-line (cdr where)) (ledger-delete-current-transaction)) (let ((inhibit-read-only t)) (goto-char (line-beginning-position)) @@ -157,7 +158,8 @@ (cur-buf (get-buffer ledger-recon-buffer-name))) (when target-buffer (switch-to-buffer-other-window target-buffer) - (goto-char (cdr where)) + (ledger-goto-line (cdr where)) + (forward-char) (recenter) (ledger-highlight-xact-under-point) (if come-back @@ -183,7 +185,7 @@ (face (get-text-property (point) 'face))) (if (eq face 'ledger-font-reconciler-pending-face) (with-current-buffer (ledger-reconcile-get-buffer where) - (goto-char (cdr where)) + (ledger-goto-line (cdr where)) (ledger-toggle-current 'cleared)))) (forward-line 1))) (ledger-reconcile-save)) @@ -217,15 +219,11 @@ (let ((buf (if (is-stdin (nth 0 emacs-xact)) ledger-buf (find-file-noselect (nth 0 emacs-xact))))) - (with-current-buffer buf - (cons - buf - (save-excursion - (if ledger-clear-whole-transactions - (goto-line (nth 1 emacs-xact)) - (goto-line (nth 0 posting))) - (1+ (point-marker))))))) ;;Add 1 to make sure the marker is - ;;within the transaction + (cons + buf + (if ledger-clear-whole-transactions + (nth 1 emacs-xact) ;; return line-no of xact + (nth 0 posting))))) ;; return line-no of posting (defun ledger-do-reconcile () "get the uncleared transactions in the account and display them diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index ab2c34f4..4b73b2ea 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -74,5 +74,7 @@ (ledger-context-field-value context-info 'payee) nil)))) +(defsubst ledger-goto-line (line-number) + (goto-char (point-min)) (forward-line (1- line-number))) (provide 'ldg-xact) \ No newline at end of file -- cgit v1.2.3 From d31913871fc2ca3ba26e12bb302df2dd93cdd3da Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 13 Feb 2013 15:53:16 -0700 Subject: Added rudimentary target checking to reconcile. --- doc/ledger3.texi | 12 ++++++- lisp/ldg-commodities.el | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ lisp/ldg-new.el | 2 ++ lisp/ldg-reconcile.el | 56 +++++++++++++++++++++++------ 4 files changed, 152 insertions(+), 11 deletions(-) create mode 100644 lisp/ldg-commodities.el (limited to 'lisp/ldg-reconcile.el') diff --git a/doc/ledger3.texi b/doc/ledger3.texi index a8f1d4b1..55732ceb 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -2542,7 +2542,7 @@ all of the uncleared transactions. The reconcile buffer has several functions: @table @code @item SPACE - toggles the cleared status of a transaction, and show cleared balance inthe minibuffer + toggles the cleared status of a transaction, and shows pending balance in the mini-buffer @item RETURN moves the cursor to that transaction in the ledger. @item C-x C-s @@ -2555,6 +2555,8 @@ all of the uncleared transactions. The reconcile buffer has several functions: add entry @item D delete entry + @item t + change target reconciliation amount @item g reconcile new account @item b @@ -2570,6 +2572,14 @@ show all transaction meeting the regex, cleared or not. This behavior can be disabled by setting @code{ledger-fold-on-reconcile} to nil in the emacs customization menus. +When you reconcile an account you nromally know the final balance you +are aiming at. When you enter the reconciliation mode ledger will ask +for a target balance. Enter the amount you are aiming for (the default +commodity can be chaged in the customization window). Each time you +toggle a posting to pending, ledger will calculate the new balance of +the account and display the new balance and the difference to make the +target. + @node Generating Reports, , Reconciling accounts, Using EMACS @subsection Generating Reports diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el new file mode 100644 index 00000000..94d2ddf0 --- /dev/null +++ b/lisp/ldg-commodities.el @@ -0,0 +1,93 @@ +;;; ldg-commodities.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. + + + + +;;; Commentary: +;; Helper functions to deal with commoditized numbers. A commoditized +;; number will be a cons of value and string where the string contains +;; the commodity + +;;; Code: + +(defcustom ledger-reconcile-default-commodity "$" + "the default commodity for use in target calculations in ledger reconcile" + :type 'string + :group 'ledger) + +(defun ledger-string-balance-to-commoditized-amount (str) + (let ((fields (split-string str "[\n\r]"))) ; break any balances + ; with multi commodities + ; into a list + (mapcar '(lambda (str) + (let* ((parts (split-string str)) ;break into number and commodity string + (first (car parts)) + (second (cadr parts))) + ;"^-*[1-9][0-9]*[.,][0-9]*" + (if (string-match "^-*[1-9]+" first) + (list (string-to-number first) second) + (list (string-to-number second) first)))) + fields))) + + +(defun -commodity (c1 c2) + (if (string= (cadr c1) (cadr c2)) + (list (- (car c1) (car c2)) (cadr c1)) + (error "Can't subtract different commodities %S from %S" c2 c1))) + +(defun +commodity (c1 c2) + (if (string= (cadr c1) (cadr c2)) + (list (+ (car c1) (car c2)) (cadr c1)) + (error "Can't add different commodities, %S to %S" c1 c2))) + +(defun ledger-commodity-to-string (c1) + (let ((val (number-to-string (car c1))) + (commodity (cadr c1))) + (if (> (length commodity) 1) + (concat val " " commodity) + (concat commodity " " val)))) + +(defun ledger-read-commodity-string (comm) + (interactive (list (read-from-minibuffer + (concat "Enter commoditized amount (" ledger-reconcile-default-commodity "): ")))) + (let ((parts (split-string comm))) + (if parts + (if (/= (length parts) 2) ;;assume a number was entered and use default commodity + (list (string-to-number (car parts)) + ledger-reconcile-default-commodity) + (let ((valp1 (string-to-number (car parts))) + (valp2 (string-to-number (cadr parts)))) + (cond ((and (= valp1 valp2) (= 0 valp1));; means neither contained a valid number (both = 0) + (list 0 "")) + ((and (/= 0 valp1) (= valp2 0)) + (list valp1 (cadr parts))) + ((and (/= 0 valp2) (= valp1 0)) + (list valp2 (car parts))) + (t + (error "cannot understand commodity")))))))) + +(provide 'ldg-commodities) + +;;; ldg-commodities.el ends here diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index ad21564a..3c56c108 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -46,6 +46,8 @@ (require 'ldg-sort) (require 'ldg-fonts) (require 'ldg-occur) +(require 'ldg-commodities) + (autoload #'ledger-texi-update-test "ldg-texi" nil t) (autoload #'ledger-texi-update-examples "ldg-texi" nil t) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 63ea522b..bb8d97f2 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -24,6 +24,7 @@ (defvar ledger-buf nil) (defvar ledger-bufs nil) (defvar ledger-acct nil) +(defvar ledger-target nil) (defcustom ledger-recon-buffer-name "*Reconcile*" "Name to use for reconciliation window" @@ -54,19 +55,42 @@ :type 'boolean :group 'ledger) -(defun ledger-display-balance () - "Calculate the cleared balance of the account being reconciled" + +(defun ledger-reconcile-get-balances () + "Calculate the cleared and uncleared balance of the account being reconciled, + return a list with the account, uncleared and cleared balances as numbers" (interactive) (let ((buffer ledger-buf) - (account ledger-acct)) + (account ledger-acct) + (val nil)) (with-temp-buffer - (ledger-exec-ledger buffer (current-buffer) "balance" "--limit" "cleared or pending" account) - (goto-char (1- (point-max))) - (goto-char (line-beginning-position)) - (delete-horizontal-space) - (message "Current pending balance = %s" - (buffer-substring-no-properties (point) - (line-end-position)))))) + (ledger-exec-ledger buffer (current-buffer) + ; note that in the line below, the --format option is + ; separated from the actual format string. emacs does not + ; split arguments like the shell does, so you need to + ; specify the individual fields in the command line. + "balance" "--limit" "cleared or pending" + "--format" "(\"%(amount)\")" account) + (setq val (read (buffer-substring-no-properties (point-min) (point-max))))))) + +(defun ledger-display-balance () + "Calculate the cleared balance of the account being reconciled" + (interactive) + (let* ((pending (car (ledger-string-balance-to-commoditized-amount + (car (ledger-reconcile-get-balances))))) + (target-delta (if ledger-target + (-commodity ledger-target pending) + nil))) + + (if target-delta + (message "Pending balance: %s, Difference from target: %s" + (ledger-commodity-to-string pending) + (ledger-commodity-to-string target-delta)) + (message "Pending balance: %s" + (ledger-commodity-to-string pending))))) + + + (defun is-stdin (file) "True if ledger file is standard input" @@ -323,6 +347,8 @@ Spliting the windows of BUF if needed" (if ledger-fold-on-reconcile (ledger-occur-change-regex account ledger-buf)) (set-buffer (get-buffer ledger-recon-buffer-name)) + (setq ledger-target + (call-interactively #'ledger-read-commodity-string)) (unless (get-buffer-window rbuf) (ledger-reconcile-open-windows buf rbuf)) (ledger-reconcile-refresh)) @@ -337,10 +363,18 @@ Spliting the windows of BUF if needed" (ledger-reconcile-mode) (set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-acct) account) + (set (make-local-variable 'ledger-target) + (call-interactively #'ledger-read-commodity-string)) (ledger-do-reconcile)))))) (defvar ledger-reconcile-mode-abbrev-table) +(defun ledger-reconcile-change-target () + (setq ledger-target (call-interactively #'ledger-read-commodity-string))) +; (setq ledger-target +; (if (and target (> (length target) 0)) +; (ledger-string-balance-to-commoditized-amount target)))) + (defun ledger-reconcile-display-internals () (interactive) (message "%S %S" ledger-acct ledger-buf)) @@ -358,6 +392,7 @@ Spliting the windows of BUF if needed" (define-key map [?g] 'ledger-reconcile); (define-key map [?n] 'next-line) (define-key map [?p] 'previous-line) + (define-key map [?t] 'ledger-reconcile-change-target) (define-key map [?s] 'ledger-reconcile-save) (define-key map [?q] 'ledger-reconcile-quit) (define-key map [?b] 'ledger-display-balance) @@ -376,6 +411,7 @@ Spliting the windows of BUF if needed" (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 tgt] '("Change Target Balance" . ledger-reconcile-change-target)) (define-key map [menu-bar ldg-recon-menu sep4] '("--")) (define-key map [menu-bar ldg-recon-menu rna] '("Reconcile New Account" . ledger-reconcile)) (define-key map [menu-bar ldg-recon-menu sep5] '("--")) -- cgit v1.2.3 From 30dc7e349db236d842cbe86fbf4972f0dbbbd10a Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 14 Feb 2013 10:05:53 -0700 Subject: Fix to target change function in leg-reconcile Took out the (interactive) statement and it needed to be there. --- lisp/ldg-reconcile.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index bb8d97f2..96a10afb 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -370,6 +370,7 @@ Spliting the windows of BUF if needed" (defvar ledger-reconcile-mode-abbrev-table) (defun ledger-reconcile-change-target () + (interactive) (setq ledger-target (call-interactively #'ledger-read-commodity-string))) ; (setq ledger-target ; (if (and target (> (length target) 0)) -- cgit v1.2.3 From d8f0b0fa83c6c6984f79dbb918e324a847cdb094 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 14 Feb 2013 15:37:13 -0700 Subject: Code commenting cleanup. --- lisp/ldg-commodities.el | 20 ++++++--- lisp/ldg-complete.el | 26 ++++++++---- lisp/ldg-exec.el | 18 ++++++-- lisp/ldg-fonts.el | 39 ++++++++++------- lisp/ldg-mode.el | 36 ++++++++++++---- lisp/ldg-new.el | 13 +++--- lisp/ldg-occur.el | 45 ++++++++++---------- lisp/ldg-post.el | 32 +++++++++++--- lisp/ldg-reconcile.el | 110 ++++++++++++++++++++++++++---------------------- lisp/ldg-report.el | 68 ++++++++++++++++++------------ lisp/ldg-sort.el | 15 +++++-- lisp/ldg-state.el | 25 +++++++++-- lisp/ldg-xact.el | 36 ++++++++++------ 13 files changed, 309 insertions(+), 174 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index 94d2ddf0..c007816d 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -33,11 +33,12 @@ ;;; Code: (defcustom ledger-reconcile-default-commodity "$" - "the default commodity for use in target calculations in ledger reconcile" + "The default commodity for use in target calculations in ledger reconcile." :type 'string :group 'ledger) (defun ledger-string-balance-to-commoditized-amount (str) + "Return a commoditized amount (val, 'comm') from STR." (let ((fields (split-string str "[\n\r]"))) ; break any balances ; with multi commodities ; into a list @@ -48,29 +49,36 @@ ;"^-*[1-9][0-9]*[.,][0-9]*" (if (string-match "^-*[1-9]+" first) (list (string-to-number first) second) - (list (string-to-number second) first)))) + (list (string-to-number second) first)))) fields))) (defun -commodity (c1 c2) - (if (string= (cadr c1) (cadr c2)) + "Subtract C2 from C1, ensuring their commodities match." + (if (string= (cadr c1) (cadr c2)) (list (- (car c1) (car c2)) (cadr c1)) (error "Can't subtract different commodities %S from %S" c2 c1))) (defun +commodity (c1 c2) + "Add C1 and C2, ensuring their commodities match." (if (string= (cadr c1) (cadr c2)) (list (+ (car c1) (car c2)) (cadr c1)) (error "Can't add different commodities, %S to %S" c1 c2))) (defun ledger-commodity-to-string (c1) - (let ((val (number-to-string (car c1))) + "Return string representing C1. +Single character commodities are placed ahead of the value, +longer one are after the value." +(let ((val (number-to-string (car c1))) (commodity (cadr c1))) (if (> (length commodity) 1) (concat val " " commodity) (concat commodity " " val)))) (defun ledger-read-commodity-string (comm) - (interactive (list (read-from-minibuffer + "Return a commoditizd value (val 'comm') from COMM. +Assumes a space between the value and the commodity." + (interactive (list (read-from-minibuffer (concat "Enter commoditized amount (" ledger-reconcile-default-commodity "): ")))) (let ((parts (split-string comm))) (if parts @@ -86,7 +94,7 @@ ((and (/= 0 valp2) (= valp1 0)) (list valp2 (car parts))) (t - (error "cannot understand commodity")))))))) + (error "Cannot understand commodity")))))))) (provide 'ldg-commodities) diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index a0508a98..82046e07 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -21,10 +21,16 @@ ;;(require 'esh-util) ;;(require 'esh-arg) + +;;; Commentary: +;; Functions providing payee and account auto complete. + (require 'pcomplete) ;; In-place completion support +;;; Code: + (defun ledger-parse-arguments () "Parse whitespace separated arguments in the current region." (let* ((info (save-excursion @@ -43,6 +49,7 @@ (cons (reverse args) (reverse begins))))) (defun ledger-payees-in-buffer () + "Scan buffer and return list of all payees." (let ((origin (point)) payees-list) (save-excursion @@ -58,9 +65,9 @@ (pcomplete-uniqify-list (nreverse payees-list)))) (defun ledger-find-accounts-in-buffer () - "search through buffer and build tree of accounts. Return tree - structure" - (let ((origin (point)) + "Search through buffer and build tree of accounts. +Return tree structure" + (let ((origin (point)) (account-tree (list t)) (account-elements nil)) (save-excursion @@ -69,8 +76,8 @@ "^[ \t]+\\([*!]\\s-+\\)?[[(]?\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)" nil t) (unless (and (>= origin (match-beginning 0)) (< origin (match-end 0))) - (setq account-elements - (split-string + (setq account-elements + (split-string (match-string-no-properties 2) ":")) (let ((root account-tree)) (while account-elements @@ -84,6 +91,7 @@ account-tree)) (defun ledger-accounts () + "Return a tree of all accounts in the buffer." (let* ((current (caar (ledger-parse-arguments))) (elements (and current (split-string current ":"))) (root (ledger-find-accounts-in-buffer)) @@ -110,7 +118,7 @@ 'string-lessp)))) (defun ledger-complete-at-point () - "Do appropriate completion for the thing at point" + "Do appropriate completion for the thing at point." (interactive) (while (pcomplete-here (if (eq (save-excursion @@ -134,8 +142,8 @@ (ledger-accounts))))) (defun ledger-fully-complete-entry () - "Completes a transaction if there is another matching payee in - the buffer. Does not use ledger xact" + "Completes a transaction if there is another matching payee in the buffer. +Does not use ledger xact" (interactive) (let ((name (caar (ledger-parse-arguments))) xacts) @@ -164,3 +172,5 @@ (goto-char (match-end 0)))))) (provide 'ldg-complete) + +;;; ldg-complete.el ends here diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el index e9cefd20..af5dd3a8 100644 --- a/lisp/ldg-exec.el +++ b/lisp/ldg-exec.el @@ -19,11 +19,17 @@ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. + +;;; Commentary: +;; Code for executing ledger synchronously. + +;;; Code: + (defconst ledger-version-needed "3.0.0" - "The version of ledger executable needed for interactive features") + "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") + "Flag showing whether the ledger binary can support `ledger-mode' interactive features.") (defgroup ledger-exec nil "Interface to the Ledger command-line accounting program." @@ -35,7 +41,7 @@ :group 'ledger) (defun ledger-exec-ledger (input-buffer &optional output-buffer &rest args) - "Run Ledger." + "Run Ledger using INPUT-BUFFER and optionally capturing output in OUTPUT-BUFFER with ARGS." (if (null ledger-binary-path) (error "The variable `ledger-binary-path' has not been set")) (let ((buf (or input-buffer (current-buffer))) @@ -51,6 +57,7 @@ outbuf))) (defun ledger-exec-read (&optional input-buffer &rest args) + "Run ledger from option INPUT-BUFFER using ARGS, return a list structure of the ledger Emacs output." (with-current-buffer (apply #'ledger-exec-ledger input-buffer nil "emacs" args) (goto-char (point-min)) @@ -59,7 +66,7 @@ (kill-buffer (current-buffer))))) (defun ledger-version-greater-p (needed) - "verify the ledger binary is usable for ledger-mode" + "Verify the ledger binary is usable for `ledger-mode' (version greater than NEEDED)." (let ((buffer ledger-buf) (version-strings '()) (version-number)) @@ -77,6 +84,7 @@ nil)))) (defun ledger-check-version () + "Verify that ledger works and is modern enough." (interactive) (setq ledger-works (ledger-version-greater-p ledger-version-needed)) (if ledger-works @@ -84,3 +92,5 @@ (message "Bad Ledger Version"))) (provide 'ldg-exec) + +;;; ldg-exec.el ends here diff --git a/lisp/ldg-fonts.el b/lisp/ldg-fonts.el index cf40c59d..d760140c 100644 --- a/lisp/ldg-fonts.el +++ b/lisp/ldg-fonts.el @@ -20,48 +20,54 @@ ;; MA 02111-1307, USA. + +;;; Commentary: +;; All of the faces for ledger mode are defined here. + +;;; Code: + (defgroup ledger-faces nil "Ledger mode highlighting" :group 'ledger) -(defface ledger-font-uncleared-face +(defface ledger-font-uncleared-face `((t :foreground "#dc322f" :weight bold )) "Default face for Ledger" :group 'ledger-faces) -(defface ledger-font-cleared-face +(defface ledger-font-cleared-face `((t :foreground "#657b83" :weight normal )) "Default face for cleared (*) transactions" :group 'ledger-faces) -(defface ledger-font-highlight-face +(defface ledger-font-highlight-face `((t :background "white")) "Default face for transaction under point" :group 'ledger-faces) -(defface ledger-font-pending-face +(defface ledger-font-pending-face `((t :foreground "#cb4b16" :weight normal )) "Default face for pending (!) transactions" :group 'ledger-faces) -(defface ledger-font-other-face +(defface ledger-font-other-face `((t :foreground "yellow" )) "Default face for other transactions" :group 'ledger-faces) -(defface ledger-font-posting-account-face +(defface ledger-font-posting-account-face `((t :foreground "#268bd2" )) "Face for Ledger accounts" :group 'ledger-faces) -(defface ledger-font-posting-amount-face +(defface ledger-font-posting-amount-face `((t :foreground "yellow" )) "Face for Ledger amounts" :group 'ledger-faces) -(defface ledger-occur-folded-face +(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 +(defface ledger-occur-xact-face `((t :background "#eee8d5" )) "Default face for Ledger occur mode shown transactions" :group 'ledger-faces) @@ -71,22 +77,22 @@ "Face for Ledger comments" :group 'ledger-faces) -(defface ledger-font-reconciler-uncleared-face +(defface ledger-font-reconciler-uncleared-face `((t :foreground "#dc322f" :weight bold )) "Default face for uncleared transactions in the reconcile window" :group 'ledger-faces) -(defface ledger-font-reconciler-cleared-face +(defface ledger-font-reconciler-cleared-face `((t :foreground "#657b83" :weight normal )) "Default face for cleared (*) transactions in the reconcile window" :group 'ledger-faces) -(defface ledger-font-reconciler-pending-face +(defface ledger-font-reconciler-pending-face `((t :foreground "#cb4b16" :weight normal )) "Default face for pending (!) transactions in the reconcile window" :group 'ledger-faces) -(defface ledger-font-report-clickable-face +(defface ledger-font-report-clickable-face `((t :foreground "#cb4b16" :weight normal )) "Default face for pending (!) transactions in the reconcile window" :group 'ledger-faces) @@ -95,7 +101,7 @@ (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) + ("^[0-9]+[-/.=][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)" 2 'ledger-font-uncleared-face) ("^\\s-+\\([*]\\s-*\\)?\\(\\([[(]\\)?[^*: ]+?:\\([^]); ]\\|\\s-\\)+?\\([])]\\)?\\)\\( \\| \\|$\\)" @@ -105,4 +111,7 @@ ("^\\([A-Za-z]+ .+\\)" 1 ledger-font-other-face)) "Expressions to highlight in Ledger mode.") -(provide 'ldg-fonts) \ No newline at end of file + +(provide 'ldg-fonts) + +;;; ldg-fonts.el ends here diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index fc018853..6cab7c9b 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -20,18 +20,24 @@ ;; MA 02111-1307, USA. + +;;; Commentary: +;; Most of the general ledger-mode code is here. + +;;; Code: + (defsubst ledger-current-year () + "The default current year for adding transactions." (format-time-string "%Y")) (defsubst ledger-current-month () + "The default current month for adding transactions." (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.") + "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.") + "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." @@ -39,7 +45,8 @@ customizable to ease retro-entry.") :group 'ledger) (defun ledger-remove-overlays () - (interactive) + "Remove all overlays from the ledger buffer." +(interactive) "remove overlays formthe buffer, used if the buffer is reverted" (remove-overlays)) @@ -135,13 +142,15 @@ customizable to ease retro-entry.") (< (nth 1 t1) (nth 1 t2))))) (defun ledger-time-subtract (t1 t2) - "Subtract two time values. Return the difference in the format - of a time value." + "Subtract two time values, T1 - T2. +Return the difference in the format of a time value." (let ((borrow (< (cadr t1) (cadr t2)))) (list (- (car t1) (car t2) (if borrow 1 0)) (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))) (defun ledger-find-slot (moment) + "Find the right place in the buffer for a transaction at MOMENT. +MOMENT is an encoded date" (catch 'found (ledger-iterate-transactions (function @@ -150,6 +159,7 @@ customizable to ease retro-entry.") (throw 'found t))))))) (defun ledger-iterate-transactions (callback) + "Iterate through each transaction call CALLBACK for each." (goto-char (point-min)) (let* ((now (current-time)) (current-year (nth 5 (decode-time now)))) @@ -177,20 +187,24 @@ customizable to ease retro-entry.") (forward-line)))) (defun ledger-set-year (newyear) - "Set ledger's idea of the current year to the prefix argument." + "Set ledger's idea of the current year to the prefix argument NEWYEAR." (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." + "Set ledger's idea of the current month to the prefix argument NEWMONTH." (interactive "p") (if (= newmonth 1) (setq ledger-month (read-string "Month: " (ledger-current-month))) (setq ledger-month (format "%02d" newmonth)))) (defun ledger-add-transaction (transaction-text &optional insert-at-point) + "Use ledger xact TRANSACTION-TEXT to add a transaction to the buffer. +If INSERT-AT-POINT is non-nil insert the transaction +there, otherwise call `ledger-find-slot' to insert it at the +correct chronological place in the buffer." (interactive (list (read-string "Transaction: " (concat ledger-year "/" ledger-month "/")))) (let* ((args (with-temp-buffer @@ -223,6 +237,7 @@ customizable to ease retro-entry.") (end-of-line -1))))) (defun ledger-current-transaction-bounds () + "Return markers for the beginning and end of transaction surrounding point." (save-excursion (when (or (looking-at "^[0-9]") (re-search-backward "^[0-9]" nil t)) @@ -232,8 +247,11 @@ customizable to ease retro-entry.") (cons (copy-marker beg) (point-marker)))))) (defun ledger-delete-current-transaction () + "Delete the transaction surrounging point." (interactive) (let ((bounds (ledger-current-transaction-bounds))) (delete-region (car bounds) (cdr bounds)))) (provide 'ldg-mode) + +;;; ldg-mode.el ends here diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index 3c56c108..ab267747 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -31,7 +31,7 @@ ;; MA 02111-1307, USA. ;;; Commentary: - +;; Load up the ledger mode (require 'ldg-complete) (require 'ldg-exec) (require 'ldg-mode) @@ -49,6 +49,8 @@ (require 'ldg-commodities) +;;; Code: + (autoload #'ledger-texi-update-test "ldg-texi" nil t) (autoload #'ledger-texi-update-examples "ldg-texi" nil t) @@ -57,13 +59,12 @@ :group 'data) (defconst ledger-version "3.0" - "The version of ledger.el currently loaded") - -(provide 'ledger) + "The version of ledger.el currently loaded.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun ledger-create-test () + "Create a regression test." (interactive) (save-restriction (org-narrow-to-subtree) @@ -87,4 +88,6 @@ (delete-char 3) (forward-line 1)))))) -;;; ledger.el ends here +(provide 'ledger) + +;;; ldg-new.el ends here diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index d53be09b..417a3d2a 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -25,7 +25,7 @@ ;;; Commentary: ;; Provide code folding to ledger mode. Adapted from original loccur ;; mode by Alexey Veretennikov +;; com> ;; ;; Adapted to ledger mode by Craig Earls @@ -34,8 +34,8 @@ (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" +(defcustom ledger-occur-use-face-unfolded t + "If non-nil use a custom face for xacts shown in `ledger-occur' mode." :type 'boolean :group 'ledger) (make-variable-buffer-local 'ledger-occur-use-face-unfolded) @@ -49,11 +49,11 @@ (list '(ledger-occur-mode ledger-occur-mode)))) (defvar ledger-occur-history nil - "History of previously searched expressions for the prompt") + "History of previously searched expressions for the prompt.") (make-variable-buffer-local 'ledger-occur-history) (defvar ledger-occur-last-match nil - "Last match found") + "Last match found.") (make-variable-buffer-local 'ledger-occur-last-match) (defvar ledger-occur-overlay-list nil @@ -61,12 +61,12 @@ (make-variable-buffer-local 'ledger-occur-overlay-list) (defun ledger-occur-mode (regex buffer) - "Higlight transaction that match REGEX, hiding others + "Highlight transactions that match REGEX in BUFFER, hiding others. When REGEX is nil, unhide everything, and remove higlight" (progn (set-buffer buffer) - (setq ledger-occur-mode + (setq ledger-occur-mode (if (or (null regex) (zerop (length regex))) nil @@ -76,7 +76,7 @@ When REGEX is nil, unhide everything, and remove higlight" (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 + (setq ledger-occur-overlay-list (ledger-occur-create-xact-overlays ovl-bounds)) (setq ledger-occur-overlay-list (append ledger-occur-overlay-list @@ -86,13 +86,12 @@ When REGEX is nil, unhide everything, and remove higlight" (recenter))) (defun ledger-occur (regex) - "Perform a simple grep in current buffer for the regular - expression 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 + those containing the regular expression REGEX. A second call of the function unhides lines again" - (interactive + (interactive (if ledger-occur-mode (list nil) (list (read-string (concat "Regexp<" (ledger-occur-prompt) @@ -101,7 +100,7 @@ When REGEX is nil, unhide everything, and remove higlight" (ledger-occur-mode regex (current-buffer))) (defun ledger-occur-prompt () - "Returns the default value of the prompt. + "Return the default value of the prompt. Default value for prompt is a current word or active region(selection), if its size is 1 line" @@ -129,7 +128,7 @@ When REGEX is nil, unhide everything, and remove higlight" ;; the last form in ;; the lambda is the ;; (make-overlay) - (setq prev-end (1+ (cadr match))) + (setq prev-end (1+ (cadr match))) ;; add 1 so that we skip the ;; empty line after the xact (make-overlay @@ -147,7 +146,9 @@ When REGEX is nil, unhide everything, and remove higlight" (defun ledger-occur-create-xact-overlays (ovl-bounds) - (let ((overlays + "Create the overlay for the visible transactions. +Argument OVL-BOUNDS contains bounds for the transactions to be left visible." + (let ((overlays (mapcar (lambda (bnd) (make-overlay (car bnd) @@ -161,8 +162,7 @@ When REGEX is nil, unhide everything, and remove higlight" overlays))) (defun ledger-occur-change-regex (regex buffer) - "use this function to programatically change the overlays, - rather than quitting out and restarting" + "Use this function to programatically change the overlays using REGEX in BUFFER, rather than quitting out and restarting." (progn (set-buffer buffer) (setq ledger-occur-mode nil) @@ -171,8 +171,8 @@ When REGEX is nil, unhide everything, and remove higlight" (recenter))) (defun ledger-occur-quit-buffer (buffer) - "quits hidings transaction in the given buffer. Used for - coordinating ledger-occur with other buffers, like reconcile" + "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) @@ -181,13 +181,15 @@ When REGEX is nil, unhide everything, and remove higlight" (recenter))) (defun ledger-occur-remove-overlays () + "Remove the transaction hiding overlays." (interactive) - (remove-overlays (point-min) + (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) + "Use BUFFER-MATCHES to produce the overlay for the visible transactions." (let ((prev-end (point-min)) (overlays (list))) (when buffer-matches @@ -199,8 +201,7 @@ When REGEX is nil, unhide everything, and remove higlight" (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" + "Return a list of 2-number tuples describing the beginning and start of transactions meeting REGEX." (save-excursion (goto-char (point-min)) ;; Set initial values for variables diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 8b0e3db6..bdbb4386 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -19,8 +19,14 @@ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. + +;;; Commentary: +;; Utility functions for dealing with postings. + (require 'ldg-regex) +;;; Code: + (defgroup ledger-post nil "" :group 'ledger) @@ -46,12 +52,13 @@ :group 'ledger-post) (defcustom ledger-post-use-decimal-comma nil - "if non-nil the use commas as decimal separator. This only has - effect interfacing to calc mode in edit amount" + "If non-nil the use commas as decimal separator. +This only has effect interfacing to calc mode in edit amount" :type 'boolean :group 'ledger-post) (defun ledger-post-all-accounts () + "Return a list of all accounts in the buffer." (let ((origin (point)) (ledger-post-list nil) account elements) @@ -68,8 +75,8 @@ (defvar iswitchb-temp-buflist) (defun ledger-post-completing-read (prompt choices) - "Use iswitchb as a completing-read replacement to choose from choices. - PROMPT is a string to prompt with. CHOICES is a list of + "Use iswitchb as a `completing-read' replacement to choose from choices. +PROMPT is a string to prompt with. CHOICES is a list of strings to choose from." (cond (ledger-post-use-iswitchb @@ -86,6 +93,7 @@ (defvar ledger-post-current-list nil) (defun ledger-post-pick-account () + "Insert an account entered by the user." (interactive) (let* ((account (ledger-post-completing-read @@ -111,6 +119,7 @@ (goto-char pos))) (defun ledger-next-amount (&optional end) + "Move point to the next amount, as long as it is not past END." (when (re-search-forward "\\( \\|\t\\| \t\\)[ \t]*-?\\([A-Z$€£]+ *\\)?\\(-?[0-9,]+?\\)\\(.[0-9]+\\)?\\( *[A-Z$€£]+\\)?\\([ \t]*@@?[^\n;]+?\\)?\\([ \t]+;.+?\\)?$" (marker-position end) t) (goto-char (match-beginning 0)) (skip-syntax-forward " ") @@ -119,7 +128,7 @@ (defun ledger-align-amounts (&optional column) "Align amounts in the current region. - This is done so that the last digit falls in COLUMN, which +This is done so that the last digit falls in COLUMN, which defaults to 52." (interactive "p") (if (or (null column) (= column 1)) @@ -146,6 +155,7 @@ (forward-line)))))) (defun ledger-post-align-amount () + "Align the amounts in this posting." (interactive) (save-excursion (set-mark (line-beginning-position)) @@ -153,6 +163,8 @@ (ledger-align-amounts))) (defun ledger-post-maybe-align (beg end len) + "Align amounts only if point is in a posting. +BEG, END, and LEN control how far it can align." (save-excursion (goto-char beg) (when (< end (line-end-position)) @@ -161,11 +173,12 @@ (ledger-post-align-amount))))) (defun ledger-post-edit-amount () + "Call 'calc-mode' and push the amount in the posting to the top of stack." (interactive) (goto-char (line-beginning-position)) - (when (re-search-forward ledger-post-line-regexp (line-end-position) t) + (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))) + (let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;; determine if there is an amount to edit (if end-of-amount (let ((val (match-string 0))) @@ -189,6 +202,7 @@ (calc)))))) (defun ledger-post-prev-xact () + "Move point to the previous transaction." (interactive) (backward-paragraph) (when (re-search-backward ledger-xact-line-regexp nil t) @@ -197,6 +211,7 @@ (goto-char (match-end ledger-regex-post-line-group-account)))) (defun ledger-post-next-xact () + "Move point to the next transaction." (interactive) (when (re-search-forward ledger-xact-line-regexp nil t) (goto-char (match-beginning 0)) @@ -204,8 +219,11 @@ (goto-char (match-end ledger-regex-post-line-group-account)))) (defun ledger-post-setup () + "Configure `ledger-mode' to auto-align postings." (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)))) (provide 'ldg-post) + +;;; ldg-post.el ends here diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 96a10afb..b632a070 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -21,60 +21,64 @@ ;; Reconcile mode + +;;; Commentary: +;; + +;;; Code: + (defvar ledger-buf nil) (defvar ledger-bufs nil) (defvar ledger-acct nil) (defvar ledger-target nil) (defcustom ledger-recon-buffer-name "*Reconcile*" - "Name to use for reconciliation window" + "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" +(defcustom ledger-fold-on-reconcile t + "If t, limit transactions shown in main buffer to those matching the reconcile regex." :type 'boolean :group 'ledger) (defcustom ledger-buffer-tracks-reconcile-buffer t - "if t, then when the cursor is moved to a new xact in the recon - window, then that transaction will be shown in its source - buffer." + "If t, then when the cursor is moved to a new xact in the recon window. +Then that transaction will be shown in its source buffer." :type 'boolean :group 'ledger) (defcustom ledger-reconcile-force-window-bottom nil - "If t make the reconcile window appear along the bottom of the - register window and resize" + "If t make the reconcile window appear along the bottom of the register window and resize." :type 'boolean :group 'ledger) (defcustom ledger-reconcile-toggle-to-pending t - "if true then toggle between uncleared and pending. - reconcile-finish will mark all pending posting cleared. " + "If true then toggle between uncleared and pending. +reconcile-finish will mark all pending posting cleared." :type 'boolean :group 'ledger) (defun ledger-reconcile-get-balances () - "Calculate the cleared and uncleared balance of the account being reconciled, - return a list with the account, uncleared and cleared balances as numbers" + "Calculate the cleared and uncleared balance of the account. +Return a list with the account, uncleared and cleared balances as +numbers" (interactive) (let ((buffer ledger-buf) (account ledger-acct) (val nil)) (with-temp-buffer - (ledger-exec-ledger buffer (current-buffer) + (ledger-exec-ledger buffer (current-buffer) ; note that in the line below, the --format option is ; separated from the actual format string. emacs does not ; split arguments like the shell does, so you need to ; specify the individual fields in the command line. - "balance" "--limit" "cleared or pending" + "balance" "--limit" "cleared or pending" "--format" "(\"%(amount)\")" account) (setq val (read (buffer-substring-no-properties (point-min) (point-max))))))) (defun ledger-display-balance () - "Calculate the cleared balance of the account being reconciled" + "Calculate the cleared balance of the account being reconciled." (interactive) (let* ((pending (car (ledger-string-balance-to-commoditized-amount (car (ledger-reconcile-get-balances))))) @@ -83,28 +87,30 @@ nil))) (if target-delta - (message "Pending balance: %s, Difference from target: %s" + (message "Pending balance: %s, Difference from target: %s" (ledger-commodity-to-string pending) (ledger-commodity-to-string target-delta)) - (message "Pending balance: %s" + (message "Pending balance: %s" (ledger-commodity-to-string pending))))) (defun is-stdin (file) - "True if ledger file is standard input" + "True if ledger FILE is standard input." (or (equal file "") (equal file "") (equal file "/dev/stdin"))) (defun ledger-reconcile-get-buffer (where) + "Return a buffer from WHERE the transaction is." (if (bufferp (car where)) (car where) - (error "buffer not set"))) + (error "Buffer not set"))) (defun ledger-reconcile-toggle () + "Toggle the current transaction, and mark the recon window." (interactive) (let ((where (get-text-property (point) 'where)) (inhibit-read-only t) @@ -113,7 +119,7 @@ (with-current-buffer (ledger-reconcile-get-buffer where) (ledger-goto-line (cdr where)) (forward-char) - (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending + (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending 'pending 'cleared)))) ;; remove the existing face and add the new face @@ -128,7 +134,7 @@ (add-text-properties (line-beginning-position) (line-end-position) (list 'face 'ledger-font-reconciler-cleared-face ))) - (t + (t (add-text-properties (line-beginning-position) (line-end-position) (list 'face 'ledger-font-reconciler-uncleared-face ))))) @@ -137,6 +143,7 @@ (ledger-display-balance))) (defun ledger-reconcile-refresh () + "Force the reconciliation window to refresh." (interactive) (let ((inhibit-read-only t) (line (count-lines (point-min) (point)))) @@ -147,6 +154,7 @@ (forward-line line))) (defun ledger-reconcile-refresh-after-save () + "Refresh the recon-window after the ledger buffer is saved." (let ((buf (get-buffer ledger-recon-buffer-name))) (if buf (with-current-buffer buf @@ -154,12 +162,14 @@ (set-buffer-modified-p nil))))) (defun ledger-reconcile-add () + "Use ledger xact to add a new transaction." (interactive) (with-current-buffer ledger-buf (call-interactively #'ledger-add-transaction)) (ledger-reconcile-refresh)) (defun ledger-reconcile-delete () + "Delete the transactions pointed to in the recon window." (interactive) (let ((where (get-text-property (point) 'where))) (when (ledger-reconcile-get-buffer where) @@ -172,11 +182,12 @@ (set-buffer-modified-p t))))) (defun ledger-reconcile-visit (&optional come-back) + "Recenter ledger buffer on transaction and COME-BACK if non-nil." (interactive) (progn (beginning-of-line) (let* ((where (get-text-property (1+ (point)) 'where)) - (target-buffer (if where + (target-buffer (if where (ledger-reconcile-get-buffer where) nil)) (cur-buf (get-buffer ledger-recon-buffer-name))) @@ -190,6 +201,7 @@ (switch-to-buffer-other-window cur-buf)))))) (defun ledger-reconcile-save () + "Save the ledger buffer." (interactive) (dolist (buf (cons ledger-buf ledger-bufs)) (with-current-buffer buf @@ -198,9 +210,9 @@ (ledger-display-balance)) (defun ledger-reconcile-finish () - "Mark all pending posting or transactions as cleared, depending - on ledger-reconcile-clear-whole-transactions, save the buffers - and exit reconcile mode" + "Mark all pending posting or transactions as cleared. +Depends on ledger-reconcile-clear-whole-transactions, save the buffers +and exit reconcile mode" (interactive) (save-excursion (goto-char (point-min)) @@ -216,6 +228,7 @@ (defun ledger-reconcile-quit () + "Quite the reconcile window without saving ledger buffer." (interactive) (ledger-reconcile-quit-cleanup) (let ((buf ledger-buf) @@ -228,18 +241,18 @@ (set-window-buffer (selected-window) buf))) (defun ledger-reconcile-quit-cleanup () + "Cleanup all hooks established by reconcile mode." (interactive) (let ((buf ledger-buf) (reconcile-buf (get-buffer ledger-recon-buffer-name))) (with-current-buffer buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) (if ledger-fold-on-reconcile - (ledger-occur-quit-buffer buf))))) + (ledger-occur-quit-buffer buf))))) (defun ledger-marker-where-xact-is (emacs-xact posting) - "find the position of the xact in the ledger-buf buffer using - the emacs output from ledger, return the buffer and a marker - to the beginning of the xact in that buffer" + "Find the position of the EMACS-XACT in the `ledger-buf'. +POSTING is used in `ledger-clear-whole-transactions' is nil." (let ((buf (if (is-stdin (nth 0 emacs-xact)) ledger-buf (find-file-noselect (nth 0 emacs-xact))))) @@ -250,13 +263,12 @@ (nth 0 posting))))) ;; return line-no of posting (defun ledger-do-reconcile () - "get the uncleared transactions in the account and display them - in the *Reconcile* buffer" + "Get the uncleared transactions in the account and display them in the *Reconcile* buffer." (let* ((buf ledger-buf) (account ledger-acct) (xacts - (with-temp-buffer - (ledger-exec-ledger buf (current-buffer) + (with-temp-buffer + (ledger-exec-ledger buf (current-buffer) "--uncleared" "--real" "emacs" account) (goto-char (point-min)) (unless (eobp) @@ -267,7 +279,7 @@ (progn (dolist (xact xacts) (dolist (posting (nthcdr 5 xact)) - (let ((beg (point)) + (let ((beg (point)) (where (ledger-marker-where-xact-is xact posting))) (insert (format "%s %-4s %-30s %-30s %15s\n" (format-time-string "%Y/%m/%d" (nth 2 xact)) @@ -278,13 +290,13 @@ (if (nth 3 posting) (if (eq (nth 3 posting) 'pending) (set-text-properties beg (1- (point)) - (list 'face 'ledger-font-reconciler-pending-face + (list 'face 'ledger-font-reconciler-pending-face 'where where)) (set-text-properties beg (1- (point)) - (list 'face 'ledger-font-reconciler-cleared-face + (list 'face 'ledger-font-reconciler-cleared-face 'where where))) (set-text-properties beg (1- (point)) - (list 'face 'ledger-font-reconciler-uncleared-face + (list 'face 'ledger-font-reconciler-uncleared-face 'where where)))) )) (goto-char (point-max)) (delete-char -1)) ;gets rid of the extra line feed at the bottom of the list @@ -312,6 +324,7 @@ (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t)))) (defun ledger-reconcile-track-xact () + "Force the ledger buffer to recenter on the transactionat point in the reconcile buffer." (if (member this-command (list 'next-line 'previous-line 'mouse-set-point @@ -321,15 +334,14 @@ (ledger-reconcile-visit t))))) (defun ledger-reconcile-open-windows (buf rbuf) - "Ensure that the reconcile buffer has its windows - -Spliting the windows of BUF if needed" + "Ensure that the ledger buffer BUF is split by RBUF." (if ledger-reconcile-force-window-bottom ;;create the *Reconcile* window directly below the ledger buffer. (set-window-buffer (split-window (get-buffer-window buf) nil nil) rbuf) (pop-to-buffer rbuf))) (defun ledger-reconcile (account) + "Start reconciling ACCOUNT." (interactive "sAccount to reconcile: ") (let ((buf (current-buffer)) (rbuf (get-buffer ledger-recon-buffer-name))) ;; this means @@ -339,7 +351,7 @@ Spliting the windows of BUF if needed" (if rbuf ;; *Reconcile* already exists (with-current-buffer rbuf (set 'ledger-acct account) ;; already buffer local - (if (not (eq buf rbuf)) + (if (not (eq buf rbuf)) (progn ;; called from some other ledger-mode buffer (ledger-reconcile-quit-cleanup) (set 'ledger-buf buf))) ;; should already be @@ -370,15 +382,9 @@ Spliting the windows of BUF if needed" (defvar ledger-reconcile-mode-abbrev-table) (defun ledger-reconcile-change-target () + "Change the traget amount for the reconciliation process." (interactive) (setq ledger-target (call-interactively #'ledger-read-commodity-string))) -; (setq ledger-target -; (if (and target (> (length target) 0)) -; (ledger-string-balance-to-commoditized-amount target)))) - -(defun ledger-reconcile-display-internals () - (interactive) - (message "%S %S" ledger-acct ledger-buf)) (define-derived-mode ledger-reconcile-mode text-mode "Reconcile" "A mode for reconciling ledger entries." @@ -397,7 +403,6 @@ Spliting the windows of BUF if needed" (define-key map [?s] 'ledger-reconcile-save) (define-key map [?q] 'ledger-reconcile-quit) (define-key map [?b] 'ledger-display-balance) - (define-key map [?i] 'ledger-reconcile-display-internals) (define-key map [menu-bar] (make-sparse-keymap "ldg-recon-menu")) (define-key map [menu-bar ldg-recon-menu] (cons "Reconcile" map)) @@ -424,4 +429,7 @@ Spliting the windows of BUF if needed" (add-hook 'kill-buffer-hook 'ledger-reconcile-quit-cleanup nil t))) -(provide 'ldg-reconcile) \ No newline at end of file +(provide 'ldg-reconcile) +(provide 'ldg-reconcile) + +;;; ldg-reconcile.el ends here diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 711af042..40e54935 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -19,6 +19,12 @@ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. + +;;; Commentary: +;; + +;;; Code: + (eval-when-compile (require 'cl)) @@ -34,7 +40,7 @@ contain format specifiers that are replaced with context sensitive information. Format specifiers have the format '%()' where is an identifier for the information to be replaced. The `ledger-report-format-specifiers' alist variable contains a mapping -from format specifier identifier to a lisp function that implements +from format specifier identifier to a Lisp function that implements the substitution. See the documentation of the individual functions in that variable for more information on the behavior of each specifier." @@ -46,7 +52,7 @@ specifier." '(("ledger-file" . ledger-report-ledger-file-format-specifier) ("payee" . ledger-report-payee-format-specifier) ("account" . ledger-report-account-format-specifier)) - "Alist mapping ledger report format specifiers to implementing functions + "An alist mapping ledger report format specifiers to implementing functions. The function is called with no parameters and expected to return the text that should replace the format specifier." @@ -121,13 +127,14 @@ The empty string and unknown names are allowed." (defun ledger-report (report-name edit) "Run a user-specified report from `ledger-reports'. -Prompts the user for the name of the report to run. If no name is -entered, the user will be prompted for a command line to run. The -command line specified or associated with the selected report name -is run and the output is made available in another buffer for viewing. -If a prefix argument is given and the user selects a valid report -name, the user is prompted with the corresponding command line for -editing before the command is run. +Prompts the user for the REPORT-NAME of the report to run or +EDIT. If no name is entered, the user will be prompted for a +command line to run. The command line specified or associated +with the selected report name is run and the output is made +available in another buffer for viewing. If a prefix argument is +given and the user selects a valid report name, the user is +prompted with the corresponding command line for editing before +the command is run. The output buffer will be in `ledger-report-mode', which defines commands for saving a new named report based on the command line @@ -159,11 +166,11 @@ used to generate the buffer, navigating the buffer, etc." (message "q to quit; r to redo; e to edit; k to kill; s to save; SPC and DEL to scroll")))) (defun string-empty-p (s) - "Check for the empty string." + "Check S for the empty string." (string-equal "" s)) (defun ledger-report-name-exists (name) - "Check to see if the given report name exists. + "Check to see if the given report NAME exists. If name exists, returns the object naming the report, otherwise returns nil." @@ -171,7 +178,7 @@ used to generate the buffer, navigating the buffer, etc." (car (assoc name ledger-reports)))) (defun ledger-reports-add (name cmd) - "Add a new report to `ledger-reports'." + "Add a new report NAME and CMD to `ledger-reports'." (setq ledger-reports (cons (list name cmd) ledger-reports))) (defun ledger-reports-custom-save () @@ -179,15 +186,15 @@ used to generate the buffer, navigating the buffer, etc." (customize-save-variable 'ledger-reports ledger-reports)) (defun ledger-report-read-command (report-cmd) - "Read the command line to create a report." + "Read the command line to create a report from REPORT-CMD." (read-from-minibuffer "Report command line: " (if (null report-cmd) "ledger " report-cmd) nil nil 'ledger-report-cmd-prompt-history)) (defun ledger-report-ledger-file-format-specifier () - "Substitute the full path to master or current ledger file + "Substitute the full path to master or current ledger file. - The master file name is determined by the ledger-master-file + The master file name is determined by the variable `ledger-master-file' buffer-local variable which can be set using file variables. If it is set, it is used, otherwise the current buffer file is used." @@ -201,7 +208,7 @@ used to generate the buffer, navigating the buffer, etc." "Return the master file for a ledger file. The master file is either the file for the current ledger buffer or the - file specified by the buffer-local variable ledger-master-file. Typically + file specified by the buffer-local variable `ledger-master-file'. Typically 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 @@ -209,6 +216,7 @@ used to generate the buffer, navigating the buffer, etc." (buffer-file-name))) (defun ledger-read-string-with-default (prompt default) + "Return user supplied string after PROMPT, or DEFAULT." (let ((default-prompt (concat prompt (if default (concat " (" default "): ") @@ -216,7 +224,7 @@ used to generate the buffer, navigating the buffer, etc." (read-string default-prompt nil nil default))) (defun ledger-report-payee-format-specifier () - "Substitute a payee name + "Substitute a payee name. The user is prompted to enter a payee and that is substitued. If point is in an entry, the payee for that entry is used as the @@ -227,7 +235,7 @@ used to generate the buffer, navigating the buffer, etc." (ledger-read-string-with-default "Payee" (regexp-quote (ledger-xact-payee)))) (defun ledger-report-account-format-specifier () - "Substitute an account name + "Substitute an account name. The user is prompted to enter an account name, which can be any regular expression identifying an account. If point is on an account @@ -243,6 +251,7 @@ used to generate the buffer, navigating the buffer, etc." (ledger-read-string-with-default "Account" default))) (defun ledger-report-expand-format-specifiers (report-cmd) + "Expand %(account) and %(payee) appearing in REPORT-CMD with thing under point." (save-match-data (let ((expanded-cmd report-cmd)) (set-match-data (list 0 0)) @@ -258,7 +267,8 @@ used to generate the buffer, navigating the buffer, etc." expanded-cmd))) (defun ledger-report-cmd (report-name edit) - "Get the command line to run the report." + "Get the command line to run the report name REPORT-NAME. +Optional EDIT the command." (let ((report-cmd (car (cdr (assoc report-name ledger-reports))))) ;; logic for substitution goes here (when (or (null report-cmd) edit) @@ -269,12 +279,12 @@ used to generate the buffer, navigating the buffer, etc." (or (string-empty-p report-name) (ledger-report-name-exists report-name) (progn - (ledger-reports-add report-name report-cmd) + (ledger-reports-add report-name report-cmd) (ledger-reports-custom-save))) report-cmd)) (defun ledger-do-report (cmd) - "Run a report command line." + "Run a report command line CMD." (goto-char (point-min)) (insert (format "Report: %s\n" ledger-report-name) (format "Command: %s\n" cmd) @@ -289,7 +299,8 @@ used to generate the buffer, navigating the buffer, etc." (if (and register-report (not (string-match "--subtotal" cmd))) (concat cmd " --prepend-format='%(filename):%(beg_line):'") - cmd) t nil) + cmd) + t nil) (when register-report (goto-char data-pos) (while (re-search-forward "^\\(/[^:]+\\)?:\\([0-9]+\\)?:" nil t) @@ -310,6 +321,7 @@ used to generate the buffer, navigating the buffer, etc." (defun ledger-report-visit-source () + "Visit the transaction under point in the report window." (interactive) (let* ((prop (get-text-property (point) 'ledger-source)) (file (if prop (car prop))) @@ -382,7 +394,7 @@ used to generate the buffer, navigating the buffer, etc." (setq ledger-report-name (ledger-report-read-new-name))) (if (setq existing-name (ledger-report-name-exists ledger-report-name)) - (cond ((y-or-n-p (format "Overwrite existing report named '%s' " + (cond ((y-or-n-p (format "Overwrite existing report named '%s'? " ledger-report-name)) (if (string-equal ledger-report-cmd @@ -395,7 +407,7 @@ used to generate the buffer, navigating the buffer, etc." (ledger-reports-custom-save)))) (t (progn - (setq ledger-report-name (ledger-report-read-new-name)) + (setq ledger-report-name (ledger-report-read-new-name)) (ledger-reports-add ledger-report-name ledger-report-cmd) (ledger-reports-custom-save))))))) @@ -424,9 +436,9 @@ used to generate the buffer, navigating the buffer, etc." (indent account)))))) (defun ledger-extract-context-info (line-type pos) - "Get context info for current line. + "Get context info for current line with LINE-TYPE. -Assumes point is at beginning of line, and the pos argument specifies +Assumes point is at beginning of line, and the POS argument specifies where the \"users\" point was." (let ((linfo (assoc line-type ledger-line-config)) found field fields) @@ -495,7 +507,7 @@ the fields in the line in a association list." '(unknown nil nil))))))) (defun ledger-context-other-line (offset) - "Return a list describing context of line offset for existing position. + "Return a list describing context of line OFFSET from existing position. Offset can be positive or negative. If run out of buffer before reaching specified line, returns nil." @@ -534,3 +546,5 @@ specified line, returns nil." (goto-char (ledger-context-field-end-position context-info field-name))) (provide 'ldg-report) + +;;; ldg-report.el ends here diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el index 8a1d9573..361eead8 100644 --- a/lisp/ldg-sort.el +++ b/lisp/ldg-sort.el @@ -19,10 +19,15 @@ ;; 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. + + +;;; Commentary: +;; + +;;; Code: (defun ledger-next-record-function () + "Move point to next transaction." (if (re-search-forward (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) @@ -30,9 +35,11 @@ (goto-char (point-max)))) (defun ledger-end-record-function () + "Move point to end of transaction." (forward-paragraph)) (defun ledger-sort-region (beg end) + "Sort the region from BEG to END in chronological order." (interactive "r") ;; load beg and end from point and mark ;; automagically (let ((new-beg beg) @@ -57,8 +64,10 @@ 'ledger-end-record-function)))))) (defun ledger-sort-buffer () + "Sort the entire buffer." (interactive) (ledger-sort-region (point-min) (point-max))) +(provide 'ldg-sort) -(provide 'ldg-sort) \ No newline at end of file +;;; ldg-sort.el ends here diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index fad7d71c..3e349e4e 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -19,12 +19,19 @@ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. + +;;; Commentary: +;; Utilities for dealing with transaction and posting status. + +;;; Code: + (defcustom ledger-clear-whole-transactions nil "If non-nil, clear whole transactions, not individual postings." :type 'boolean :group 'ledger) (defun ledger-toggle-state (state &optional style) + "Return the correct toggle state given the current STATE, and STYLE." (if (not (null state)) (if (and style (eq style 'cleared)) 'cleared) @@ -33,6 +40,7 @@ 'cleared))) (defun ledger-transaction-state () + "Return the state of the transaction at point." (save-excursion (when (or (looking-at "^[0-9]") (re-search-backward "^[0-9]" nil t)) @@ -43,6 +51,7 @@ (t nil))))) (defun ledger-posting-state () + "Return the state of the posting." (save-excursion (goto-char (line-beginning-position)) (skip-syntax-forward " ") @@ -51,6 +60,7 @@ (t (ledger-transaction-state))))) (defun ledger-char-from-state (state) + "Return the char representation of STATE." (if state (if (eq state 'pending) "!" @@ -58,6 +68,7 @@ "")) (defun ledger-state-from-char (state-char) + "Get state from STATE-CHAR." (cond ((eql state-char ?\!) 'pending) ((eql state-char ?\*) @@ -69,7 +80,7 @@ "Toggle the cleared status of the transaction under point. Optional argument STYLE may be `pending' or `cleared', depending on which type of status the caller wishes to indicate (default is -`cleared'). Returns the new status as 'pending 'cleared or nil. +`cleared'). Returns the new status as 'pending 'cleared or nil. This function is rather complicated because it must preserve both the overall formatting of the ledger entry, as well as ensuring that the most minimal display format is used. This could be @@ -87,7 +98,7 @@ dropped." (setq cur-status (and (member (char-after) '(?\* ?\!)) (ledger-state-from-char (char-after)))) ;;if cur-status if !, or * then delete the marker - (when cur-status + (when cur-status (let ((here (point))) (skip-chars-forward "*! ") (let ((width (- (point) here))) @@ -105,7 +116,7 @@ dropped." (setq new-status nil))) ;;this excursion marks the posting pending or cleared - (save-excursion + (save-excursion (goto-char (line-beginning-position)) (when (looking-at "[ \t]") (skip-chars-forward " \t") @@ -189,6 +200,7 @@ dropped." new-status)) (defun ledger-toggle-current (&optional style) + "Toggle the current thing at point with optional STYLE." (interactive) (if (or ledger-clear-whole-transactions (eq 'transaction (ledger-thing-at-point))) @@ -207,6 +219,7 @@ dropped." (ledger-toggle-current-posting style))) (defun ledger-toggle-current-transaction (&optional style) + "Toggle the transaction at point using optional STYLE." (interactive) (let (status) (save-excursion @@ -219,7 +232,7 @@ dropped." (progn (delete-char 1) (if (and style (eq style 'cleared)) - (progn + (progn (insert " *") (setq status 'cleared)))) (if (and style (eq style 'pending)) @@ -232,3 +245,7 @@ dropped." status)) (provide 'ldg-state) + +(provide 'ldg-state) + +;;; ldg-state.el ends here diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index a1c768ca..94a58542 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -19,19 +19,23 @@ ;; 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. + +;;; Commentary: +;; Utilites for running ledger synchronously. + +;;; Code: (defcustom ledger-highlight-xact-under-point t - "If t highlight xact under point" + "If t highlight xact under point." :type 'boolean :group 'ledger) (defvar highlight-overlay (list)) (defun ledger-find-xact-extents (pos) - "return point for beginning of xact and and of xact containing - position. Requires empty line separating xacts" + "Return point for beginning of xact and and of xact containing position. +Requires empty line separating xacts. Argument POS is a location +within the transaction." (interactive "d") (save-excursion (goto-char pos) @@ -49,7 +53,8 @@ (defun ledger-highlight-xact-under-point () - (if ledger-highlight-xact-under-point + "Move the highlight overlay to the current transaction." +(if ledger-highlight-xact-under-point (let ((exts (ledger-find-xact-extents (point))) (ovl highlight-overlay)) (if (not highlight-overlay) @@ -63,7 +68,7 @@ (overlay-put ovl 'priority 100)))) (defun ledger-xact-payee () - "Returns the payee of the entry containing point or nil." + "Return the payee of the entry containing point or nil." (let ((i 0)) (while (eq (ledger-context-line-type (ledger-context-other-line i)) 'acct-transaction) (setq i (- i 1))) @@ -73,10 +78,12 @@ nil)))) (defsubst ledger-goto-line (line-number) - (goto-char (point-min)) (forward-line (1- line-number))) + "Rapidly move point to line LINE-NUMBER." +(goto-char (point-min)) (forward-line (1- line-number))) (defun ledger-thing-at-point () - (let ((here (point))) + "Describe thing at points. Return 'transaction, 'posting, or nil." +(let ((here (point))) (goto-char (line-beginning-position)) (cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+") (goto-char (match-end 0)) @@ -91,9 +98,9 @@ (ignore (goto-char here)))))) (defun ledger-copy-transaction-at-point (date) - (interactive (list - (read-string "Copy to date: " - (concat ledger-year "/" ledger-month "/")))) + "Ask for a new DATE and copy the transaction under point to that date. Leave point on the first amount."(interactive (list + (read-string "Copy to date: " + (concat ledger-year "/" ledger-month "/")))) (let* ((here (point)) (extents (ledger-find-xact-extents (point))) (transaction (buffer-substring (car extents) (cadr extents))) @@ -112,4 +119,7 @@ -(provide 'ldg-xact) \ No newline at end of file +(provide 'ldg-xact) +(provide 'ldg-xact) + +;;; ldg-xact.el ends here -- cgit v1.2.3 From 089716fb13911ea6a1c044ed5d435809f9e2fff6 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 14 Feb 2013 19:38:42 -0700 Subject: Bug 894 Changing reconciliation account now repositions point in the Reconcile buffer correctly. --- lisp/ldg-reconcile.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index b632a070..ea8ff06e 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -74,7 +74,7 @@ numbers" ; split arguments like the shell does, so you need to ; specify the individual fields in the command line. "balance" "--limit" "cleared or pending" - "--format" "(\"%(amount)\")" account) + "--format" "(\"%(display_total)\")" account) (setq val (read (buffer-substring-no-properties (point-min) (point-max))))))) (defun ledger-display-balance () @@ -363,7 +363,8 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (call-interactively #'ledger-read-commodity-string)) (unless (get-buffer-window rbuf) (ledger-reconcile-open-windows buf rbuf)) - (ledger-reconcile-refresh)) + (ledger-reconcile-refresh) + (goto-char (point-min))) (progn ;; no recon-buffer, starting from scratch. (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) -- cgit v1.2.3 From 7f0693bcdc6829aaad100c52fcb16dacd89aed62 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 15 Feb 2013 06:14:33 -0700 Subject: Improved error reporting --- lisp/ldg-commodities.el | 6 ------ lisp/ldg-complete.el | 2 +- lisp/ldg-mode.el | 2 +- lisp/ldg-reconcile.el | 4 ++-- 4 files changed, 4 insertions(+), 10 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index c007816d..ab5c8898 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -19,12 +19,6 @@ ;; 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. - - - - ;;; Commentary: ;; Helper functions to deal with commoditized numbers. A commoditized ;; number will be a cons of value and string where the string contains diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index 82046e07..1836eb2c 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -132,7 +132,7 @@ Return tree structure" (line-end-position)) (condition-case err (ledger-add-transaction text t) - ((error) + ((error "ledger-complete-at-point") (insert text)))) (forward-line) (goto-char (line-end-position)) diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 6cab7c9b..6499d803 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -229,7 +229,7 @@ correct chronological place in the buffer." (mapcar 'eval args))) (goto-char (point-min)) (if (looking-at "Error: ") - (error (buffer-string)) + (error (concat "Error in ledger-add-transaction: " (buffer-string)) (buffer-string))) "\n")) (progn diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ea8ff06e..bb4bec5e 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -107,7 +107,7 @@ numbers" "Return a buffer from WHERE the transaction is." (if (bufferp (car where)) (car where) - (error "Buffer not set"))) + (error "ledger-reconcile-get-buffer: Buffer not set"))) (defun ledger-reconcile-toggle () "Toggle the current transaction, and mark the recon window." @@ -273,7 +273,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (goto-char (point-min)) (unless (eobp) (unless (looking-at "(") - (error (buffer-string))) + (error (concat "ledger-do-reconcile: " (buffer-string))) (read (current-buffer)))))) ;current-buffer is the *temp* created above (if (> (length xacts) 0) (progn -- cgit v1.2.3 From 8116ef478160364cde1b33429ae03c81a536ccbf Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 15 Feb 2013 08:07:41 -0700 Subject: Oops. This adds missing parenthesis to the last commit. --- lisp/ldg-mode.el | 2 +- lisp/ldg-reconcile.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 6499d803..01a1b615 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -229,7 +229,7 @@ correct chronological place in the buffer." (mapcar 'eval args))) (goto-char (point-min)) (if (looking-at "Error: ") - (error (concat "Error in ledger-add-transaction: " (buffer-string)) + (error (concat "Error in ledger-add-transaction: " (buffer-string))) (buffer-string))) "\n")) (progn diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index bb4bec5e..373b3de9 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -273,7 +273,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (goto-char (point-min)) (unless (eobp) (unless (looking-at "(") - (error (concat "ledger-do-reconcile: " (buffer-string))) + (error (concat "ledger-do-reconcile: " (buffer-string)))) (read (current-buffer)))))) ;current-buffer is the *temp* created above (if (> (length xacts) 0) (progn -- cgit v1.2.3 From d37a369c12f0f29bc00d87bb7ef75347c6c5dffe Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 15 Feb 2013 12:43:56 -0700 Subject: Changed prompt for reconciliation target. --- lisp/ldg-commodities.el | 7 +++---- lisp/ldg-reconcile.el | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index ab5c8898..cf2ee128 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -69,12 +69,11 @@ longer one are after the value." (concat val " " commodity) (concat commodity " " val)))) -(defun ledger-read-commodity-string (comm) +(defun ledger-read-commodity-string (prompt) "Return a commoditizd value (val 'comm') from COMM. Assumes a space between the value and the commodity." - (interactive (list (read-from-minibuffer - (concat "Enter commoditized amount (" ledger-reconcile-default-commodity "): ")))) - (let ((parts (split-string comm))) + (let ((parts (split-string (read-from-minibuffer + (concat prompt " (" ledger-reconcile-default-commodity "): "))))) (if parts (if (/= (length parts) 2) ;;assume a number was entered and use default commodity (list (string-to-number (car parts)) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 373b3de9..58cb6626 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -360,7 +360,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (ledger-occur-change-regex account ledger-buf)) (set-buffer (get-buffer ledger-recon-buffer-name)) (setq ledger-target - (call-interactively #'ledger-read-commodity-string)) + (ledger-read-commodity-string "Set reconciliation target")) (unless (get-buffer-window rbuf) (ledger-reconcile-open-windows buf rbuf)) (ledger-reconcile-refresh) @@ -377,7 +377,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-acct) account) (set (make-local-variable 'ledger-target) - (call-interactively #'ledger-read-commodity-string)) + (ledger-read-commodity-string "Set reconciliation target")) (ledger-do-reconcile)))))) (defvar ledger-reconcile-mode-abbrev-table) @@ -385,7 +385,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (defun ledger-reconcile-change-target () "Change the traget amount for the reconciliation process." (interactive) - (setq ledger-target (call-interactively #'ledger-read-commodity-string))) + (setq ledger-target (ledger-read-commodity-string "Set reconciliation target"))) (define-derived-mode ledger-reconcile-mode text-mode "Reconcile" "A mode for reconciling ledger entries." -- cgit v1.2.3 From 2c69aa1ff5759a38f458dda69a7b1f6e49294cd0 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 17 Feb 2013 19:47:16 -0700 Subject: A better try to deal with decimal-comma from ledger --- lisp/ldg-commodities.el | 46 ++++++++++++++++++++++++++++++++++++++-------- lisp/ldg-complete.el | 4 ++-- lisp/ldg-post.el | 8 +------- lisp/ldg-reconcile.el | 2 +- lisp/ldg-report.el | 20 +++++++++----------- 5 files changed, 51 insertions(+), 29 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index cf2ee128..04dc23de 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -31,6 +31,12 @@ :type 'string :group 'ledger) +(defcustom ledger-use-decimal-comma nil + "If non-nil the use commas as decimal separator. +This only has effect interfacing to calc mode in edit amount" + :type 'boolean + :group 'ledger) + (defun ledger-string-balance-to-commoditized-amount (str) "Return a commoditized amount (val, 'comm') from STR." (let ((fields (split-string str "[\n\r]"))) ; break any balances @@ -40,10 +46,11 @@ (let* ((parts (split-string str)) ;break into number and commodity string (first (car parts)) (second (cadr parts))) - ;"^-*[1-9][0-9]*[.,][0-9]*" (if (string-match "^-*[1-9]+" first) - (list (string-to-number first) second) - (list (string-to-number second) first)))) + (list (string-to-number + (ledger-commodity-string-number-decimalize first :from-user)) second) + (list (string-to-number + (ledger-commodity-string-number-decimalize second :from-user)) first)))) fields))) @@ -59,15 +66,38 @@ (list (+ (car c1) (car c2)) (cadr c1)) (error "Can't add different commodities, %S to %S" c1 c2))) +(defun ledger-commodity-string-number-decimalize (number-string direction) + "Take NUMBER-STRING and ensure proper decimalization for use by string-to-number and number-to-string. + +DIRECTION can be :to-user or :from-user. All math calculations +are done with decimal-period, some users may prefer decimal-comma +which must be translated both directions." + (let ((val number-string)) + (if ledger-use-decimal-comma + (cond ((eq direction :from-user) + ;; change string to decimal-period + (while (string-match "," val) + (setq val (replace-match "." nil nil val)))) ;; switch to period separator + ((eq direction :to-user) + ;; change to decimal-comma + (while (string-match "\\." val) + (setq val (replace-match "," nil nil val)))) ;; gets rid of periods + (t + (error "ledger-commodity-string-number-decimalize: direction not properly specified %S" direction)))) + val)) + + + (defun ledger-commodity-to-string (c1) "Return string representing C1. Single character commodities are placed ahead of the value, longer one are after the value." -(let ((val (number-to-string (car c1))) - (commodity (cadr c1))) - (if (> (length commodity) 1) - (concat val " " commodity) - (concat commodity " " val)))) +(let ((val (ledger-commodity-string-number-decimalize + (number-to-string (car c1)) :to-user)) + (commodity (cadr c1))) + (if (> (length commodity) 1) + (concat val " " commodity) + (concat commodity " " val)))) (defun ledger-read-commodity-string (prompt) "Return a commoditizd value (val 'comm') from COMM. diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index 3fd1b319..3686d0fd 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -164,10 +164,10 @@ Does not use ledger xact" xacts)) (forward-line)) (setq xacts (nreverse xacts))))) + ;; Insert rest-of-name and the postings (when xacts (save-excursion - (insert rest-of-name) - (insert ?\n) + (insert rest-of-name ?\n) (while xacts (insert (car xacts) ?\n) (setq xacts (cdr xacts)))) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index bdbb4386..14c3c55f 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -51,12 +51,6 @@ :type 'boolean :group 'ledger-post) -(defcustom ledger-post-use-decimal-comma nil - "If non-nil the use commas as decimal separator. -This only has effect interfacing to calc mode in edit amount" - :type 'boolean - :group 'ledger-post) - (defun ledger-post-all-accounts () "Return a list of all accounts in the buffer." (let ((origin (point)) @@ -185,7 +179,7 @@ BEG, END, and LEN control how far it can align." (goto-char (match-beginning 0)) (delete-region (match-beginning 0) (match-end 0)) (calc) - (if ledger-post-use-decimal-comma + (if ledger-use-decimal-comma (progn (while (string-match "\\." val) (setq val (replace-match "" nil nil val))) ;; gets rid of periods diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 58cb6626..20857127 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -81,7 +81,7 @@ numbers" "Calculate the cleared balance of the account being reconciled." (interactive) (let* ((pending (car (ledger-string-balance-to-commoditized-amount - (car (ledger-reconcile-get-balances))))) + (car (ledger-reconcile-get-balances))))) (target-delta (if ledger-target (-commodity ledger-target pending) nil))) diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 370117fc..944ae2e6 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -21,7 +21,7 @@ ;;; Commentary: -;; +;; Provide facilities for running and saving reports in emacs ;;; Code: @@ -51,7 +51,8 @@ specifier." (defcustom ledger-report-format-specifiers '(("ledger-file" . ledger-report-ledger-file-format-specifier) ("payee" . ledger-report-payee-format-specifier) - ("account" . ledger-report-account-format-specifier)) + ("account" . ledger-report-account-format-specifier) + ("value" . ledger-report-value-format-specifier)) "An alist mapping ledger report format specifiers to implementing functions. The function is called with no parameters and expected to return the @@ -59,15 +60,6 @@ text that should replace the format specifier." :type 'alist :group 'ledger) -;;(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) - -;; Ledger report mode - (defvar ledger-report-buffer-name "*Ledger Report*") (defvar ledger-report-name nil) @@ -128,6 +120,12 @@ text that should replace the format specifier." (use-local-map map))) +(defun ledger-report-value-format-specifier () + "Return a valid meta-data tag name" + ;; It is intended completion should be available on existing account + ;; names, but it remains to be implemented. + (ledger-read-string-with-default "Value: " nil)) + (defun ledger-report-read-name () "Read the name of a ledger report to use, with completion. -- cgit v1.2.3 From 21cdc04ab3eaea54c90bf93bd33aedb44cab29fb Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 18 Feb 2013 08:45:24 -0700 Subject: Fixes Bug 900 If the buffer being reconciles was killed with the *Reconcile* buffer still around their were dirty hooks left around that caused bug problems. This fix adds a local kill-buffer hook that calls the ledger-quit routines --- lisp/ldg-reconcile.el | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 20857127..ebaf7949 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -228,23 +228,23 @@ and exit reconcile mode" (defun ledger-reconcile-quit () - "Quite the reconcile window without saving ledger buffer." + "Quit the reconcile window without saving ledger buffer." (interactive) - (ledger-reconcile-quit-cleanup) - (let ((buf ledger-buf) - (recon-buf (get-buffer ledger-recon-buffer-name))) - ;; Make sure you delete the window before you delete the buffer, - ;; otherwise, madness ensues + (let ((recon-buf (get-buffer ledger-recon-buffer-name)) + buf) (with-current-buffer recon-buf + (ledger-reconcile-quit-cleanup) + (set 'buf ledger-buf) + ;; Make sure you delete the window before you delete the buffer, + ;; otherwise, madness ensues (delete-window (get-buffer-window recon-buf)) - (kill-buffer recon-buf)) - (set-window-buffer (selected-window) buf))) + (kill-buffer recon-buf) + (set-window-buffer (selected-window) buf)))) (defun ledger-reconcile-quit-cleanup () "Cleanup all hooks established by reconcile mode." (interactive) - (let ((buf ledger-buf) - (reconcile-buf (get-buffer ledger-recon-buffer-name))) + (let ((buf ledger-buf)) (with-current-buffer buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) (if ledger-fold-on-reconcile @@ -315,6 +315,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (when recon-window (fit-window-to-buffer recon-window) (with-current-buffer buf + (add-hook 'kill-buffer-hook 'ledger-reconcile-quit nil t) (select-window (get-buffer-window buf)) (goto-char (point-max)) (recenter -1)) @@ -426,9 +427,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (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) - - (add-hook 'kill-buffer-hook 'ledger-reconcile-quit-cleanup nil t))) + (use-local-map map))) (provide 'ldg-reconcile) (provide 'ldg-reconcile) -- cgit v1.2.3 From cf39acfd8ba0ebb542cf32f86944b2b6361cc6db Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 19 Feb 2013 09:30:20 -0700 Subject: Fix another null buffer problem when closing ledger buffers --- lisp/ldg-new.el | 1 + lisp/ldg-reconcile.el | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index ab267747..1e70c432 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -47,6 +47,7 @@ (require 'ldg-fonts) (require 'ldg-occur) (require 'ldg-commodities) +(require 'esh-arg) ;;; Code: diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ebaf7949..6d7226de 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -232,23 +232,25 @@ and exit reconcile mode" (interactive) (let ((recon-buf (get-buffer ledger-recon-buffer-name)) buf) - (with-current-buffer recon-buf - (ledger-reconcile-quit-cleanup) - (set 'buf ledger-buf) - ;; Make sure you delete the window before you delete the buffer, - ;; otherwise, madness ensues - (delete-window (get-buffer-window recon-buf)) - (kill-buffer recon-buf) - (set-window-buffer (selected-window) buf)))) + (if recon-buf + (with-current-buffer recon-buf + (ledger-reconcile-quit-cleanup) + (set 'buf ledger-buf) + ;; Make sure you delete the window before you delete the buffer, + ;; otherwise, madness ensues + (delete-window (get-buffer-window recon-buf)) + (kill-buffer recon-buf) + (set-window-buffer (selected-window) buf))))) (defun ledger-reconcile-quit-cleanup () "Cleanup all hooks established by reconcile mode." (interactive) (let ((buf ledger-buf)) - (with-current-buffer buf - (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) - (if ledger-fold-on-reconcile - (ledger-occur-quit-buffer buf))))) + (if buf + (with-current-buffer buf + (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) + (if ledger-fold-on-reconcile + (ledger-occur-quit-buffer buf)))))) (defun ledger-marker-where-xact-is (emacs-xact posting) "Find the position of the EMACS-XACT in the `ledger-buf'. -- cgit v1.2.3 From 988a41c3a4e9dbc131bb3e0d2fca18f796468777 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 20 Feb 2013 14:00:46 -0700 Subject: Make ledger-reconcile a little cleaner. The recon buffer is filled before asking for target, so there isn't a blank window showing while asking for target. --- lisp/ldg-reconcile.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 6d7226de..602d918e 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -362,12 +362,12 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (if ledger-fold-on-reconcile (ledger-occur-change-regex account ledger-buf)) (set-buffer (get-buffer ledger-recon-buffer-name)) - (setq ledger-target - (ledger-read-commodity-string "Set reconciliation target")) (unless (get-buffer-window rbuf) (ledger-reconcile-open-windows buf rbuf)) (ledger-reconcile-refresh) - (goto-char (point-min))) + (goto-char (point-min)) + (setq ledger-target + (ledger-read-commodity-string "Set reconciliation target"))) (progn ;; no recon-buffer, starting from scratch. (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) @@ -379,9 +379,9 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (ledger-reconcile-mode) (set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-acct) account) + (ledger-do-reconcile) (set (make-local-variable 'ledger-target) - (ledger-read-commodity-string "Set reconciliation target")) - (ledger-do-reconcile)))))) + (ledger-read-commodity-string "Set reconciliation target"))))))) (defvar ledger-reconcile-mode-abbrev-table) -- cgit v1.2.3 From 8029fd1149a607ee2eed7712194904b6c711d4b4 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 20 Feb 2013 20:46:38 -0700 Subject: Run ledger-highlight-xact-under-point when reconcile quits, so only one xact is highlighted --- lisp/ldg-reconcile.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 602d918e..9ac89915 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -250,7 +250,9 @@ and exit reconcile mode" (with-current-buffer buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) (if ledger-fold-on-reconcile - (ledger-occur-quit-buffer buf)))))) + (progn + (ledger-occur-quit-buffer buf) + (ledger-highlight-xact-under-point))))))) (defun ledger-marker-where-xact-is (emacs-xact posting) "Find the position of the EMACS-XACT in the `ledger-buf'. -- cgit v1.2.3 From a4e76727be273185c7eee5758262d58c5aa4ccdd Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 20 Feb 2013 21:16:05 -0700 Subject: Put in more nil window protection. --- lisp/ldg-occur.el | 3 ++- lisp/ldg-reconcile.el | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index 417a3d2a..c3f04c5d 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -82,7 +82,8 @@ When REGEX is nil, unhide everything, and remove higlight" (append ledger-occur-overlay-list (ledger-occur-create-folded-overlays buffer-matches))) (setq ledger-occur-last-match regex) - (select-window (get-buffer-window buffer)))) + (if (get-buffer-window buffer) + (select-window (get-buffer-window buffer))))) (recenter))) (defun ledger-occur (regex) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 9ac89915..623d7230 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -320,10 +320,10 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (fit-window-to-buffer recon-window) (with-current-buffer buf (add-hook 'kill-buffer-hook 'ledger-reconcile-quit nil t) - (select-window (get-buffer-window buf)) + (if (get-window-for-other-buffer buf) + (select-window (get-buffer-window buf))) (goto-char (point-max)) (recenter -1)) - (select-window recon-window) (ledger-reconcile-visit t)) (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t)))) -- cgit v1.2.3 From 2fd1574cf2e969c7da7bf346837d859ac6ae90c9 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 21 Feb 2013 06:43:00 -0700 Subject: Prevent point from being at the end of line when ledger-reconcile-toggle is called --- lisp/ldg-reconcile.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 623d7230..e040359d 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -112,6 +112,7 @@ numbers" (defun ledger-reconcile-toggle () "Toggle the current transaction, and mark the recon window." (interactive) + (beginning-of-line) (let ((where (get-text-property (point) 'where)) (inhibit-read-only t) status) -- cgit v1.2.3 From d638f8300f01600554017c5c5cad674873af9bc8 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 21 Feb 2013 14:59:32 -0700 Subject: bug-905, inadvertently used an aquamacs function. --- lisp/ldg-reconcile.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index e040359d..58f179f4 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -321,7 +321,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (fit-window-to-buffer recon-window) (with-current-buffer buf (add-hook 'kill-buffer-hook 'ledger-reconcile-quit nil t) - (if (get-window-for-other-buffer buf) + (if (get-buffer-window buf) (select-window (get-buffer-window buf))) (goto-char (point-max)) (recenter -1)) -- cgit v1.2.3 From 510a7c4e6c58d296d93941b193729b1d91dbb927 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 21 Feb 2013 15:31:58 -0700 Subject: Position point at beginning of line on posting being reconciled. --- lisp/ldg-reconcile.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 58f179f4..6a9d05fd 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -198,6 +198,7 @@ numbers" (forward-char) (recenter) (ledger-highlight-xact-under-point) + (forward-char -1) (if come-back (switch-to-buffer-other-window cur-buf)))))) -- cgit v1.2.3 From 42911df9f5f25914d2be7f48f294ab2fccc06248 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 27 Feb 2013 17:27:52 -0700 Subject: Restructured customization groups. Completed initial draft of ledger-mode documentation --- doc/ledger-mode.texi | 195 ++++++++++++++++++++++++++++++++++++++++++------ lisp/ldg-commodities.el | 8 +- lisp/ldg-exec.el | 2 +- lisp/ldg-init.el | 2 +- lisp/ldg-occur.el | 2 +- lisp/ldg-post.el | 26 +++---- lisp/ldg-reconcile.el | 16 ++-- lisp/ldg-report.el | 9 ++- lisp/ldg-test.el | 14 ++-- lisp/ldg-texi.el | 26 +++++-- 10 files changed, 232 insertions(+), 68 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index 0dc487a2..9b2c1262 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -72,7 +72,9 @@ reports and much more... * The Ledger Buffer:: * The Reconcile Buffer:: * The Report Buffer:: -* Installing and Customizing Ledger-mode:: +* Customizing Ledger-mode:: +* Generating Ledger Regression Tests:: +* Embedding Example results in Ledger Documentation:: * Hacking Ledger-mode:: @end menu @@ -83,12 +85,12 @@ reports and much more... @node Introduction to Ledger Mode, The Ledger Buffer, Copying, Top @chapter Introduction to Ledger Mode @menu -* Quick installation:: +* Quick Installation:: * Menus:: * Quick Demo:: @end menu -@node Quick installation, Menus, Introduction to Ledger Mode, Introduction to Ledger Mode +@node Quick Installation, Menus, Introduction to Ledger Mode, Introduction to Ledger Mode @section Quick Installation The emacs lisp source for Ledger-mode is included with the source @@ -107,7 +109,7 @@ This sets up Emacs to automatically recognize files that end with @file{.ledger} and start Ledger mode. Nothing else should be required as long as the ledger command line utility is properly installed. -@node Menus, Quick Demo, Quick installation, Introduction to Ledger Mode +@node Menus, Quick Demo, Quick Installation, Introduction to Ledger Mode @section Menus The vast majority of Ledger-mode functionality is available from the @@ -225,6 +227,12 @@ payees and accounts. Included files are not currently included in the completion scan. Repeatedly hitting @code{TAB} will cycle through the possible completions. +Ledger mode can also help you keep your amounts in alignment. Setting +@code{ledger-post-auto-adjust-amounts} to true tells Ledger-mode to +automatically place any amounts such that their last digit is aligned to +the column specified by @code{ledger-post-amount-alignment-column}, +which defautls to 52. @xref{Ledger Post Customization Group} + @node Editing Amounts, Marking Transactions, Adding Transactions, The Ledger Buffer @section Editing Amounts GNU Calc is a very powerful Reverse Polish Notation calculator built @@ -439,7 +447,7 @@ If for some reason during reconciliation your target amount changes, type @code{t} and enter the new target value. -@node The Report Buffer, Installing and Customizing Ledger-mode, The Reconcile Buffer, Top +@node The Report Buffer, Customizing Ledger-mode, The Reconcile Buffer, Top @chapter The Report Buffer @menu * Running Basic Reports:: @@ -552,36 +560,177 @@ it will reverse the order of the transactions and maintain the proper mathematical sense. -@node Installing and Customizing Ledger-mode, Hacking Ledger-mode, The Report Buffer, Top -@chapter Installing and Customizing Ledger-mode +@node Customizing Ledger-mode, Generating Ledger Regression Tests, The Report Buffer, Top +@chapter Customizing Ledger-mode @menu -* Emacs Initialization File:: * Ledger-mode Customization:: * Customization Variables:: -* Ledger-mode Faces:: @end menu -@node Emacs Initialization File, Ledger-mode Customization, Installing and Customizing Ledger-mode, Installing and Customizing Ledger-mode -@section Emacs Initialization File - -@node Ledger-mode Customization, Ledger-mode Faces, Emacs Initialization File, Installing and Customizing Ledger-mode +@node Ledger-mode Customization, Customization Variables, Customizing Ledger-mode, Customizing Ledger-mode @section Ledger-mode Customization -@node Customization Variables, , Ledger-mode Customization, Installing and Customizing Ledger-mode + +Ledger-mode has several options available for configuration. All +options can be configure through the Emacs customization menus, or +specified in your Emacs initialization file. The complete list of +options is show below. To change the option using the Emacs +customization menu, simply choe customize in the Options menu and look +for Ledger under the data options. Alternately you can choose +``Customize Specific Group'' and enger ``Ledger'' as the group. + +@node Customization Variables, , Ledger-mode Customization, Customizing Ledger-mode @section Customization Variables -@node Ledger-mode Faces, , Customization Variables, Installing and Customizing Ledger-mode -@section Ledger-mode Faces + @menu -* Using EMACS customization menus:: -* Complete list of customization variables:: +* Ledger Customization Group:: +* Ledger Reconcile Customization Group:: +* Ledger Report Customization Group:: +* Ledger Faces Customization Group:: +* Ledger Post Customization Group:: +* Ledger Exec Customization Group:: +* Ledger Test Customization Group:: +* Ledger Texi Customization Group:: @end menu -@node Using EMACS customization menus, Complete list of customization variables, Ledger-mode Faces, Ledger-mode Faces -@subsection Using EMACS customization menus +@node Ledger Customization Group, Ledger Reconcile Customization Group, Customization Variables, Customization Variables +@subsection Ledger Customization Group +@table @code +@item ledger-default-acct-transaction-indent + Default indentation for account transactions in an entry. +@item ledger-occur-use-face-unfolded + If non-nil use a custom face for xacts shown in `ledger-occur' mode using @code{ledger-occur-xact-face}. +@item ledger-clear-whole-transactions + If non-nil, clear whole transactions, not individual postings. +@item ledger-highlight-xact-under-point + If non-nil highlight xact under point using @code{ledger-font-highlight-face}. +@end table + +@node Ledger Reconcile Customization Group, Ledger Report Customization Group, Ledger Customization Group, Customization Variables +@subsection Ledger Reconcile Customization Group + +@table @code +@item ledger-reconcile-default-commodity +The default commodity for use in target calculations in ledger +reconcile. Defaults to $ (USD) +@item ledger-recon-buffer-name + Name to use for reconciliation window. +@item ledger-fold-on-reconcile + If non-nil, limit transactions shown in main buffer to those matching the + reconcile regex. +@item ledger-buffer-tracks-reconcile-buffer + If non-nil, then when the cursor is moved to a new xact in the recon + window. +@item ledger-reconcile-force-window-bottom + If non-nil, make the reconcile window appear along the bottom of the + register window and resize. +@item ledger-reconcile-toggle-to-pending + If non-nil, then toggle between uncleared and pending (@code{!}). If false + toggle between unlceared and cleared (@code{*}) +@end table + +@node Ledger Report Customization Group, Ledger Faces Customization Group, Ledger Reconcile Customization Group, Customization Variables +@subsection Ledger Report Customization Group + +@table @code +@item ledger-reports + Definition of reports to run. +@item ledger-report-format-specifiers + An alist mapping ledger report format specifiers to implementing functions. +@end table + + +@node Ledger Faces Customization Group, Ledger Post Customization Group, Ledger Report Customization Group, Customization Variables +@subsection Ledger Faces Customization Group +Ledger Faces : Ledger mode highlighting +@table @code +@item ledger-font-uncleared-face +Default face for Ledger +@item ledger-font-cleared-face +Default face for cleared (*) transactions +@item ledger-font-highlight-face +Default face for transaction under point +@item ledger-font-pending-face +Default face for pending (!) transactions +@item ledger-font-other-face +Default face for other transactions +@item ledger-font-posting-account-face +Face for Ledger accounts +@item ledger-font-posting-amount-face +Face for Ledger amounts +@item ledger-occur-folded-face +Default face for Ledger occur mode hidden transactions +@item ledger-occur-xact-face +Default face for Ledger occur mode shown transactions +@item ledger-font-comment-face +Face for Ledger comments +@item ledger-font-reconciler-uncleared-face +Default face for uncleared transactions in the reconcile window +@item ledger-font-reconciler-cleared-face +Default face for cleared (*) transactions in the reconcile window +@item ledger-font-reconciler-pending-face +Default face for pending (!) transactions in the reconcile window +@item ledger-font-report-clickable-face +Default face for pending (!) transactions in the reconcile window +@end table + +@node Ledger Post Customization Group, Ledger Exec Customization Group, Ledger Faces Customization Group, Customization Variables +@subsection Ledger Post Customization Group +Ledger Post : +@table @code +@item ledger-post-auto-adjust-amounts +If non-nil, then automatically align amounts to column specified in +@code{ledger-post-amount-alignment-column} +@item ledger-post-amount-alignment-column +The column Ledger-mode uses to align amounts +@item ledger-post-use-completion-engine +Which completion engine to use, iswitchb, ido, or built-in +@item ledger-post-use-ido +@end table + +@node Ledger Exec Customization Group, Ledger Test Customization Group, Ledger Post Customization Group, Customization Variables +@subsection Ledger Exec Customization Group + +Ledger Exec : Interface to the Ledger command-line accounting program. + +@table @code +@item ledger-binary-path +Path to the ledger executable. +@item ledger-init-file-name +Location of the ledger initialization file. nil if you don't have one +@end table + + +@node Ledger Test Customization Group, Ledger Texi Customization Group, Ledger Exec Customization Group, Customization Variables +@subsection Ledger Test Customization Group +@table @code +@item ledger-source-directory + Directory where the Ledger sources are located. +@item ledger-test-binary + Directory where the debug binary. +@end table + +@node Ledger Texi Customization Group, , Ledger Test Customization Group, Customization Variables +@subsection Ledger Texi Customization Group + +@table @code +@item ledger-texi-sample-doc-path +Location for sample data to be used in texi tests, defaults to @file{~/ledger/doc/sample.dat} +@item ledger-texi-normalization-args +texi normalization for producing ledger output, defaults to ``@code{--args-only --columns 80}'' +@end table + +@node Generating Ledger Regression Tests, Embedding Example results in Ledger Documentation, Customizing Ledger-mode, Top +@chapter Generating Ledger Regression Tests + +Work in Progress. + +@node Embedding Example results in Ledger Documentation, Hacking Ledger-mode, Generating Ledger Regression Tests, Top +@chapter Embedding Example results in Ledger Documentation -@node Complete list of customization variables, , Using EMACS customization menus, Ledger-mode Faces -@subsection Complete list of customization variables +Work in Progress. -@node Hacking Ledger-mode, , Installing and Customizing Ledger-mode, Top +@node Hacking Ledger-mode, , Embedding Example results in Ledger Documentation, Top @chapter Hacking Ledger-mode +Work in Progress. @bye diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index 6f835221..c5500785 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -29,13 +29,7 @@ (defcustom ledger-reconcile-default-commodity "$" "The default commodity for use in target calculations in ledger reconcile." :type 'string - :group 'ledger) - -(defcustom ledger-use-decimal-comma nil - "If non-nil the use commas as decimal separator. -This only has effect interfacing to calc mode in edit amount" - :type 'boolean - :group 'ledger) + :group 'ledger-reconcile) (defun ledger-split-commodity-string (str) "Split a commoditized amount into two parts" diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el index af5dd3a8..d62fd419 100644 --- a/lisp/ldg-exec.el +++ b/lisp/ldg-exec.el @@ -38,7 +38,7 @@ (defcustom ledger-binary-path "ledger" "Path to the ledger executable." :type 'file - :group 'ledger) + :group 'ledger-exec) (defun ledger-exec-ledger (input-buffer &optional output-buffer &rest args) "Run Ledger using INPUT-BUFFER and optionally capturing output in OUTPUT-BUFFER with ARGS." diff --git a/lisp/ldg-init.el b/lisp/ldg-init.el index fbb4b838..72317088 100644 --- a/lisp/ldg-init.el +++ b/lisp/ldg-init.el @@ -24,7 +24,7 @@ (defcustom ledger-init-file-name "~/.ledgerrc" "Location of the ledger initialization file. nil if you don't have one" - :group 'ledger) + :group 'ledger-exec) (defvar ledger-environment-alist nil) diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index c3f04c5d..1561d6f8 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -35,7 +35,7 @@ (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." + "If non-nil, use a custom face for xacts shown in `ledger-occur' mode using ledger-occur-xact-face." :type 'boolean :group 'ledger) (make-variable-buffer-local 'ledger-occur-use-face-unfolded) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 14c3c55f..de28a8a9 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -28,7 +28,7 @@ ;;; Code: (defgroup ledger-post nil - "" + "Options for controlling how Ledger-mode deals with postings and completion" :group 'ledger) (defcustom ledger-post-auto-adjust-amounts nil @@ -37,19 +37,17 @@ :group 'ledger-post) (defcustom ledger-post-amount-alignment-column 52 - "If non-nil, ." + "The column Ledger-mode attempts to align amounts to." :type 'integer :group 'ledger-post) -(defcustom ledger-post-use-iswitchb nil - "If non-nil, ." - :type 'boolean - :group 'ledger-post) - -(defcustom ledger-post-use-ido nil - "If non-nil, ." - :type 'boolean - :group 'ledger-post) +(defcustom ledger-post-use-completion-engine :built-in + "Which completion engine to use, :iswitchb or :ido chose those engines, +:built-in uses built-in Ledger-mode completion" + :type '(radio (const :tag "built in completion" :built-in) + (const :tag "ido completion" :ido) + (const :tag "iswitchb completion" :iswitchb) ) + :group 'ledger-post) (defun ledger-post-all-accounts () "Return a list of all accounts in the buffer." @@ -73,13 +71,13 @@ PROMPT is a string to prompt with. CHOICES is a list of strings to choose from." (cond - (ledger-post-use-iswitchb + ((eq ledger-post-use-completion-engine :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 + ((eq ledger-post-use-completion-engine :ido) (ido-completing-read prompt choices)) (t (completing-read prompt choices)))) @@ -114,7 +112,7 @@ PROMPT is a string to prompt with. CHOICES is a list of (defun ledger-next-amount (&optional end) "Move point to the next amount, as long as it is not past END." - (when (re-search-forward "\\( \\|\t\\| \t\\)[ \t]*-?\\([A-Z$€£]+ *\\)?\\(-?[0-9,]+?\\)\\(.[0-9]+\\)?\\( *[A-Z$€£]+\\)?\\([ \t]*@@?[^\n;]+?\\)?\\([ \t]+;.+?\\)?$" (marker-position end) t) + (when (re-search-forward "\\( \\|\t\\| \t\\)[ \t]*-?\\([A-Z$€£]+ *\\)?\\(-?[0-9,]+?\\)\\(.[0-9]+\\)?\\( *[A-Z$€£]+\\)?\\([ \t]*@@?[^\n;]+?\\)?\\([ \t]+;.+?\\|[ \t]*\\)?$" (marker-position end) t) (goto-char (match-beginning 0)) (skip-syntax-forward " ") (- (or (match-end 4) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 6a9d05fd..6093f9df 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -23,7 +23,7 @@ ;;; Commentary: -;; +;; Code to handle reconciling Ledger files wiht outside sources ;;; Code: @@ -32,31 +32,35 @@ (defvar ledger-acct nil) (defvar ledger-target nil) +(defgroup ledger-reconcile nil + "Options for Ledger-mode reconciliation" + :group 'ledger) + (defcustom ledger-recon-buffer-name "*Reconcile*" "Name to use for reconciliation window." - :group 'ledger) + :group 'ledger-reconcile) (defcustom ledger-fold-on-reconcile t "If t, limit transactions shown in main buffer to those matching the reconcile regex." :type 'boolean - :group 'ledger) + :group 'ledger-reconcile) (defcustom ledger-buffer-tracks-reconcile-buffer t "If t, then when the cursor is moved to a new xact in the recon window. Then that transaction will be shown in its source buffer." :type 'boolean - :group 'ledger) + :group 'ledger-reconcile) (defcustom ledger-reconcile-force-window-bottom nil "If t make the reconcile window appear along the bottom of the register window and resize." :type 'boolean - :group 'ledger) + :group 'ledger-reconcile) (defcustom ledger-reconcile-toggle-to-pending t "If true then toggle between uncleared and pending. reconcile-finish will mark all pending posting cleared." :type 'boolean - :group 'ledger) + :group 'ledger-reconcile) (defun ledger-reconcile-get-balances () diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 4db58494..0aa91ac0 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -28,6 +28,11 @@ (eval-when-compile (require 'cl)) +(defgroup ledger-report nil + "Customization option for the Report buffer" + :group 'ledger +) + (defcustom ledger-reports '(("bal" "ledger -f %(ledger-file) bal") ("reg" "ledger -f %(ledger-file) reg") @@ -46,7 +51,7 @@ in that variable for more information on the behavior of each specifier." :type '(repeat (list (string :tag "Report Name") (string :tag "Command Line"))) - :group 'ledger) + :group 'ledger-report) (defcustom ledger-report-format-specifiers '(("ledger-file" . ledger-report-ledger-file-format-specifier) @@ -58,7 +63,7 @@ specifier." The function is called with no parameters and expected to return the text that should replace the format specifier." :type 'alist - :group 'ledger) + :group 'ledger-report) (defvar ledger-report-buffer-name "*Ledger Report*") diff --git a/lisp/ldg-test.el b/lisp/ldg-test.el index 7667a05e..dbba9546 100644 --- a/lisp/ldg-test.el +++ b/lisp/ldg-test.el @@ -19,15 +19,19 @@ ;; 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 +(defgroup ledger-test nil + "Definitions for the Ledger testing framework" :group 'ledger) -(defcustom ledger-test-binary "~/Products/ledger/debug/ledger" +(defcustom ledger-source-directory "~/ledger/" "Directory where the Ledger sources are located." + :type 'directory + :group 'ledger-test) + +(defcustom ledger-test-binary "/Products/ledger/debug/ledger" + "Directory where the Ledger debug binary is located." :type 'file - :group 'ledger) + :group 'ledger-test) (defun ledger-test-org-narrow-to-entry () (outline-back-to-heading) diff --git a/lisp/ldg-texi.el b/lisp/ldg-texi.el index 53e050ce..84ba34c2 100644 --- a/lisp/ldg-texi.el +++ b/lisp/ldg-texi.el @@ -19,9 +19,19 @@ ;; 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") +(defgroup ledger-texi nil +"Options for working on Ledger texi documentation" +:group 'ledger) + +(defcustom ledger-texi-sample-doc-path "~/ledger/doc/sample.dat" +"Location for sample data to be used in texi tests" +:type 'file +:group 'ledger-texi) + +(defcustom ledger-texi-normalization-args "--args-only --columns 80" +"texi normalization for producing ledger output" +:type 'string +:group 'ledger-texi) (defun ledger-update-test () (interactive) @@ -92,10 +102,10 @@ (defun ledger-texi-expand-command (command data-file) (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))) + (replace-match (format "%s -f \"%s\" %s" ledger-binary-path + data-file ledger-texi-normalization-args) t t command) + (concat (format "%s -f \"%s\" %s " ledger-binary-path + data-file ledger-texi-normalization-args) command))) (defun ledger-texi-invoke-command (command) (with-temp-buffer (shell-command command t (current-buffer)) @@ -122,7 +132,7 @@ (let ((section (match-string 1)) (example-name (match-string 2)) (command (match-string 3)) expanded-command - (data-file ledger-sample-doc-path) + (data-file ledger-texi-sample-doc-path) input output) (goto-char (match-end 0)) (forward-line) -- cgit v1.2.3 From 3a0182d8d7a20ac33f78ab7e614881c6fe87a129 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 1 Mar 2013 09:37:33 -0700 Subject: Ensure reconcile balance display can handle empty accounts. Also force balance display at the beginning of reconciliation. --- lisp/ldg-commodities.el | 27 +++++++++++++++++---------- lisp/ldg-reconcile.el | 29 ++++++++++++++++------------- 2 files changed, 33 insertions(+), 23 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index c5500785..a3cc8951 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -38,16 +38,23 @@ (with-temp-buffer (insert str) (goto-char (point-min)) - (re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t) - (setq val - (string-to-number - (ledger-commodity-string-number-decimalize - (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))) - (goto-char (point-min)) - (re-search-forward "[^[:space:]]" nil t) - (setq comm - (delete-and-extract-region (match-beginning 0) (match-end 0))) - (list val comm)))) + (cond ((re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t) + ;; found a decimal number + (setq val + (string-to-number + (ledger-commodity-string-number-decimalize + (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))) + (goto-char (point-min)) + (re-search-forward "[^[:space:]]" nil t) + (setq comm + (delete-and-extract-region (match-beginning 0) (match-end 0))) + (list val comm)) + ((re-search-forward "0" nil t) + ;; couldn't find a decimal number, look for a single 0, + ;; indicating account with zero balance + (list 0 ledger-reconcile-default-commodity)) + (t + (error "split-commodity-string: cannot parse commodity string: %S" str)))))) (defun ledger-string-balance-to-commoditized-amount (str) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 6093f9df..f64f1bca 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -63,10 +63,8 @@ reconcile-finish will mark all pending posting cleared." :group 'ledger-reconcile) -(defun ledger-reconcile-get-balances () - "Calculate the cleared and uncleared balance of the account. -Return a list with the account, uncleared and cleared balances as -numbers" +(defun ledger-reconcile-get-cleared-or-pending-balance () + "Calculate the cleared or pending balance of the account." (interactive) (let ((buffer ledger-buf) (account ledger-acct) @@ -77,15 +75,17 @@ numbers" ; separated from the actual format string. emacs does not ; split arguments like the shell does, so you need to ; specify the individual fields in the command line. - "balance" "--limit" "cleared or pending" - "--format" "(\"%(display_total)\")" account) - (setq val (read (buffer-substring-no-properties (point-min) (point-max))))))) + "balance" "--limit" "cleared or pending" "--empty" + "--format" "%(display_total)" account) + (setq val + (ledger-split-commodity-string + (buffer-substring-no-properties (point-min) (point-max))))))) (defun ledger-display-balance () - "Calculate the cleared balance of the account being reconciled." + "Display the cleared-or-pending balnce and calculate the +target-delta of the account being reconciled." (interactive) - (let* ((pending (car (ledger-string-balance-to-commoditized-amount - (car (ledger-reconcile-get-balances))))) + (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance)) (target-delta (if ledger-target (-commodity ledger-target pending) nil))) @@ -156,7 +156,8 @@ numbers" (ledger-do-reconcile) (set-buffer-modified-p t) (goto-char (point-min)) - (forward-line line))) + (forward-line line) + (ledger-display-balance))) (defun ledger-reconcile-refresh-after-save () "Refresh the recon-window after the ledger buffer is saved." @@ -375,7 +376,8 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (ledger-reconcile-refresh) (goto-char (point-min)) (setq ledger-target - (ledger-read-commodity-string "Set reconciliation target"))) + (ledger-read-commodity-string "Set reconciliation target")) + (ledger-display-balance)) (progn ;; no recon-buffer, starting from scratch. (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) @@ -389,7 +391,8 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (set (make-local-variable 'ledger-acct) account) (ledger-do-reconcile) (set (make-local-variable 'ledger-target) - (ledger-read-commodity-string "Set reconciliation target"))))))) + (ledger-read-commodity-string "Set reconciliation target")) + (ledger-display-balance)))))) (defvar ledger-reconcile-mode-abbrev-table) -- cgit v1.2.3 From 497d668778e17e08ac91695ba1cb5da50612cd0a Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 1 Mar 2013 23:29:31 -0700 Subject: Clean up the reconcile balance display code --- lisp/ldg-reconcile.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index f64f1bca..33c9f06f 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -156,8 +156,7 @@ target-delta of the account being reconciled." (ledger-do-reconcile) (set-buffer-modified-p t) (goto-char (point-min)) - (forward-line line) - (ledger-display-balance))) + (forward-line line))) (defun ledger-reconcile-refresh-after-save () "Refresh the recon-window after the ledger buffer is saved." -- cgit v1.2.3 From efce6c89362abed1276cd060cec8077777a038e4 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 4 Mar 2013 09:36:34 -0700 Subject: Add acct under point to reconcile prompt. Fix reconcile balance display of empty accounts --- lisp/ldg-commodities.el | 46 ++++++++++++++++++++++++---------------------- lisp/ldg-post.el | 12 ++++++++++++ lisp/ldg-reconcile.el | 9 +++++---- lisp/ldg-report.el | 11 +++-------- 4 files changed, 44 insertions(+), 34 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index a3cc8951..9291136f 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -33,28 +33,30 @@ (defun ledger-split-commodity-string (str) "Split a commoditized amount into two parts" - (let (val - comm) - (with-temp-buffer - (insert str) - (goto-char (point-min)) - (cond ((re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t) - ;; found a decimal number - (setq val - (string-to-number - (ledger-commodity-string-number-decimalize - (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))) - (goto-char (point-min)) - (re-search-forward "[^[:space:]]" nil t) - (setq comm - (delete-and-extract-region (match-beginning 0) (match-end 0))) - (list val comm)) - ((re-search-forward "0" nil t) - ;; couldn't find a decimal number, look for a single 0, - ;; indicating account with zero balance - (list 0 ledger-reconcile-default-commodity)) - (t - (error "split-commodity-string: cannot parse commodity string: %S" str)))))) + (if (> (length str) 0) + (let (val + comm) + (with-temp-buffer + (insert str) + (goto-char (point-min)) + (cond ((re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t) + ;; found a decimal number + (setq val + (string-to-number + (ledger-commodity-string-number-decimalize + (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))) + (goto-char (point-min)) + (re-search-forward "[^[:space:]]" nil t) + (setq comm + (delete-and-extract-region (match-beginning 0) (match-end 0))) + (list val comm)) + ((re-search-forward "0" nil t) + ;; couldn't find a decimal number, look for a single 0, + ;; indicating account with zero balance + (list 0 ledger-reconcile-default-commodity)) + (t + (error "split-commodity-string: cannot parse commodity string: %S" str))))) + (list 0 ledger-reconcile-default-commodity))) (defun ledger-string-balance-to-commoditized-amount (str) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 7105ef7a..6cba305b 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -229,6 +229,18 @@ BEG, END, and LEN control how far it can align." (add-hook 'after-change-functions 'ledger-post-maybe-align t t)) (add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil)))) + +(defun ledger-post-read-account-with-prompt (prompt) + (let* ((context (ledger-context-at-point)) + (default + (if (eq (ledger-context-line-type context) 'acct-transaction) + (regexp-quote (ledger-context-field-value context 'account)) + nil))) + (ledger-read-string-with-default prompt default))) + + (provide 'ldg-post) + + ;;; ldg-post.el ends here diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 33c9f06f..e45ab7c3 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -351,10 +351,11 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (set-window-buffer (split-window (get-buffer-window buf) nil nil) rbuf) (pop-to-buffer rbuf))) -(defun ledger-reconcile (account) - "Start reconciling ACCOUNT." - (interactive "sAccount to reconcile: ") - (let ((buf (current-buffer)) +(defun ledger-reconcile () + "Start reconciling, prompt for account." + (interactive) + (let ((account (ledger-post-read-account-with-prompt "Account to reconcile")) + (buf (current-buffer)) (rbuf (get-buffer ledger-recon-buffer-name))) ;; this means ;; only one ;; *Reconcile* diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 0728495e..ef088f17 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -258,12 +258,7 @@ used to generate the buffer, navigating the buffer, etc." the default." ;; It is intended completion should be available on existing account ;; names, but it remains to be implemented. - (let* ((context (ledger-context-at-point)) - (default - (if (eq (ledger-context-line-type context) 'acct-transaction) - (regexp-quote (ledger-context-field-value context 'account)) - nil))) - (ledger-read-string-with-default "Account" default))) + (ledger-post-read-account-with-prompt "Account")) (defun ledger-report-expand-format-specifiers (report-cmd) "Expand %(account) and %(payee) appearing in REPORT-CMD with thing under point." @@ -437,9 +432,9 @@ Optional EDIT the command." ("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*\\)[ \t]*$" (date nil status nil nil code payee)))) (acct-transaction - (("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" + (("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" (indent account commodity amount nil comment)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*$" + ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*$" (indent account commodity amount nil)) ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\(-?[0-9]+\\(\\.[0-9]*\\)?\\)[ \t]+\\(.*?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" (indent account amount nil commodity comment)) -- cgit v1.2.3 From 1eba7c6cdf4ac334a5b8580e4f18102db26b8c5f Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 6 Mar 2013 14:36:31 -0500 Subject: Code formatting cleanup. --- lisp/ldg-occur.el | 4 +++- lisp/ldg-reconcile.el | 1 - lisp/ldg-regex.el | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index 1561d6f8..f14aeeda 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -41,7 +41,9 @@ (make-variable-buffer-local 'ledger-occur-use-face-unfolded) -(defvar ledger-occur-mode nil) ;; name of the minor mode, shown in the mode-line +(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) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index e45ab7c3..fd452004 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -443,6 +443,5 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (use-local-map map))) (provide 'ldg-reconcile) -(provide 'ldg-reconcile) ;;; ldg-reconcile.el ends here diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el index e81394ef..97fd6e2c 100644 --- a/lisp/ldg-regex.el +++ b/lisp/ldg-regex.el @@ -24,7 +24,8 @@ (eval-when-compile (require 'cl)) -(defvar ledger-date-regex "\\([0-9]+\\)[/-]\\([0-9]+\\)[/-]\\([0-9]+\\)") +(defvar ledger-date-regex + "\\([0-9]+\\)[/-]\\([0-9]+\\)[/-]\\([0-9]+\\)") (defmacro ledger-define-regexp (name regex docs &rest args) "Simplify the creation of a Ledger regex and helper functions." -- cgit v1.2.3 From 27d27ecb6c5be3a9523fd4efc895b6d0b2a6cfb4 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 6 Mar 2013 21:13:06 -0500 Subject: Account auto formatting now works with tab completion --- lisp/ldg-complete.el | 11 ++++++----- lisp/ldg-post.el | 13 +++++++++---- lisp/ldg-reconcile.el | 2 +- lisp/ldg-xact.el | 3 --- 4 files changed, 16 insertions(+), 13 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index 3686d0fd..6607d372 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -145,16 +145,17 @@ Return tree structure" "Completes a transaction if there is another matching payee in the buffer. Does not use ledger xact" (interactive) - (let ((name (caar (ledger-parse-arguments))) - rest-of-name + (let* ((name (caar (ledger-parse-arguments))) + (rest-of-name name) xacts) (save-excursion (when (eq 'transaction (ledger-thing-at-point)) + (delete-region (point) (+ (length name) (point))) ;; Search backward for a matching payee (when (re-search-backward - (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" - (regexp-quote name) ) nil t) ;; "\\(\t\\|\n\\| [ \t]\\)" - (setq rest-of-name (buffer-substring-no-properties (match-end 0) (line-end-position))) + (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.*" + (regexp-quote name) ".*\\)" ) nil t) ;; "\\(\t\\|\n\\| [ \t]\\)" + (setq rest-of-name (match-string 3)) ;; Start copying the postings (forward-line) (while (looking-at "^\\s-+") diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index e794f071..d68d7f16 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -133,10 +133,15 @@ the account" (setq column ledger-post-amount-alignment-column)) (save-excursion ;; Position the account - ;; (beginning-of-line) - (set-mark (point)) - ;; (delete-horizontal-space) - ;; (insert ledger-default-acct-transaction-indent) + (if (not + (and (looking-at "[ \t]+\n") + (looking-back "[ \n]" (- (point) 2)))) + (progn + (beginning-of-line) + (set-mark (point)) + (delete-horizontal-space) + (insert ledger-default-acct-transaction-indent)) + (set-mark (point))) (goto-char (1+ (line-end-position))) (let* ((mark-first (< (mark) (point))) (begin (if mark-first (mark) (point))) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index fd452004..7b3df459 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -397,7 +397,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (defvar ledger-reconcile-mode-abbrev-table) (defun ledger-reconcile-change-target () - "Change the traget amount for the reconciliation process." + "Change the target amount for the reconciliation process." (interactive) (setq ledger-target (ledger-read-commodity-string "Set reconciliation target"))) diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index 8db50df2..ecd87127 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -118,9 +118,6 @@ within the transaction." (replace-match date) (re-search-forward "[1-9][0-9]+\.[0-9]+"))) - - -(provide 'ldg-xact) (provide 'ldg-xact) ;;; ldg-xact.el ends here -- cgit v1.2.3 From b475e569c4c4cb97d32e76de4d85d0810c9cc462 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 7 Mar 2013 15:28:09 -0500 Subject: Made account formatting and auto complete compatible. --- lisp/ldg-new.el | 1 + lisp/ldg-post.el | 38 +++++++++++++----------- lisp/ldg-reconcile.el | 16 +++++------ lisp/ldg-state.el | 80 +++++++++++++++++++++++++++------------------------ 4 files changed, 72 insertions(+), 63 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index 7a2961f7..4cebbba7 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -32,6 +32,7 @@ ;;; Commentary: ;; Load up the ledger mode +(require 'esh-util) (require 'esh-arg) (require 'ldg-commodities) (require 'ldg-complete) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index d68d7f16..87922dd1 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -36,11 +36,16 @@ "Options for controlling how Ledger-mode deals with postings and completion" :group 'ledger) -(defcustom ledger-post-auto-adjust-amounts nil - "If non-nil, ." +(defcustom ledger-post-auto-adjust-postings nil + "If non-nil, adjust account and amount to columns set below" :type 'boolean :group 'ledger-post) +(defcustom ledger-post-account-alignment-column 4 + "The column Ledger-mode attempts to align accounts to." + :type 'integer + :group 'ledger-post) + (defcustom ledger-post-amount-alignment-column 52 "The column Ledger-mode attempts to align amounts to." :type 'integer @@ -123,25 +128,25 @@ PROMPT is a string to prompt with. CHOICES is a list of (- (or (match-end 4) (match-end 3)) (point)))) -(defun ledger-align-amounts (&optional column) +(defun ledger-post-align-postings (&optional column) "Align amounts and accounts in the current region. This is done so that the last digit falls in COLUMN, which -defaults to 52. ledger-default-acct-transaction-indent positions +defaults to 52. ledger-post-account-column positions the account" (interactive "p") (if (or (null column) (= column 1)) (setq column ledger-post-amount-alignment-column)) (save-excursion ;; Position the account - (if (not - (and (looking-at "[ \t]+\n") - (looking-back "[ \n]" (- (point) 2)))) - (progn + (if (not (and (looking-at "[ \t]+\n") + (looking-back "[ \n]" (- (point) 2)))) + (save-excursion (beginning-of-line) - (set-mark (point)) - (delete-horizontal-space) - (insert ledger-default-acct-transaction-indent)) + (set-mark (point)) + (delete-horizontal-space) + (insert (make-string ledger-post-account-alignment-column ? ))) (set-mark (point))) + (set-mark (point)) (goto-char (1+ (line-end-position))) (let* ((mark-first (< (mark) (point))) (begin (if mark-first (mark) (point))) @@ -153,7 +158,7 @@ the account" (let ((col (current-column)) (target-col (- column offset)) adjust) - (setq adjust (- target-col col)) + (setq adjust (- target-col col)) (if (< col target-col) (insert (make-string (- target-col col) ? )) (move-to-column target-col) @@ -164,13 +169,13 @@ the account" (insert " "))) (forward-line)))))) -(defun ledger-post-align-amount () +(defun ledger-post-align-posting () "Align the amounts in this posting." (interactive) (save-excursion (set-mark (line-beginning-position)) (goto-char (1+ (line-end-position))) - (ledger-align-amounts))) + (ledger-post-align-postings))) (defun ledger-post-maybe-align (beg end len) "Align amounts only if point is in a posting. @@ -180,7 +185,7 @@ BEG, END, and LEN control how far it can align." (when (<= end (line-end-position)) (goto-char (line-beginning-position)) (if (looking-at ledger-post-line-regexp) - (ledger-align-amounts))))) + (ledger-post-align-postings))))) (defun ledger-post-edit-amount () "Call 'calc-mode' and push the amount in the posting to the top of stack." @@ -221,8 +226,7 @@ BEG, END, and LEN control how far it can align." (defun ledger-post-setup () "Configure `ledger-mode' to auto-align postings." - (if ledger-post-auto-adjust-amounts - (add-hook 'after-change-functions 'ledger-post-maybe-align t t)) + (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 7b3df459..6ede6b51 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -70,20 +70,20 @@ reconcile-finish will mark all pending posting cleared." (account ledger-acct) (val nil)) (with-temp-buffer + ;; note that in the line below, the --format option is + ;; separated from the actual format string. emacs does not + ;; split arguments like the shell does, so you need to + ;; specify the individual fields in the command line. (ledger-exec-ledger buffer (current-buffer) - ; note that in the line below, the --format option is - ; separated from the actual format string. emacs does not - ; split arguments like the shell does, so you need to - ; specify the individual fields in the command line. "balance" "--limit" "cleared or pending" "--empty" "--format" "%(display_total)" account) - (setq val + (setq val (ledger-split-commodity-string (buffer-substring-no-properties (point-min) (point-max))))))) (defun ledger-display-balance () - "Display the cleared-or-pending balnce and calculate the -target-delta of the account being reconciled." + "Display the cleared-or-pending balance. +And calculate the target-delta of the account being reconciled." (interactive) (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance)) (target-delta (if ledger-target @@ -111,7 +111,7 @@ target-delta of the account being reconciled." "Return a buffer from WHERE the transaction is." (if (bufferp (car where)) (car where) - (error "ledger-reconcile-get-buffer: Buffer not set"))) + (error "Function ledger-reconcile-get-buffer: Buffer not set"))) (defun ledger-reconcile-toggle () "Toggle the current transaction, and mark the recon window." diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index b2247afe..dd5e42ad 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -122,42 +122,48 @@ dropped." ;;this excursion toggles the posting status (save-excursion - (goto-char (line-beginning-position)) - (when (looking-at "[ \t]") - (skip-chars-forward " \t") - (let ((here (point)) - (cur-status (ledger-state-from-char (char-after)))) - (skip-chars-forward "*! ") - (let ((width (- (point) here))) - (when (> width 0) - (delete-region here (point)) - (save-excursion - (if (search-forward " " (line-end-position) t) - (insert (make-string width ? )))))) - (let (inserted) - (if cur-status - (if (and style (eq style 'cleared)) - (progn - (insert "* ") - (setq inserted 'cleared))) - (if (and style (eq style 'pending)) - (progn - (insert "! ") - (setq inserted 'pending)) - (progn - (insert "* ") - (setq inserted 'cleared)))) - (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)))) - (setq new-status inserted))))) + (let ((has-align-hook (remove-hook + 'after-change-functions + 'ledger-post-maybe-align t))) + + (goto-char (line-beginning-position)) + (when (looking-at "[ \t]") + (skip-chars-forward " \t") + (let ((here (point)) + (cur-status (ledger-state-from-char (char-after)))) + (skip-chars-forward "*! ") + (let ((width (- (point) here))) + (when (> width 0) + (delete-region here (point)) + (save-excursion + (if (search-forward " " (line-end-position) t) + (insert (make-string width ? )))))) + (let (inserted) + (if cur-status + (if (and style (eq style 'cleared)) + (progn + (insert "* ") + (setq inserted 'cleared))) + (if (and style (eq style 'pending)) + (progn + (insert "! ") + (setq inserted 'pending)) + (progn + (insert "* ") + (setq inserted 'cleared)))) + (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)))) + (setq new-status inserted)))) + (if has-align-hook + (add-hook 'after-change-functions 'ledger-post-maybe-align t t)))) ;; This excursion cleans up the entry so that it displays ;; minimally. This means that if all posts are cleared, remove @@ -254,6 +260,4 @@ dropped." (provide 'ldg-state) -(provide 'ldg-state) - ;;; ldg-state.el ends here -- cgit v1.2.3 From 8f4b0e89627b082f9c5d4bd2b506661aab732b0b Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 8 Mar 2013 00:08:25 -0500 Subject: Added Ledger error handling. No more lisp backtraces! --- lisp/ldg-exec.el | 83 +++++++++++++++++++++++++++++++-------------------- lisp/ldg-reconcile.el | 53 ++++++++++++++++---------------- 2 files changed, 78 insertions(+), 58 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el index d62fd419..46775914 100644 --- a/lisp/ldg-exec.el +++ b/lisp/ldg-exec.el @@ -40,30 +40,48 @@ :type 'file :group 'ledger-exec) +(defun ledger-exec-handle-error (ledger-output) + "Deal with ledger errors contained in LEDGER-OUTPUT." + (with-current-buffer (get-buffer-create "*Ledger Error*") + (insert-buffer-substring ledger-output) + (make-frame) + (fit-frame) + (view-mode) + (toggle-read-only))) + +(defun ledger-exec-success-p (ledger-output-buffer) + (with-current-buffer ledger-output-buffer + (goto-char (point-min)) + (if (and (> (buffer-size) 1) (looking-at (regexp-quote "While"))) + nil + ledger-output-buffer))) + (defun ledger-exec-ledger (input-buffer &optional output-buffer &rest args) "Run Ledger using INPUT-BUFFER and optionally capturing output in OUTPUT-BUFFER with ARGS." (if (null ledger-binary-path) - (error "The variable `ledger-binary-path' has not been set")) - (let ((buf (or input-buffer (current-buffer))) - (outbuf (or output-buffer - (generate-new-buffer " *ledger-tmp*")))) - (with-current-buffer buf - (let ((coding-system-for-write 'utf-8) - (coding-system-for-read 'utf-8)) - (apply #'call-process-region - (append (list (point-min) (point-max) - ledger-binary-path nil outbuf nil "-f" "-") - args))) - outbuf))) - -(defun ledger-exec-read (&optional input-buffer &rest args) - "Run ledger from option INPUT-BUFFER using ARGS, return a list structure of the ledger Emacs output." - (with-current-buffer - (apply #'ledger-exec-ledger input-buffer nil "emacs" args) - (goto-char (point-min)) - (prog1 - (read (current-buffer)) - (kill-buffer (current-buffer))))) + (error "The variable `ledger-binary-path' has not been set") + (let ((buf (or input-buffer (current-buffer))) + (outbuf (or output-buffer + (generate-new-buffer " *ledger-tmp*")))) + (with-current-buffer buf + (let ((coding-system-for-write 'utf-8) + (coding-system-for-read 'utf-8)) + (apply #'call-process-region + (append (list (point-min) (point-max) + ledger-binary-path nil outbuf nil "-f" "-") + args))) + (if (ledger-exec-success-p outbuf) + outbuf + (ledger-exec-handle-error outbuf)))))) + +;; (defun ledger-exec-read (&optional input-buffer &rest args) +;; "Run ledger from option INPUT-BUFFER using ARGS, return a list structure of the ledger Emacs output." +;; (with-current-buffer +;; (apply #'ledger-exec-ledger input-buffer nil "emacs" args) +;; (goto-char (point-min)) +;; (prog1 +;; (read (current-buffer)) +;; (kill-buffer (current-buffer))))) (defun ledger-version-greater-p (needed) "Verify the ledger binary is usable for `ledger-mode' (version greater than NEEDED)." @@ -71,17 +89,18 @@ (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)))) + (if (ledger-exec-ledger (current-buffer) (current-buffer) "--version") + (progn + (goto-char (point-min)) + (delete-horizontal-space) + (setq version-strings (split-string + (buffer-substring-no-properties (point) + (point-max)))) + (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 () "Verify that ledger works and is modern enough." diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 6ede6b51..9f1a220c 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -74,28 +74,25 @@ reconcile-finish will mark all pending posting cleared." ;; separated from the actual format string. emacs does not ;; split arguments like the shell does, so you need to ;; specify the individual fields in the command line. - (ledger-exec-ledger buffer (current-buffer) - "balance" "--limit" "cleared or pending" "--empty" - "--format" "%(display_total)" account) - (setq val - (ledger-split-commodity-string - (buffer-substring-no-properties (point-min) (point-max))))))) + (if (ledger-exec-ledger buffer (current-buffer) + "balance" "--limit" "cleared or pending" "--empty" + "--format" "%(display_total)" account) + (setq val + (ledger-split-commodity-string + (buffer-substring-no-properties (point-min) (point-max)))))))) (defun ledger-display-balance () "Display the cleared-or-pending balance. And calculate the target-delta of the account being reconciled." (interactive) - (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance)) - (target-delta (if ledger-target - (-commodity ledger-target pending) - nil))) - - (if target-delta - (message "Pending balance: %s, Difference from target: %s" - (ledger-commodity-to-string pending) - (ledger-commodity-to-string target-delta)) - (message "Pending balance: %s" - (ledger-commodity-to-string pending))))) + (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance))) + (if pending + (if ledger-target + (message "Pending balance: %s, Difference from target: %s" + (ledger-commodity-to-string pending) + (ledger-commodity-to-string (-commodity ledger-target pending))) + (message "Pending balance: %s" + (ledger-commodity-to-string pending)))))) @@ -276,16 +273,18 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." "Get the uncleared transactions in the account and display them in the *Reconcile* buffer." (let* ((buf ledger-buf) (account ledger-acct) + (ledger-success nil) (xacts (with-temp-buffer - (ledger-exec-ledger buf (current-buffer) - "--uncleared" "--real" "emacs" account) - (goto-char (point-min)) - (unless (eobp) - (unless (looking-at "(") - (error (concat "ledger-do-reconcile: " (buffer-string)))) - (read (current-buffer)))))) ;current-buffer is the *temp* created above - (if (> (length xacts) 0) + (if (ledger-exec-ledger buf (current-buffer) + "--uncleared" "--real" "emacs" account) + (progn + (setq ledger-success t) + (goto-char (point-min)) + (unless (eobp) + (if (looking-at "(") + (read (current-buffer))))))))) ;current-buffer is the *temp* created above + (if (and ledger-success (> (length xacts) 0)) (progn (dolist (xact xacts) (dolist (posting (nthcdr 5 xact)) @@ -310,7 +309,9 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." 'where where)))) )) (goto-char (point-max)) (delete-char -1)) ;gets rid of the extra line feed at the bottom of the list - (insert (concat "There are no uncleared entries for " account))) + (if ledger-success + (insert (concat "There are no uncleared entries for " account)) + (insert "Ledger has reported a problem. Check *Ledger Error* buffer."))) (goto-char (point-min)) (set-buffer-modified-p nil) (toggle-read-only t) -- cgit v1.2.3 From bfe360d4c992caf2e7da09ab058599c0404f1348 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 8 Mar 2013 19:33:16 -0500 Subject: Reconcile date configuration is pulled from ledgerrc --- lisp/ldg-reconcile.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 9f1a220c..802cb3b4 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -285,13 +285,15 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (if (looking-at "(") (read (current-buffer))))))))) ;current-buffer is the *temp* created above (if (and ledger-success (> (length xacts) 0)) - (progn + (let ((date-format (cdr (assoc "date-format" ledger-environment-alist)))) (dolist (xact xacts) (dolist (posting (nthcdr 5 xact)) (let ((beg (point)) (where (ledger-marker-where-xact-is xact posting))) (insert (format "%s %-4s %-30s %-30s %15s\n" - (format-time-string "%Y/%m/%d" (nth 2 xact)) + (format-time-string (if date-format + date-format + "%Y/%m/%d") (nth 2 xact)) (if (nth 3 xact) (nth 3 xact) "") -- cgit v1.2.3 From c85f397edc33f895921b7900f938cd9cbb9f0e16 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 13 Mar 2013 10:20:21 -0700 Subject: Cleaned up ledger-reconcile, easier to read, fewer lines of code. --- lisp/ldg-reconcile.el | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 802cb3b4..9a6c7b67 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -363,6 +363,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." ;; only one ;; *Reconcile* ;; buffer, ever + ;; Set up the reconcile buffer (if rbuf ;; *Reconcile* already exists (with-current-buffer rbuf (set 'ledger-acct account) ;; already buffer local @@ -371,31 +372,31 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (ledger-reconcile-quit-cleanup) (set 'ledger-buf buf))) ;; should already be ;; buffer-local - (if ledger-fold-on-reconcile - (ledger-occur-change-regex account ledger-buf)) - (set-buffer (get-buffer ledger-recon-buffer-name)) + (unless (get-buffer-window rbuf) - (ledger-reconcile-open-windows buf rbuf)) - (ledger-reconcile-refresh) - (goto-char (point-min)) - (setq ledger-target - (ledger-read-commodity-string "Set reconciliation target")) - (ledger-display-balance)) - - (progn ;; no recon-buffer, starting from scratch. - (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) - (if ledger-fold-on-reconcile - (ledger-occur-mode account buf)) - - (with-current-buffer (get-buffer-create ledger-recon-buffer-name) - (ledger-reconcile-open-windows buf (current-buffer)) - (ledger-reconcile-mode) - (set (make-local-variable 'ledger-buf) buf) - (set (make-local-variable 'ledger-acct) account) - (ledger-do-reconcile) - (set (make-local-variable 'ledger-target) - (ledger-read-commodity-string "Set reconciliation target")) - (ledger-display-balance)))))) + (ledger-reconcile-open-windows buf rbuf))) + + (progn ;; no recon-buffer, starting from scratch. + (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) + + (with-current-buffer (setq rbuf + (get-buffer-create ledger-recon-buffer-name)) + (ledger-reconcile-open-windows buf rbuf) + (ledger-reconcile-mode) + (make-local-variable 'ledger-target) + (set (make-local-variable 'ledger-buf) buf) + (set (make-local-variable 'ledger-acct) account)))) + + ;; Fold the ledger buffer + (if ledger-fold-on-reconcile + (ledger-occur-mode account buf)) + + ;; Now, actually run the reconciliation + (with-current-buffer rbuf + (ledger-reconcile-refresh) + (goto-char (point-min)) + (ledger-reconcile-change-target) + (ledger-display-balance)))) (defvar ledger-reconcile-mode-abbrev-table) -- cgit v1.2.3 From 027c03858d5292a2c66888133a5a464514f5a8ab Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 13 Mar 2013 10:57:43 -0700 Subject: More reconcile restructuring. --- lisp/ldg-reconcile.el | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 9a6c7b67..37d6f32c 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -318,11 +318,13 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (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. + (ledger-reconcile-ensure-xacts-visible))) + +(defun ledger-reconcile-ensure-xacts-visible () + "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)))) (when recon-window @@ -335,10 +337,10 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (recenter -1)) (select-window recon-window) (ledger-reconcile-visit t)) - (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t)))) + (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t))) (defun ledger-reconcile-track-xact () - "Force the ledger buffer to recenter on the transactionat point in the reconcile buffer." + "Force the ledger buffer to recenter on the transaction at point in the reconcile buffer." (if (member this-command (list 'next-line 'previous-line 'mouse-set-point @@ -388,11 +390,12 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (set (make-local-variable 'ledger-acct) account)))) ;; Fold the ledger buffer - (if ledger-fold-on-reconcile - (ledger-occur-mode account buf)) ;; Now, actually run the reconciliation (with-current-buffer rbuf + (save-excursion + (if ledger-fold-on-reconcile + (ledger-occur-mode account ledger-buf))) (ledger-reconcile-refresh) (goto-char (point-min)) (ledger-reconcile-change-target) -- cgit v1.2.3 From b608ed23e413aaec6024c42c453f8cd9854498d7 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 13 Mar 2013 11:27:51 -0700 Subject: Reconcile skips asking for target if there are no uncleared xacts. --- lisp/ldg-reconcile.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 37d6f32c..ec4b7f88 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -145,15 +145,16 @@ And calculate the target-delta of the account being reconciled." (ledger-display-balance))) (defun ledger-reconcile-refresh () - "Force the reconciliation window to refresh." + "Force the reconciliation window to refresh. +Return the number of uncleared xacts found." (interactive) (let ((inhibit-read-only t) (line (count-lines (point-min) (point)))) (erase-buffer) - (ledger-do-reconcile) - (set-buffer-modified-p t) - (goto-char (point-min)) - (forward-line line))) + (prog1 (ledger-do-reconcile) + (set-buffer-modified-p t) + (goto-char (point-min)) + (forward-line line)))) (defun ledger-reconcile-refresh-after-save () "Refresh the recon-window after the ledger buffer is saved." @@ -270,7 +271,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (nth 0 posting))))) ;; return line-no of posting (defun ledger-do-reconcile () - "Get the uncleared transactions in the account and display them in the *Reconcile* buffer." + "Return the number of uncleared transactions in the account and display them in the *Reconcile* buffer." (let* ((buf ledger-buf) (account ledger-acct) (ledger-success nil) @@ -318,7 +319,8 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (set-buffer-modified-p nil) (toggle-read-only t) - (ledger-reconcile-ensure-xacts-visible))) + (ledger-reconcile-ensure-xacts-visible) + (length xacts))) (defun ledger-reconcile-ensure-xacts-visible () "Ensures that the last of the visible transactions in the @@ -396,9 +398,8 @@ moved and recentered. If they aren't strange things happen." (save-excursion (if ledger-fold-on-reconcile (ledger-occur-mode account ledger-buf))) - (ledger-reconcile-refresh) - (goto-char (point-min)) - (ledger-reconcile-change-target) + (if (> (ledger-reconcile-refresh) 0) + (ledger-reconcile-change-target)) (ledger-display-balance)))) (defvar ledger-reconcile-mode-abbrev-table) -- cgit v1.2.3 From f89665ba44ae50f056363d7e2c79a508060e2d18 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 14 Mar 2013 11:37:12 -0700 Subject: Reconcile code cleanup --- lisp/ldg-reconcile.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ec4b7f88..c5e20c64 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -148,13 +148,11 @@ And calculate the target-delta of the account being reconciled." "Force the reconciliation window to refresh. Return the number of uncleared xacts found." (interactive) - (let ((inhibit-read-only t) - (line (count-lines (point-min) (point)))) + (let ((inhibit-read-only t)) (erase-buffer) (prog1 (ledger-do-reconcile) (set-buffer-modified-p t) - (goto-char (point-min)) - (forward-line line)))) + (goto-char (point-min))))) (defun ledger-reconcile-refresh-after-save () "Refresh the recon-window after the ledger buffer is saved." -- cgit v1.2.3 From b1c2c49709c9f2e9a2c0bb715a2e599094483498 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 17 Mar 2013 19:56:02 -0700 Subject: Fix bug 917 C-Begin C-End don't keep buffer synced --- lisp/ldg-reconcile.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index c5e20c64..a2c13917 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -344,7 +344,9 @@ moved and recentered. If they aren't strange things happen." (if (member this-command (list 'next-line 'previous-line 'mouse-set-point - 'ledger-reconcile-toggle)) + 'ledger-reconcile-toggle + 'end-of-buffer + 'beginning-of-buffer)) (if ledger-buffer-tracks-reconcile-buffer (save-excursion (ledger-reconcile-visit t))))) -- cgit v1.2.3 From 431d7e5b25f7e2997494ace7a0be78492c5d688b Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 17 Mar 2013 20:01:58 -0700 Subject: Fix bug 915 Save in reconcile mode maintains point. --- lisp/ldg-reconcile.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index a2c13917..40795ca2 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -205,11 +205,13 @@ Return the number of uncleared xacts found." (defun ledger-reconcile-save () "Save the ledger buffer." (interactive) - (dolist (buf (cons ledger-buf ledger-bufs)) - (with-current-buffer buf - (save-buffer))) - (set-buffer-modified-p nil) - (ledger-display-balance)) + (let ((curpoint (point))) + (dolist (buf (cons ledger-buf ledger-bufs)) + (with-current-buffer buf + (save-buffer))) + (set-buffer-modified-p nil) + (ledger-display-balance) + (goto-char curpoint))) (defun ledger-reconcile-finish () "Mark all pending posting or transactions as cleared. -- cgit v1.2.3 From 5b7186ee1fd99e547b6a9f062f155a1a8050e9c3 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 18 Mar 2013 15:22:41 -0700 Subject: Ensure the ledger but tracks the reconcile buffer after a save. --- lisp/ldg-reconcile.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 40795ca2..511f8f70 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -209,9 +209,11 @@ Return the number of uncleared xacts found." (dolist (buf (cons ledger-buf ledger-bufs)) (with-current-buffer buf (save-buffer))) - (set-buffer-modified-p nil) - (ledger-display-balance) - (goto-char curpoint))) + (with-current-buffer (get-buffer ledger-recon-buffer-name) + (set-buffer-modified-p nil) + (ledger-display-balance) + (goto-char curpoint) + (ledger-reconcile-visit t)))) (defun ledger-reconcile-finish () "Mark all pending posting or transactions as cleared. -- cgit v1.2.3 From b73e650e5f9dd2f3b2c90f445b878258f1e994d0 Mon Sep 17 00:00:00 2001 From: Rémi Vanicat Date: Thu, 21 Mar 2013 23:28:14 +0100 Subject: Don't fail cleaning after reconcile when some buffer have been killed If buffer in leger-buf has been killed, ledger-reconcile-quit-cleanup will fail with an error. Better to do nothing. --- lisp/ldg-reconcile.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 511f8f70..662ef6c1 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -252,7 +252,7 @@ and exit reconcile mode" "Cleanup all hooks established by reconcile mode." (interactive) (let ((buf ledger-buf)) - (if buf + (if (buffer-live-p buf) (with-current-buffer buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) (if ledger-fold-on-reconcile -- cgit v1.2.3 From 9284600a54c8b4d37b63d25dd9e16dba664badbe Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 22 Mar 2013 21:23:27 -0700 Subject: Fix bug 915, maintain post in ledger buffer after save during reconciliation. --- lisp/ldg-reconcile.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 511f8f70..99958aaa 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -152,15 +152,20 @@ Return the number of uncleared xacts found." (erase-buffer) (prog1 (ledger-do-reconcile) (set-buffer-modified-p t) - (goto-char (point-min))))) + ;;(goto-char (point-min)) + ))) (defun ledger-reconcile-refresh-after-save () "Refresh the recon-window after the ledger buffer is saved." - (let ((buf (get-buffer ledger-recon-buffer-name))) + (let ((curbuf (current-buffer)) + (curpoint (point)) + (buf (get-buffer ledger-recon-buffer-name))) (if buf - (with-current-buffer buf - (ledger-reconcile-refresh) - (set-buffer-modified-p nil))))) + (progn + (with-current-buffer buf + (ledger-reconcile-refresh) + (set-buffer-modified-p nil)) + (select-window (get-buffer-window curbuf)))))) (defun ledger-reconcile-add () "Use ledger xact to add a new transaction." -- cgit v1.2.3 From f855d7e745a41f8c91f0d6f593274df794a83589 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sat, 23 Mar 2013 20:09:07 -0700 Subject: Finish bug 929 got rid of all references to folding, use narrowing instead. --- doc/ledger-mode.texi | 6 +++--- lisp/ldg-fonts.el | 2 +- lisp/ldg-occur.el | 14 +++++++------- lisp/ldg-reconcile.el | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index def583ca..70a5d97a 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -614,7 +614,7 @@ for Ledger under the data options. Alternately you can choose @node Ledger Customization Group, Ledger Reconcile Customization Group, Customization Variables, Customization Variables @subsection Ledger Customization Group @table @code -@item ledger-occur-use-face-unfolded +@item ledger-occur-use-face-shown If non-nil, use a custom face for xacts shown in `ledger-occur' mode using @code{ledger-occur-xact-face}. @item ledger-clear-whole-transactions If non-nil, clear whole transactions, not individual postings. @@ -631,7 +631,7 @@ The default commodity for use in target calculations in ledger reconcile. Defaults to $ (USD) @item ledger-recon-buffer-name Name to use for reconciliation window. -@item ledger-fold-on-reconcile +@item ledger-narrow-on-reconcile If non-nil, limit transactions shown in main buffer to those matching the reconcile regex. @item ledger-buffer-tracks-reconcile-buffer @@ -674,7 +674,7 @@ Default face for other transactions Face for Ledger accounts @item ledger-font-posting-amount-face Face for Ledger amounts -@item ledger-occur-folded-face +@item ledger-occur-narrowed-face Default face for Ledger occur mode hidden transactions @item ledger-occur-xact-face Default face for Ledger occur mode shown transactions diff --git a/lisp/ldg-fonts.el b/lisp/ldg-fonts.el index d760140c..76bfc03d 100644 --- a/lisp/ldg-fonts.el +++ b/lisp/ldg-fonts.el @@ -62,7 +62,7 @@ "Face for Ledger amounts" :group 'ledger-faces) -(defface ledger-occur-folded-face +(defface ledger-occur-narrowed-face `((t :foreground "grey70" :invisible t )) "Default face for Ledger occur mode hidden transactions" :group 'ledger-faces) diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index 35ca7f3d..28d87b78 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -20,7 +20,7 @@ ;; MA 02111-1307, USA. ;;; Commentary: -;; Provide code folding to ledger mode. Adapted from original loccur +;; Provide buffer narrowing to ledger mode. Adapted from original loccur ;; mode by Alexey Veretennikov ;; @@ -31,11 +31,11 @@ (defconst ledger-occur-overlay-property-name 'ledger-occur-custom-buffer-grep) -(defcustom ledger-occur-use-face-unfolded t +(defcustom ledger-occur-use-face-shown t "If non-nil, use a custom face for xacts shown in `ledger-occur' mode using ledger-occur-xact-face." :type 'boolean :group 'ledger) -(make-variable-buffer-local 'ledger-occur-use-face-unfolded) +(make-variable-buffer-local 'ledger-occur-use-face-shown) (defvar ledger-occur-mode nil @@ -69,7 +69,7 @@ When REGEX is nil, unhide everything, and remove higlight" (if (or (null regex) (zerop (length regex))) nil - (concat " Ledger-Folded: " regex))) + (concat " Ledger-Narrowed: " regex))) (force-mode-line-update) (ledger-occur-remove-overlays) (if ledger-occur-mode @@ -79,7 +79,7 @@ When REGEX is nil, unhide everything, and remove higlight" (ledger-occur-create-xact-overlays ovl-bounds)) (setq ledger-occur-overlay-list (append ledger-occur-overlay-list - (ledger-occur-create-folded-overlays buffer-matches))) + (ledger-occur-create-narrowed-overlays buffer-matches))) (setq ledger-occur-last-match regex) (if (get-buffer-window buffer) (select-window (get-buffer-window buffer))))) @@ -116,7 +116,7 @@ When REGEX is nil, unhide everything, and remove higlight" (current-word)))) prompt)) -(defun ledger-occur-create-folded-overlays(buffer-matches) +(defun ledger-occur-create-narrowed-overlays(buffer-matches) (if buffer-matches (let ((overlays (let ((prev-end (point-min)) @@ -156,7 +156,7 @@ Argument OVL-BOUNDS contains bounds for the transactions to be left visible." ovl-bounds))) (mapcar (lambda (ovl) (overlay-put ovl ledger-occur-overlay-property-name t) - (if ledger-occur-use-face-unfolded + (if ledger-occur-use-face-shown (overlay-put ovl 'face 'ledger-occur-xact-face ))) overlays))) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index c33eef2e..a4960260 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -40,7 +40,7 @@ "Name to use for reconciliation window." :group 'ledger-reconcile) -(defcustom ledger-fold-on-reconcile t +(defcustom ledger-narrow-on-reconcile t "If t, limit transactions shown in main buffer to those matching the reconcile regex." :type 'boolean :group 'ledger-reconcile) @@ -260,7 +260,7 @@ and exit reconcile mode" (if (buffer-live-p buf) (with-current-buffer buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) - (if ledger-fold-on-reconcile + (if ledger-narrow-on-reconcile (progn (ledger-occur-quit-buffer buf) (ledger-highlight-xact-under-point))))))) @@ -400,12 +400,12 @@ moved and recentered. If they aren't strange things happen." (set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-acct) account)))) - ;; Fold the ledger buffer + ;; Narrow the ledger buffer ;; Now, actually run the reconciliation (with-current-buffer rbuf (save-excursion - (if ledger-fold-on-reconcile + (if ledger-narrow-on-reconcile (ledger-occur-mode account ledger-buf))) (if (> (ledger-reconcile-refresh) 0) (ledger-reconcile-change-target)) -- cgit v1.2.3 From 0bcef93e29a67310cef209074f2162415f1cffd3 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sat, 23 Mar 2013 20:22:40 -0700 Subject: Bug 915 maintain point in buffer when saved. --- lisp/ldg-reconcile.el | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index a4960260..3d73cca9 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -159,13 +159,14 @@ Return the number of uncleared xacts found." "Refresh the recon-window after the ledger buffer is saved." (let ((curbuf (current-buffer)) (curpoint (point)) - (buf (get-buffer ledger-recon-buffer-name))) - (if buf + (recon-buf (get-buffer ledger-recon-buffer-name))) + (if (buffer-live-p recon-buf) (progn - (with-current-buffer buf - (ledger-reconcile-refresh) - (set-buffer-modified-p nil)) - (select-window (get-buffer-window curbuf)))))) + (with-current-buffer recon-buf + (ledger-reconcile-refresh) + (set-buffer-modified-p nil)) + (select-window (get-buffer-window curbuf)) + (goto-char curpoint))))) (defun ledger-reconcile-add () "Use ledger xact to add a new transaction." @@ -211,14 +212,14 @@ Return the number of uncleared xacts found." "Save the ledger buffer." (interactive) (let ((curpoint (point))) - (dolist (buf (cons ledger-buf ledger-bufs)) - (with-current-buffer buf - (save-buffer))) - (with-current-buffer (get-buffer ledger-recon-buffer-name) - (set-buffer-modified-p nil) - (ledger-display-balance) - (goto-char curpoint) - (ledger-reconcile-visit t)))) + (dolist (buf (cons ledger-buf ledger-bufs)) + (with-current-buffer buf + (save-buffer))) + (with-current-buffer (get-buffer ledger-recon-buffer-name) + (set-buffer-modified-p nil) + (ledger-display-balance) + (goto-char curpoint) + (ledger-reconcile-visit t)))) (defun ledger-reconcile-finish () "Mark all pending posting or transactions as cleared. @@ -401,8 +402,6 @@ moved and recentered. If they aren't strange things happen." (set (make-local-variable 'ledger-acct) account)))) ;; Narrow the ledger buffer - - ;; Now, actually run the reconciliation (with-current-buffer rbuf (save-excursion (if ledger-narrow-on-reconcile -- cgit v1.2.3 From d3fe4c666ff37912245d2a0386ac749737f34843 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 25 Mar 2013 01:21:19 -0400 Subject: Lots of code cleanup. (if () (progn …) ==> (when () …) all over the place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lisp/ldg-commodities.el | 2 +- lisp/ldg-complete.el | 11 ++--- lisp/ldg-exec.el | 31 ++++++------- lisp/ldg-init.el | 22 ++++----- lisp/ldg-occur.el | 50 ++++++++++----------- lisp/ldg-post.el | 2 +- lisp/ldg-reconcile.el | 117 +++++++++++++++++++++++------------------------- lisp/ldg-report.el | 53 +++++++++++----------- lisp/ldg-schedule.el | 2 +- lisp/ldg-sort.el | 32 ++++++------- lisp/ldg-state.el | 7 ++- lisp/ldg-xact.el | 13 +++--- 12 files changed, 156 insertions(+), 186 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index f664c472..0eb435b5 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -50,7 +50,7 @@ (string-to-number (ledger-commodity-string-number-decimalize (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)) - (nth 0 (split-string (buffer-substring (point-min) (point-max)))))) + (nth 0 (split-string (buffer-substring-no-properties (point-min) (point-max)))))) ((re-search-forward "0" nil t) ;; couldn't find a decimal number, look for a single 0, ;; indicating account with zero balance diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index fa0bf87a..a8e73b88 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -19,9 +19,6 @@ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. -;;(require 'esh-util) -;;(require 'esh-arg) - ;;; Commentary: ;; Functions providing payee and account auto complete. @@ -126,8 +123,8 @@ Return tree structure" (if (null current-prefix-arg) (ledger-payees-in-buffer) ;; this completes against payee names (progn - (let ((text (buffer-substring (line-beginning-position) - (line-end-position)))) + (let ((text (buffer-substring-no-properties (line-beginning-position) + (line-end-position)))) (delete-region (line-beginning-position) (line-end-position)) (condition-case err @@ -154,7 +151,7 @@ Does not use ledger xact" ;; Search backward for a matching payee (when (re-search-backward (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.*" - (regexp-quote name) ".*\\)" ) nil t) ;; "\\(\t\\|\n\\| [ \t]\\)" + (regexp-quote name) ".*\\)" ) nil t) (setq rest-of-name (match-string 3)) ;; Start copying the postings (forward-line) @@ -180,7 +177,7 @@ Does not use ledger xact" (defun ledger-pcomplete (&optional interactively) "Complete rip-off of pcomplete from pcomplete.el, only added -ledger-magic-tab in the previos commads list so that +ledger-magic-tab in the previous commands list so that ledger-magic-tab would cycle properly" (interactive "p") (if (and interactively diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el index 31621f9f..4a485072 100644 --- a/lisp/ldg-exec.el +++ b/lisp/ldg-exec.el @@ -53,7 +53,7 @@ (with-current-buffer ledger-output-buffer (goto-char (point-min)) (if (and (> (buffer-size) 1) (looking-at (regexp-quote "While"))) - nil + nil ;; failure, there is an error starting with "While" ledger-output-buffer))) (defun ledger-exec-ledger (input-buffer &optional output-buffer &rest args) @@ -77,27 +77,24 @@ (defun ledger-version-greater-p (needed) "Verify the ledger binary is usable for `ledger-mode' (version greater than NEEDED)." (let ((buffer ledger-buf) - (version-strings '()) - (version-number)) + (version-strings '())) (with-temp-buffer - (if (ledger-exec-ledger (current-buffer) (current-buffer) "--version") - (progn - (goto-char (point-min)) - (delete-horizontal-space) - (setq version-strings (split-string - (buffer-substring-no-properties (point) - (point-max)))) - (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)))))) + (when (ledger-exec-ledger (current-buffer) (current-buffer) "--version") + (goto-char (point-min)) + (delete-horizontal-space) + (setq version-strings (split-string + (buffer-substring-no-properties (point) + (point-max)))) + (if (and (string-match (regexp-quote "Ledger") (car version-strings)) + (or (string= needed (cadr version-strings)) + (string< needed (cadr version-strings)))) + t ;; success + nil))))) ;;failure (defun ledger-check-version () "Verify that ledger works and is modern enough." (interactive) - (setq ledger-works (ledger-version-greater-p ledger-version-needed)) - (if ledger-works + (if (setq ledger-works (ledger-version-greater-p ledger-version-needed)) (message "Good Ledger Version") (message "Bad Ledger Version"))) diff --git a/lisp/ldg-init.el b/lisp/ldg-init.el index 72317088..8e657323 100644 --- a/lisp/ldg-init.el +++ b/lisp/ldg-init.el @@ -33,16 +33,16 @@ (setq ledger-environment-alist nil) (goto-char (point-min)) (while (re-search-forward "^--.+?\\($\\|[ ]\\)" nil t ) - (let ((matchb (match-beginning 0)) ;; save the match data, string-match stomp on it + (let ((matchb (match-beginning 0)) ;; save the match data, string-match stamp on it (matche (match-end 0))) (end-of-line) (setq ledger-environment-alist (append ledger-environment-alist - (list (cons (let ((flag (buffer-substring (+ 2 matchb) matche))) + (list (cons (let ((flag (buffer-substring-no-properties (+ 2 matchb) matche))) (if (string-match "[ \t\n\r]+\\'" flag) (replace-match "" t t flag) flag)) - (let ((value (buffer-substring matche (point) ))) + (let ((value (buffer-substring-no-properties matche (point) ))) (if (> (length value) 0) value t)))))))) @@ -53,16 +53,12 @@ (let ((init-base-name (file-name-nondirectory ledger-init-file-name))) (if (get-buffer init-base-name) ;; init file already loaded, parse it and leave it (ledger-init-parse-initialization init-base-name) - (if (and ;; init file not loaded, load, parse and kill - ledger-init-file-name - (file-exists-p ledger-init-file-name) - (file-readable-p ledger-init-file-name)) - (progn - (find-file-noselect ledger-init-file-name) - (ledger-init-parse-initialization init-base-name) - (kill-buffer init-base-name)))))) - - + (when (and ledger-init-file-name + (file-exists-p ledger-init-file-name) + (file-readable-p ledger-init-file-name)) + (find-file-noselect ledger-init-file-name) + (ledger-init-parse-initialization init-base-name) + (kill-buffer init-base-name))))) (provide 'ldg-init) diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index 28d87b78..a2e53cb0 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -63,27 +63,24 @@ "Highlight transactions that match REGEX in BUFFER, hiding others. When REGEX is nil, unhide everything, and remove higlight" - (progn - (set-buffer buffer) - (setq ledger-occur-mode - (if (or (null regex) - (zerop (length regex))) - nil - (concat " Ledger-Narrowed: " 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-narrowed-overlays buffer-matches))) - (setq ledger-occur-last-match regex) - (if (get-buffer-window buffer) - (select-window (get-buffer-window buffer))))) - (recenter))) + (set-buffer buffer) + (setq ledger-occur-mode + (if (or (null regex) + (zerop (length regex))) + nil + (concat " Ledger-Narrowed: " 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 + (append (ledger-occur-create-xact-overlays ovl-bounds) + (ledger-occur-create-narrowed-overlays buffer-matches))) + (setq ledger-occur-last-match regex) + (if (get-buffer-window buffer) + (select-window (get-buffer-window buffer))))) + (recenter)) (defun ledger-occur (regex) "Perform a simple grep in current buffer for the regular expression REGEX. @@ -163,12 +160,11 @@ Argument OVL-BOUNDS contains bounds for the transactions to be left visible." (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))) + (set-buffer buffer) + (setq ledger-occur-mode nil) + (force-mode-line-update) + (ledger-occur-remove-overlays) + (recenter)) (defun ledger-occur-remove-overlays () "Remove the transaction hiding overlays." diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index bbed297d..c831f01a 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -135,7 +135,7 @@ Return the width of the amount field as an integer." (match-end 3)) (point)))) (defvar ledger-post-account-regex - (concat "\\(^[ ]+\\)" + (concat "\\(^[ \t]+\\)" "\\([\\[(*!;a-zA-Z0-9]+?\\)")) (defun ledger-next-account (&optional end) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 3d73cca9..3d3b7c92 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -66,9 +66,10 @@ reconcile-finish will mark all pending posting cleared." (defun ledger-reconcile-get-cleared-or-pending-balance () "Calculate the cleared or pending balance of the account." (interactive) - (let ((buffer ledger-buf) - (account ledger-acct) - (val nil)) + ;; these vars are buffer local, need to hold them for use in the + ;; temp buffer below + (let ((buffer ledger-buf) + (account ledger-acct)) (with-temp-buffer ;; note that in the line below, the --format option is ;; separated from the actual format string. emacs does not @@ -77,16 +78,15 @@ reconcile-finish will mark all pending posting cleared." (if (ledger-exec-ledger buffer (current-buffer) "balance" "--limit" "cleared or pending" "--empty" "--format" "%(display_total)" account) - (setq val - (ledger-split-commodity-string - (buffer-substring-no-properties (point-min) (point-max)))))))) + (ledger-split-commodity-string + (buffer-substring-no-properties (point-min) (point-max))))))) (defun ledger-display-balance () "Display the cleared-or-pending balance. And calculate the target-delta of the account being reconciled." (interactive) (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance))) - (if pending + (when pending (if ledger-target (message "Pending balance: %s, Difference from target: %s" (ledger-commodity-to-string pending) @@ -150,23 +150,21 @@ Return the number of uncleared xacts found." (interactive) (let ((inhibit-read-only t)) (erase-buffer) - (prog1 (ledger-do-reconcile) - (set-buffer-modified-p t) - ;;(goto-char (point-min)) - ))) + (prog1 + (ledger-do-reconcile) + (set-buffer-modified-p t)))) (defun ledger-reconcile-refresh-after-save () "Refresh the recon-window after the ledger buffer is saved." (let ((curbuf (current-buffer)) (curpoint (point)) (recon-buf (get-buffer ledger-recon-buffer-name))) - (if (buffer-live-p recon-buf) - (progn - (with-current-buffer recon-buf - (ledger-reconcile-refresh) - (set-buffer-modified-p nil)) - (select-window (get-buffer-window curbuf)) - (goto-char curpoint))))) + (when (buffer-live-p recon-buf) + (with-current-buffer recon-buf + (ledger-reconcile-refresh) + (set-buffer-modified-p nil)) + (select-window (get-buffer-window curbuf)) + (goto-char curpoint)))) (defun ledger-reconcile-add () "Use ledger xact to add a new transaction." @@ -247,7 +245,7 @@ and exit reconcile mode" (if recon-buf (with-current-buffer recon-buf (ledger-reconcile-quit-cleanup) - (set 'buf ledger-buf) + (setq buf ledger-buf) ;; Make sure you delete the window before you delete the buffer, ;; otherwise, madness ensues (delete-window (get-buffer-window recon-buf)) @@ -261,10 +259,9 @@ and exit reconcile mode" (if (buffer-live-p buf) (with-current-buffer buf (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) - (if ledger-narrow-on-reconcile - (progn - (ledger-occur-quit-buffer buf) - (ledger-highlight-xact-under-point))))))) + (when ledger-narrow-on-reconcile + (ledger-occur-quit-buffer buf) + (ledger-highlight-xact-under-point)))))) (defun ledger-marker-where-xact-is (emacs-xact posting) "Find the position of the EMACS-XACT in the `ledger-buf'. @@ -285,14 +282,13 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (ledger-success nil) (xacts (with-temp-buffer - (if (ledger-exec-ledger buf (current-buffer) - "--uncleared" "--real" "emacs" account) - (progn - (setq ledger-success t) - (goto-char (point-min)) - (unless (eobp) - (if (looking-at "(") - (read (current-buffer))))))))) ;current-buffer is the *temp* created above + (when (ledger-exec-ledger buf (current-buffer) + "--uncleared" "--real" "emacs" account) + (setq ledger-success t) + (goto-char (point-min)) + (unless (eobp) + (if (looking-at "(") + (read (current-buffer)))))))) ;current-buffer is the *temp* created above (if (and ledger-success (> (length xacts) 0)) (let ((date-format (cdr (assoc "date-format" ledger-environment-alist)))) (dolist (xact xacts) @@ -351,15 +347,15 @@ moved and recentered. If they aren't strange things happen." (defun ledger-reconcile-track-xact () "Force the ledger buffer to recenter on the transaction at point in the reconcile buffer." - (if (member this-command (list 'next-line - 'previous-line - 'mouse-set-point - 'ledger-reconcile-toggle - 'end-of-buffer - 'beginning-of-buffer)) - (if ledger-buffer-tracks-reconcile-buffer - (save-excursion - (ledger-reconcile-visit t))))) + (if (and ledger-buffer-tracks-reconcile-buffer + (member this-command (list 'next-line + 'previous-line + 'mouse-set-point + 'ledger-reconcile-toggle + 'end-of-buffer + 'beginning-of-buffer))) + (save-excursion + (ledger-reconcile-visit t)))) (defun ledger-reconcile-open-windows (buf rbuf) "Ensure that the ledger buffer BUF is split by RBUF." @@ -373,33 +369,30 @@ moved and recentered. If they aren't strange things happen." (interactive) (let ((account (ledger-post-read-account-with-prompt "Account to reconcile")) (buf (current-buffer)) - (rbuf (get-buffer ledger-recon-buffer-name))) ;; this means - ;; only one - ;; *Reconcile* - ;; buffer, ever - ;; Set up the reconcile buffer - (if rbuf ;; *Reconcile* already exists + (rbuf (get-buffer ledger-recon-buffer-name))) + ;; this means only one *Reconcile* buffer, ever Set up the + ;; reconcile buffer + (if rbuf ;; *Reconcile* already exists (with-current-buffer rbuf - (set 'ledger-acct account) ;; already buffer local - (if (not (eq buf rbuf)) - (progn ;; called from some other ledger-mode buffer - (ledger-reconcile-quit-cleanup) - (set 'ledger-buf buf))) ;; should already be - ;; buffer-local + (set 'ledger-acct account) ;; already buffer local + (when (not (eq buf rbuf)) + ;; called from some other ledger-mode buffer + (ledger-reconcile-quit-cleanup) + (set 'ledger-buf buf)) ;; should already be buffer-local (unless (get-buffer-window rbuf) (ledger-reconcile-open-windows buf rbuf))) - (progn ;; no recon-buffer, starting from scratch. - (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) - - (with-current-buffer (setq rbuf - (get-buffer-create ledger-recon-buffer-name)) - (ledger-reconcile-open-windows buf rbuf) - (ledger-reconcile-mode) - (make-local-variable 'ledger-target) - (set (make-local-variable 'ledger-buf) buf) - (set (make-local-variable 'ledger-acct) account)))) + ;; no recon-buffer, starting from scratch. + (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) + + (with-current-buffer (setq rbuf + (get-buffer-create ledger-recon-buffer-name)) + (ledger-reconcile-open-windows buf rbuf) + (ledger-reconcile-mode) + (make-local-variable 'ledger-target) + (set (make-local-variable 'ledger-buf) buf) + (set (make-local-variable 'ledger-acct) account))) ;; Narrow the ledger buffer (with-current-buffer rbuf diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 8e642a61..4f14fdcb 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -30,8 +30,7 @@ (defgroup ledger-report nil "Customization option for the Report buffer" - :group 'ledger -) + :group 'ledger) (defcustom ledger-reports '(("bal" "ledger -f %(ledger-file) bal") @@ -319,18 +318,17 @@ Optional EDIT the command." (let ((file (match-string 1)) (line (string-to-number (match-string 2)))) (delete-region (match-beginning 0) (match-end 0)) - (if file - (progn - (set-text-properties (line-beginning-position) (line-end-position) - (list 'ledger-source (cons file (save-window-excursion - (save-excursion - (find-file file) - (widen) - (ledger-goto-line line) - (point-marker)))))) - (add-text-properties (line-beginning-position) (line-end-position) - (list 'face 'ledger-font-report-clickable-face)) - (end-of-line)))))) + (when file + (set-text-properties (line-beginning-position) (line-end-position) + (list 'ledger-source (cons file (save-window-excursion + (save-excursion + (find-file file) + (widen) + (ledger-goto-line line) + (point-marker)))))) + (add-text-properties (line-beginning-position) (line-end-position) + (list 'face 'ledger-font-report-clickable-face)) + (end-of-line))))) (goto-char data-pos))) @@ -340,20 +338,19 @@ Optional EDIT the command." (let* ((prop (get-text-property (point) 'ledger-source)) (file (if prop (car prop))) (line-or-marker (if prop (cdr prop)))) - (if (and file line-or-marker) - (progn - (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))))))) + (when (and file line-or-marker) + (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." diff --git a/lisp/ldg-schedule.el b/lisp/ldg-schedule.el index c2e5ea01..effa20b5 100644 --- a/lisp/ldg-schedule.el +++ b/lisp/ldg-schedule.el @@ -223,7 +223,7 @@ returns true if the date meets the requirements" ;; read the descriptor string into a lisp object the transform the ;; string descriptor into useable things (ledger-transform-auto-tree - (read (buffer-substring (point-min) (point-max)))))) + (read (buffer-substring-no-properties (point-min) (point-max)))))) (defun ledger-transform-auto-tree (tree) "Takes a lisp list of date descriptor strings, TREE, and returns a string with a lambda function of date." diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el index 3ce429fc..ecb86371 100644 --- a/lisp/ldg-sort.el +++ b/lisp/ldg-sort.el @@ -47,26 +47,22 @@ (match-end 0))) (defun ledger-sort-insert-start-mark () - (interactive) - (let (has-old-marker) - (save-excursion - (goto-char (point-min)) - (setq has-old-marker (ledger-sort-find-start)) - (if has-old-marker - (delete-region (match-beginning 0) (match-end 0)))) - (beginning-of-line) - (insert "\n; Ledger-mode: Start sort\n\n"))) + (interactive) + (save-excursion + (goto-char (point-min)) + (if (ledger-sort-find-start) + (delete-region (match-beginning 0) (match-end 0)))) + (beginning-of-line) + (insert "\n; Ledger-mode: Start sort\n\n")) (defun ledger-sort-insert-end-mark () - (interactive) - (let (has-old-marker) - (save-excursion - (goto-char (point-min)) - (setq has-old-marker (ledger-sort-find-end)) - (if has-old-marker - (delete-region (match-beginning 0) (match-end 0)))) - (beginning-of-line) - (insert "\n; Ledger-mode: End sort\n\n"))) + (interactive) + (save-excursion + (goto-char (point-min)) + (if (ledger-sort-find-end) + (delete-region (match-beginning 0) (match-end 0)))) + (beginning-of-line) + (insert "\n; Ledger-mode: End sort\n\n")) (defun ledger-sort-region (beg end) "Sort the region from BEG to END in chronological order." diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index dd5e42ad..c1027f5c 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -245,10 +245,9 @@ dropped." (eq (ledger-state-from-char (char-after)) 'cleared)) (progn (delete-char 1) - (if (and style (eq style 'cleared)) - (progn - (insert " *") - (setq status 'cleared)))) + (when (and style (eq style 'cleared)) + (insert " *") + (setq status 'cleared))) (if (and style (eq style 'pending)) (progn (insert " ! ") diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index 3e4cec4b..e2180b57 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -44,12 +44,10 @@ within the transaction." (backward-paragraph) (if (/= (point) (point-min)) (forward-line)) - (beginning-of-line) - (setq beg-pos (point)) + (setq beg-pos (line-beginning-position)) (forward-paragraph) (forward-line -1) - (end-of-line) - (setq end-pos (1+ (point))) + (setq end-pos (1+ (line-end-position))) (list beg-pos end-pos)))) @@ -80,11 +78,12 @@ within the transaction." (defsubst ledger-goto-line (line-number) "Rapidly move point to line LINE-NUMBER." -(goto-char (point-min)) (forward-line (1- line-number))) + (goto-char (point-min)) + (forward-line (1- line-number))) (defun ledger-thing-at-point () "Describe thing at points. Return 'transaction, 'posting, or nil." -(let ((here (point))) + (let ((here (point))) (goto-char (line-beginning-position)) (cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+") (goto-char (match-end 0)) @@ -105,7 +104,7 @@ within the transaction." (concat ledger-year "/" ledger-month "/") 'ledger-minibuffer-history))) (let* ((here (point)) (extents (ledger-find-xact-extents (point))) - (transaction (buffer-substring (car extents) (cadr extents))) + (transaction (buffer-substring-no-properties (car extents) (cadr extents))) encoded-date) (if (string-match ledger-date-regex date) (setq encoded-date -- cgit v1.2.3 From e5525130c023862a58277c248047c3e1cc80d613 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 25 Mar 2013 13:35:59 -0400 Subject: Improve complete-all and reconcile saving --- lisp/ldg-commodities.el | 3 ++- lisp/ldg-complete.el | 2 +- lisp/ldg-reconcile.el | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index 0eb435b5..3485d93f 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -32,7 +32,8 @@ :group 'ledger-reconcile) (defun ledger-split-commodity-string (str) - "Split a commoditized amount into two parts" + "Split a commoditized string, STR, into two parts. +Returns a list with (value commodity)." (if (> (length str) 0) (let ((number-regex (if (assoc "decimal-comma" ledger-environment-alist) "-?[1-9][0-9.]*[,]?[0-9]*" diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index a8e73b88..7e37163b 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -155,7 +155,7 @@ Does not use ledger xact" (setq rest-of-name (match-string 3)) ;; Start copying the postings (forward-line) - (while (looking-at "^\\s-+") + (while (looking-at ledger-post-account-regex) (setq xacts (cons (buffer-substring-no-properties (line-beginning-position) (line-end-position)) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 3d3b7c92..a05a61c0 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -217,7 +217,8 @@ Return the number of uncleared xacts found." (set-buffer-modified-p nil) (ledger-display-balance) (goto-char curpoint) - (ledger-reconcile-visit t)))) + ;; (ledger-reconcile-visit t) + ))) (defun ledger-reconcile-finish () "Mark all pending posting or transactions as cleared. -- cgit v1.2.3 From 862a83e7927ed0d18e5d297801d28f82595bb2a5 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 25 Mar 2013 14:05:29 -0400 Subject: add --collapse to reconcile balance calculation --- lisp/ldg-reconcile.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index a05a61c0..5a6a117a 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -76,7 +76,7 @@ reconcile-finish will mark all pending posting cleared." ;; split arguments like the shell does, so you need to ;; specify the individual fields in the command line. (if (ledger-exec-ledger buffer (current-buffer) - "balance" "--limit" "cleared or pending" "--empty" + "balance" "--limit" "cleared or pending" "--empty" "--collapse" "--format" "%(display_total)" account) (ledger-split-commodity-string (buffer-substring-no-properties (point-min) (point-max))))))) -- cgit v1.2.3 From 62996f9366fc582f0e2cebe8d88aea9095629239 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 1 Apr 2013 10:15:48 -0700 Subject: Make 'return' visit source in reports, make Visit Source the entry in reconcile mode. --- lisp/ldg-reconcile.el | 2 +- lisp/ldg-report.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 5a6a117a..bec6d175 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -434,7 +434,7 @@ moved and recentered. If they aren't strange things happen." (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 vis] '("Visit Source" . 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)) diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 04c182dd..3225d803 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -103,7 +103,7 @@ text that should replace the format specifier." '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 [return] 'ledger-report-visit-source) (define-key map [menu-bar] (make-sparse-keymap "ldg-rep")) -- cgit v1.2.3 From 519e57ca1fac01ea057bea8263c6cb06a8ac4e7e Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 2 Apr 2013 23:13:23 -0700 Subject: Consolidated all major regexes into ldg-regex. Only major exception are the regex in ledger context at point. --- lisp/ldg-commodities.el | 8 +++++--- lisp/ldg-complete.el | 5 ++--- lisp/ldg-fonts.el | 44 +++++++++++++++++++++++++++----------------- lisp/ldg-init.el | 4 +++- lisp/ldg-mode.el | 2 +- lisp/ldg-new.el | 2 +- lisp/ldg-post.el | 11 +---------- lisp/ldg-reconcile.el | 14 ++++++++++++-- lisp/ldg-regex.el | 35 ++++++++++++++++++++++++++++++++++- lisp/ldg-sort.el | 5 ++--- lisp/ldg-xact.el | 4 ++-- 11 files changed, 90 insertions(+), 44 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index 8755166d..031bddeb 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -26,6 +26,8 @@ ;;; Code: +(require 'ldg-regex) + (defcustom ledger-reconcile-default-commodity "$" "The default commodity for use in target calculations in ledger reconcile." :type 'string @@ -36,13 +38,13 @@ Returns a list with (value commodity)." (if (> (length str) 0) (let ((number-regex (if (assoc "decimal-comma" ledger-environment-alist) - "-?[1-9][0-9.]*[,]?[0-9]*" - "-?[1-9][0-9,]*[.]?[0-9]*"))) + ledger-amount-decimal-comma-regex + ledger-amount-decimal-period-regex))) (with-temp-buffer (insert str) (goto-char (point-min)) (cond - ((re-search-forward "\"\\(.*\\)\"" nil t) + ((re-search-forward "\"\\(.*\\)\"" nil t) ; look for quoted commodities (let ((com (delete-and-extract-region (match-beginning 1) (match-end 1)))) diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index fe27e91d..3462c0bb 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -52,8 +52,7 @@ (save-excursion (goto-char (point-min)) (while (re-search-forward - (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" - "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) ;; matches first line + ledger-xact-payee-regex nil t) ;; matches first line (unless (and (>= origin (match-beginning 0)) (< origin (match-end 0))) (setq payees-list (cons (match-string-no-properties 3) @@ -70,7 +69,7 @@ Return tree structure" (save-excursion (goto-char (point-min)) (while (re-search-forward - "^[ \t]+\\([*!]\\s-+\\)?[[(]?\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)" nil t) + ledger-complete-account-regex nil t) (unless (and (>= origin (match-beginning 0)) (< origin (match-end 0))) (setq account-elements diff --git a/lisp/ldg-fonts.el b/lisp/ldg-fonts.el index 81196c10..81b5b0bf 100644 --- a/lisp/ldg-fonts.el +++ b/lisp/ldg-fonts.el @@ -29,17 +29,17 @@ (require 'ldg-regex) (defgroup ledger-faces nil "Ledger mode highlighting" :group 'ledger) -(defface ledger-font-uncleared-face +(defface ledger-font-payee-uncleared-face `((t :foreground "#dc322f" :weight bold )) "Default face for Ledger" :group 'ledger-faces) -(defface ledger-font-cleared-face +(defface ledger-font-payee-cleared-face `((t :foreground "#657b83" :weight normal )) "Default face for cleared (*) transactions" :group 'ledger-faces) -(defface ledger-font-highlight-face +(defface ledger-font-xact-highlight-face `((t :background "#eee8d5")) "Default face for transaction under point" :group 'ledger-faces) @@ -50,7 +50,7 @@ :group 'ledger-faces) (defface ledger-font-other-face - `((t :foreground "yellow" )) + `((t :foreground "#657b83" :weight bold)) "Default face for other transactions" :group 'ledger-faces) @@ -70,7 +70,7 @@ :group 'ledger-faces) (defface ledger-font-posting-amount-face - `((t :foreground "yellow" )) + `((t :foreground "#cb4b16" )) "Face for Ledger amounts" :group 'ledger-faces) @@ -111,20 +111,30 @@ (defvar ledger-font-lock-keywords - `((,ledger-payee-pending-regex 2 'ledger-font-pending-face) - (,ledger-payee-cleared-regex 2 'ledger-font-cleared-face) - (,ledger-payee-uncleared-regex 2 'ledger-font-uncleared-face) - (,ledger-posting-account-cleared-regex - 2 'ledger-font-posting-account-cleared-face) - (,ledger-posting-account-pending-regex - 2 'ledger-font-posting-account-pending-face) ; works - (,ledger-posting-account-all-regex - 2 'ledger-font-posting-account-face) ; works - (,ledger-comment-regex 2 'ledger-font-comment-face) ; works - (,ledger-other-entries-regex 1 ledger-font-other-face)) + `( ;; (,ledger-other-entries-regex 1 + ;; ledger-font-other-face) + (,ledger-comment-regex 2 + 'ledger-font-comment-face) + (,ledger-payee-pending-regex 2 + 'ledger-font-payee-pending-face) ; Works + (,ledger-payee-cleared-regex 2 + 'ledger-font-payee-cleared-face) ; Works + (,ledger-payee-uncleared-regex 2 + 'ledger-font-payee-uncleared-face) ; Works + (,ledger-posting-account-cleared-regex 2 + 'ledger-font-posting-account-cleared-face) ; Works + (,ledger-posting-account-pending-regex 2 + 'ledger-font-posting-account-pending-face) ; Works + (,ledger-posting-account-all-regex 2 + 'ledger-font-posting-account-face)) ; Works "Expressions to highlight in Ledger mode.") + - +;; (defvar ledger-font-lock-keywords +;; `( (,ledger-other-entries-regex 1 +;; ledger-font-other-face)) +;; "Expressions to highlight in Ledger mode.") + (provide 'ldg-fonts) ;;; ldg-fonts.el ends here diff --git a/lisp/ldg-init.el b/lisp/ldg-init.el index 8e657323..29839c9e 100644 --- a/lisp/ldg-init.el +++ b/lisp/ldg-init.el @@ -22,6 +22,8 @@ ;;; Commentary: ;; Determine the ledger environment +(require 'ldg-regex) + (defcustom ledger-init-file-name "~/.ledgerrc" "Location of the ledger initialization file. nil if you don't have one" :group 'ledger-exec) @@ -32,7 +34,7 @@ (with-current-buffer file (setq ledger-environment-alist nil) (goto-char (point-min)) - (while (re-search-forward "^--.+?\\($\\|[ ]\\)" nil t ) + (while (re-search-forward ledger-init-string-regex nil t ) (let ((matchb (match-beginning 0)) ;; save the match data, string-match stamp on it (matche (match-end 0))) (end-of-line) diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index c9814918..df9dda87 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -238,7 +238,7 @@ correct chronological place in the buffer." exit-code) (unless insert-at-point (let ((date (car args))) - (if (string-match "\\([0-9]+\\)[-/]\\([0-9]+\\)[-/]\\([0-9]+\\)" date) + (if (string-match ledger-iso-date-regex date) (setq date (encode-time 0 0 0 (string-to-number (match-string 3 date)) (string-to-number (match-string 2 date)) diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index 8ff95cd3..05e18818 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -32,6 +32,7 @@ ;;; Commentary: ;; Load up the ledger mode +(require 'ldg-regex) (require 'esh-util) (require 'esh-arg) (require 'ldg-commodities) @@ -43,7 +44,6 @@ (require 'ldg-occur) (require 'ldg-post) (require 'ldg-reconcile) -(require 'ldg-regex) (require 'ldg-report) (require 'ldg-sort) (require 'ldg-state) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index f29d8af8..767a263a 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -115,14 +115,7 @@ PROMPT is a string to prompt with. CHOICES is a list of (delete-char 1))))))) (goto-char pos))) -(defvar ledger-post-amount-regex - (concat "\\( \\|\t\\| \t\\)[ \t]*-?" - "\\([A-Z$€£_]+ *\\)?" - "\\(-?[0-9,]+?\\)" - "\\(.[0-9]+\\)?" - "\\( *[[:word:]€£_\"]+\\)?" - "\\([ \t]*[@={]@?[^\n;]+?\\)?" - "\\([ \t]+;.+?\\|[ \t]*\\)?$")) + (defsubst ledger-next-amount (&optional end) "Move point to the next amount, as long as it is not past END. @@ -135,8 +128,6 @@ point at beginning of the commodity." (- (or (match-end 4) (match-end 3)) (point)))) -(defvar ledger-post-account-regex - "\\(^[ \t]+\\)\\([!*]?.+?\\)\\( \\|$\\)") (defun ledger-next-account (&optional end) "Move point to the beginning of the next account, or status marker (!*), as long as it is not past END. diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index bec6d175..ccf733b7 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -62,6 +62,16 @@ reconcile-finish will mark all pending posting cleared." :type 'boolean :group 'ledger-reconcile) +(defcustom ledger-reconcile-default-date-format "%Y/%m/%d" + "Default date format for the reconcile buffer" + :type 'string + :group 'ledger-reconcile) + +(defcustom ledger-reconcile-target-prompt-string "Target amount for reconciliation " + "Default prompt for recon target prompt" + :type 'string + :group 'ledger-reconcile) + (defun ledger-reconcile-get-cleared-or-pending-balance () "Calculate the cleared or pending balance of the account." @@ -299,7 +309,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (insert (format "%s %-4s %-30s %-30s %15s\n" (format-time-string (if date-format date-format - "%Y/%m/%d") (nth 2 xact)) + ledger-reconcile-default-date-format) (nth 2 xact)) (if (nth 3 xact) (nth 3 xact) "") @@ -409,7 +419,7 @@ moved and recentered. If they aren't strange things happen." (defun ledger-reconcile-change-target () "Change the target amount for the reconciliation process." (interactive) - (setq ledger-target (ledger-read-commodity-string "Set reconciliation target"))) + (setq ledger-target (ledger-read-commodity-string ledger-reconcile-target-prompt-string))) (define-derived-mode ledger-reconcile-mode text-mode "Reconcile" "A mode for reconciling ledger entries." diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el index 7c92bf15..24a3ae23 100644 --- a/lisp/ldg-regex.el +++ b/lisp/ldg-regex.el @@ -24,11 +24,23 @@ (eval-when-compile (require 'cl)) +(defvar ledger-amount-decimal-comma-regex + "-?[1-9][0-9.]*[,]?[0-9]*") + +(defvar ledger-amount-decimal-period-regex + "-?[1-9][0-9.]*[.]?[0-9]*") + (defvar ledger-other-entries-regex - "^\\(\\([~=].+\\)\\|\\(^\\([A-Za-z]+ .+\\)\\)\\)") + "\\(^[~=A-Za-z].+\\)+") +;\\|^\\([A-Za-z] .+\\)\\) + +(defvar ledger-xact-payee-regex + (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" + "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)")) (defvar ledger-comment-regex "\\( \\| \\|^\\)\\(;.*\\)") + (defvar ledger-payee-pending-regex "^[0-9]+[-/.=][-/.=0-9]+\\s-\\!\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)") @@ -38,19 +50,40 @@ (defvar ledger-payee-uncleared-regex "^[0-9]+[-/.=][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)") +(defvar ledger-iso-date-regex + "\\([12][0-9]\\{3\\}\\)[-/]\\([0-9]\\{2\\}\\)[-/]\\([0-9]\\{2\\}\\)") + +(defvar ledger-init-string-regex + "^--.+?\\($\\|[ ]\\)") (defvar ledger-posting-account-all-regex "\\(^[ \t]+\\)\\(.+?\\)\\( \\|$\\)") +(defvar ledger-sort-next-record-regex + (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" + "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)")) + (defvar ledger-posting-account-cleared-regex "\\(^[ \t]+\\)\\(\\*.+?\\)\\( \\|$\\)") +(defvar ledger-complete-account-regex + "^[ \t]+\\([*!]\\s-+\\)?[[(]?\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") + (defvar ledger-posting-account-pending-regex "\\(^[ \t]+\\)\\(!.+?\\)\\( \\|$\\)") (defvar ledger-date-regex "\\([0-9]+\\)[/-]\\([0-9]+\\)[/-]\\([0-9]+\\)") +(defvar ledger-post-amount-regex + (concat "\\( \\|\t\\| \t\\)[ \t]*-?" + "\\([A-Z$€£_]+ *\\)?" + "\\(-?[0-9,]+?\\)" + "\\(.[0-9]+\\)?" + "\\( *[[:word:]€£_\"]+\\)?" + "\\([ \t]*[@={]@?[^\n;]+?\\)?" + "\\([ \t]+;.+?\\|[ \t]*\\)?$")) + (defmacro ledger-define-regexp (name regex docs &rest args) "Simplify the creation of a Ledger regex and helper functions." (let ((defs diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el index 5119db5d..b106173b 100644 --- a/lisp/ldg-sort.el +++ b/lisp/ldg-sort.el @@ -28,9 +28,8 @@ (defun ledger-next-record-function () "Move point to next transaction." - (if (re-search-forward - (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" - "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) + (if (re-search-forward ledger-sort-next-record-regex + nil t) (goto-char (match-beginning 0)) (goto-char (point-max)))) diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index d6ccc2bf..66d3f46f 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -53,7 +53,7 @@ within the transaction." (defun ledger-highlight-xact-under-point () "Move the highlight overlay to the current transaction." -(if ledger-highlight-xact-under-point + (if ledger-highlight-xact-under-point (let ((exts (ledger-find-xact-extents (point))) (ovl highlight-overlay)) (if (not highlight-overlay) @@ -63,7 +63,7 @@ within the transaction." (cadr exts) (current-buffer) t nil))) (move-overlay ovl (car exts) (cadr exts))) - (overlay-put ovl 'face 'ledger-font-highlight-face) + (overlay-put ovl 'face 'ledger-font-xact-highlight-face) (overlay-put ovl 'priority 100)))) (defun ledger-xact-payee () -- cgit v1.2.3 From 2e78e61be7ba6aa73c56c157405e45ed30990b31 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 4 Apr 2013 12:35:20 -0700 Subject: Regex Cleanup --- lisp/ldg-reconcile.el | 3 +-- lisp/ldg-regex.el | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ccf733b7..ff808485 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -227,8 +227,7 @@ Return the number of uncleared xacts found." (set-buffer-modified-p nil) (ledger-display-balance) (goto-char curpoint) - ;; (ledger-reconcile-visit t) - ))) + (ledger-reconcile-visit t)))) (defun ledger-reconcile-finish () "Mark all pending posting or transactions as cleared. diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el index 95da77e2..1b338012 100644 --- a/lisp/ldg-regex.el +++ b/lisp/ldg-regex.el @@ -54,7 +54,7 @@ "^--.+?\\($\\|[ ]\\)") (defconst ledger-account-any-status-regex - "^[ \t]+\\([*!]\\s-+\\)?[[(]?\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") + "^[ \t]+\\([*!]\\s-+\\)?\\([[(]?.+?\\)\\(\t\\|\n\\| [ \t]\\)") (defconst ledger-account-pending-regex "\\(^[ \t]+\\)\\(!.+?\\)\\( \\|$\\)") -- cgit v1.2.3 From 4df990014fede0c7b0c23396f32b1f2c7c636426 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sat, 6 Apr 2013 23:13:49 -0700 Subject: Fixed reconciliation initialization. Now prompts with only account, not status and amount Moved context function to leg-context, from leg-report. Cleaned up many regex in ldg-context. --- lisp/ldg-complete.el | 30 +++++---- lisp/ldg-context.el | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/ldg-mode.el | 30 ++++++--- lisp/ldg-new.el | 1 + lisp/ldg-occur.el | 5 ++ lisp/ldg-post.el | 9 --- lisp/ldg-reconcile.el | 2 +- lisp/ldg-report.el | 156 +----------------------------------------- lisp/ldg-state.el | 8 +-- lisp/ldg-xact.el | 19 +----- 10 files changed, 237 insertions(+), 206 deletions(-) create mode 100644 lisp/ldg-context.el (limited to 'lisp/ldg-reconcile.el') diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el index f01e6e90..bd907bc8 100644 --- a/lisp/ldg-complete.el +++ b/lisp/ldg-complete.el @@ -30,9 +30,12 @@ (defun ledger-parse-arguments () "Parse whitespace separated arguments in the current region." - (let* ((info (save-excursion - (cons (ledger-thing-at-point) (point)))) - (begin (cdr info)) + ;; this is more complex than it appears to need, so that it can work + ;; with pcomplete. See pcomplete-parse-arguments-function for + ;; details + (let* ((begin (save-excursion + (ledger-thing-at-point) ;; leave point at beginning of thing under point + (point))) (end (point)) begins args) (save-excursion @@ -45,6 +48,7 @@ args))) (cons (reverse args) (reverse begins))))) + (defun ledger-payees-in-buffer () "Scan buffer and return list of all payees." (let ((origin (point)) @@ -77,12 +81,12 @@ Return tree structure" (match-string-no-properties 2) ":")) (let ((root account-tree)) (while account-elements - (let ((entry (assoc (car account-elements) root))) - (if entry - (setq root (cdr entry)) - (setq entry (cons (car account-elements) (list t))) - (nconc root (list entry)) - (setq root (cdr entry)))) + (let ((xact (assoc (car account-elements) root))) + (if xact + (setq root (cdr xact)) + (setq xact (cons (car account-elements) (list t))) + (nconc root (list xact)) + (setq root (cdr xact)))) (setq account-elements (cdr account-elements))))))) account-tree)) @@ -93,11 +97,11 @@ Return tree structure" (root (ledger-find-accounts-in-buffer)) (prefix nil)) (while (cdr elements) - (let ((entry (assoc (car elements) root))) - (if entry + (let ((xact (assoc (car elements) root))) + (if xact (setq prefix (concat prefix (and prefix ":") (car elements)) - root (cdr entry)) + root (cdr xact)) (setq root nil elements nil))) (setq elements (cdr elements))) (and root @@ -136,7 +140,7 @@ Return tree structure" (throw 'pcompleted t))) (ledger-accounts))))) -(defun ledger-fully-complete-entry () +(defun ledger-fully-complete-xact () "Completes a transaction if there is another matching payee in the buffer. Does not use ledger xact" (interactive) diff --git a/lisp/ldg-context.el b/lisp/ldg-context.el new file mode 100644 index 00000000..8861a30e --- /dev/null +++ b/lisp/ldg-context.el @@ -0,0 +1,183 @@ +;;; ldg-context.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 facilities for reflection in ledger buffers + +;;; Code: + +(eval-when-compile + (require 'cl)) + + +(defconst ledger-line-config + '((xact + (("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*?\\)[ \t]*;\\(.*\\)[ \t]*$" + (date nil status nil nil code payee comment)) + ("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*\\)[ \t]*$" + (date nil status nil nil code payee)))) + (acct-transaction + (("^\\([ \t]+;\\|;\\)\\s-?\\(.*\\)" + (indent comment)) + ("\\(^[ \t]+\\)\\([*! ]?\\)\\(.*?\\)\\s-\\s-[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*\\)[ \t]*$" + (indent status account commodity amount nil comment)) ;checked 2013-04-06 + ("\\(^[ \t]+\\)\\([*! ]?\\)\\(.*?\\)\\s-\\s-[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)$" + (indent status account commodity amount)) ;checked 2013-04-06 + ("\\(^[ \t]+\\)\\([*! ]?\\)\\(.*?\\)\\s-\\s-[ \t]+\\(-?[0-9]+\\.[0-9]*\\)[ \t]+\\(.*?\\)[ \t]*\\(;[ \t]*\\(.*?\\)[ \t]*$\\|@+\\)" + (indent status account amount nil commodity comment)) ;checked 2013-04-06 + ("\\(^[ \t]+\\)\\([*! ]?\\)\\(.*?\\)\\s-\\s-[ \t]+\\(-?[0-9]+\\.[0-9]*\\)[ \t]+\\(.*\\)" + (indent status account amount nil commodity)) ;checked 2013-04-06 + ("\\(^[ \t]+\\)\\([*! ]?\\)\\(.*?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" + (indent status account comment)) + ("\\(^[ \t]+\\)\\([*! ]?\\)\\(.*?\\)[ \t]*$" + (indent status account)))))) + +(defun ledger-extract-context-info (line-type pos) + "Get context info for current line with LINE-TYPE. + +Assumes point is at beginning of line, and the POS argument specifies +where the \"users\" point was." + (let ((linfo (assoc line-type ledger-line-config)) + found field fields) + (dolist (re-info (nth 1 linfo)) + (let ((re (nth 0 re-info)) + (names (nth 1 re-info))) + (unless found + (when (looking-at re) + (setq found t) + (dotimes (i (length names)) + (when (nth i names) + (setq fields (append fields + (list + (list (nth i names) + (match-string-no-properties (1+ i)) + (match-beginning (1+ i)))))))) + (dolist (f fields) + (and (nth 1 f) + (>= pos (nth 2 f)) + (setq field (nth 0 f)))))))) + (list line-type field fields))) + +(defun ledger-thing-at-point () + "Describe thing at points. Return 'transaction, 'posting, or nil. +Leave point at the beginning of the thing under point" + (let ((here (point))) + (goto-char (line-beginning-position)) + (cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+") + (goto-char (match-end 0)) + 'transaction) + ((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\(.\\)") + (goto-char (match-beginning 2)) + 'posting) + ((looking-at "^\\(sun\\|mon\\|tue\\|wed\\|thu\\|fri\\|sat\\)\\s-+") + (goto-char (match-end 0)) + 'day) + (t + (ignore (goto-char here)))))) + +(defun ledger-context-at-point () + "Return a list describing the context around point. + +The contents of the list are the line type, the name of the field +containing point, and for selected line types, the content of +the fields in the line in a association list." + (let ((pos (point))) + (save-excursion + (beginning-of-line) + (let ((first-char (char-after))) + (cond ((equal (point) (line-end-position)) + '(empty-line nil nil)) + ((memq first-char '(?\ ?\t)) + (ledger-extract-context-info 'acct-transaction pos)) + ((memq first-char '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) + (ledger-extract-context-info 'xact pos)) + ((equal first-char ?\=) + '(automated-xact nil nil)) + ((equal first-char ?\~) + '(period-xact nil nil)) + ((equal first-char ?\!) + '(command-directive)) + ((equal first-char ?\;) + '(comment nil nil)) + ((equal first-char ?Y) + '(default-year nil nil)) + ((equal first-char ?P) + '(commodity-price nil nil)) + ((equal first-char ?N) + '(price-ignored-commodity nil nil)) + ((equal first-char ?D) + '(default-commodity nil nil)) + ((equal first-char ?C) + '(commodity-conversion nil nil)) + ((equal first-char ?i) + '(timeclock-i nil nil)) + ((equal first-char ?o) + '(timeclock-o nil nil)) + ((equal first-char ?b) + '(timeclock-b nil nil)) + ((equal first-char ?h) + '(timeclock-h nil nil)) + (t + '(unknown nil nil))))))) + +(defun ledger-context-other-line (offset) + "Return a list describing context of line OFFSET from existing position. + +Offset can be positive or negative. If run out of buffer before reaching +specified line, returns nil." + (save-excursion + (let ((left (forward-line offset))) + (if (not (equal left 0)) + nil + (ledger-context-at-point))))) + +(defun ledger-context-line-type (context-info) + (nth 0 context-info)) + +(defun ledger-context-current-field (context-info) + (nth 1 context-info)) + +(defun ledger-context-field-info (context-info field-name) + (assoc field-name (nth 2 context-info))) + +(defun ledger-context-field-present-p (context-info field-name) + (not (null (ledger-context-field-info context-info field-name)))) + +(defun ledger-context-field-value (context-info field-name) + (nth 1 (ledger-context-field-info context-info field-name))) + +(defun ledger-context-field-position (context-info field-name) + (nth 2 (ledger-context-field-info context-info field-name))) + +(defun ledger-context-field-end-position (context-info field-name) + (+ (ledger-context-field-position context-info field-name) + (length (ledger-context-field-value context-info field-name)))) + +(defun ledger-context-goto-field-start (context-info field-name) + (goto-char (ledger-context-field-position context-info field-name))) + +(defun ledger-context-goto-field-end (context-info field-name) + (goto-char (ledger-context-field-end-position context-info field-name))) + +(provide 'ldg-context) + +;;; ldg-report.el ends here diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index f0af4383..6dea1735 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -39,10 +39,22 @@ (defvar ledger-month (ledger-current-month) "Start a ledger session with the current month, but make it customizable to ease retro-entry.") -(defun ledger-remove-overlays () - "Remove all overlays from the ledger buffer." - (interactive) - (remove-overlays)) +(defun ledger-read-account-with-prompt (prompt) + (let* ((context (ledger-context-at-point)) + (default + (if (and (eq (ledger-context-line-type context) 'acct-transaction) + (eq (ledger-context-current-field context) 'account)) + (regexp-quote (ledger-context-field-value context 'account)) + nil))) + (ledger-read-string-with-default prompt default))) + +(defun ledger-read-string-with-default (prompt default) + "Return user supplied string after PROMPT, or DEFAULT." + (let ((default-prompt (concat prompt + (if default + (concat " (" default "): ") + ": ")))) + (read-string default-prompt nil 'ledger-minibuffer-history default))) (defun ledger-magic-tab (&optional interactively) "Decide what to with with . @@ -59,7 +71,7 @@ Can be pcomplete, or align-posting" (interactive) (let ((context (car (ledger-context-at-point))) (date-string (format-time-string (cdr (assoc "date-format" ledger-environment-alist))))) - (cond ((eq 'entry context) + (cond ((eq 'xact context) (beginning-of-line) (insert date-string "=")) ((eq 'acct-transaction context) @@ -87,7 +99,7 @@ Can be pcomplete, or align-posting" (set (make-local-variable 'pcomplete-termination-string) "") (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) - (add-hook 'before-revert-hook 'ledger-remove-overlays nil t) + (add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t) (make-variable-buffer-local 'highlight-overlay) (ledger-init-load-init-file) @@ -110,8 +122,8 @@ Can be pcomplete, or align-posting" (define-key map [(control ?c) (control ?y)] 'ledger-set-year) (define-key map [tab] 'ledger-magic-tab) (define-key map [(control ?i)] 'ledger-magic-tab) - (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) tab] 'ledger-fully-complete-xact) + (define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-xact) (define-key map [(control ?c) (control ?o) (control ?a)] 'ledger-report-redo) (define-key map [(control ?c) (control ?o) (control ?e)] 'ledger-report-edit) @@ -155,7 +167,7 @@ Can be pcomplete, or align-posting" (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 Transaction" ledger-delete-current-transaction)) - (define-key map [cmp-xact] '(menu-item "Complete Transaction" ledger-fully-complete-entry)) + (define-key map [cmp-xact] '(menu-item "Complete Transaction" ledger-fully-complete-xact)) (define-key map [add-xact] '(menu-item "Add Transaction (ledger xact)" ledger-add-transaction :enable ledger-works)) (define-key map [sep3] '(menu-item "--")) (define-key map [reconcile] '(menu-item "Reconcile Account" ledger-reconcile :enable ledger-works)) diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el index b018d217..7c13c80e 100644 --- a/lisp/ldg-new.el +++ b/lisp/ldg-new.el @@ -37,6 +37,7 @@ (require 'esh-arg) (require 'ldg-commodities) (require 'ldg-complete) +(require 'ldg-context) (require 'ldg-exec) (require 'ldg-fonts) (require 'ldg-init) diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index a2e53cb0..1e1308d0 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -59,6 +59,11 @@ "A list of currently active overlays to the ledger buffer.") (make-variable-buffer-local 'ledger-occur-overlay-list) +(defun ledger-remove-all-overlays () + "Remove all overlays from the ledger buffer." + (interactive) + (remove-overlays)) + (defun ledger-occur-mode (regex buffer) "Highlight transactions that match REGEX in BUFFER, hiding others. diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 338264f5..4f80b425 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -251,15 +251,6 @@ BEG, END, and LEN control how far it can align." (add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil)) t t)) -(defun ledger-post-read-account-with-prompt (prompt) - (let* ((context (ledger-context-at-point)) - (default - (if (and (eq (ledger-context-line-type context) 'acct-transaction) - (eq (ledger-context-current-field context) 'account)) - (regexp-quote (ledger-context-field-value context 'account)) - nil))) - (ledger-read-string-with-default prompt default))) - (provide 'ldg-post) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ff808485..e5a5a8e7 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -377,7 +377,7 @@ moved and recentered. If they aren't strange things happen." (defun ledger-reconcile () "Start reconciling, prompt for account." (interactive) - (let ((account (ledger-post-read-account-with-prompt "Account to reconcile")) + (let ((account (ledger-read-account-with-prompt "Account to reconcile")) (buf (current-buffer)) (rbuf (get-buffer ledger-recon-buffer-name))) ;; this means only one *Reconcile* buffer, ever Set up the diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 3225d803..c3b83f55 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -229,19 +229,11 @@ used to generate the buffer, navigating the buffer, etc." (expand-file-name ledger-master-file) (buffer-file-name))) -(defun ledger-read-string-with-default (prompt default) - "Return user supplied string after PROMPT, or DEFAULT." - (let ((default-prompt (concat prompt - (if default - (concat " (" default "): ") - ": ")))) - (read-string default-prompt nil 'ledger-minibuffer-history default))) - (defun ledger-report-payee-format-specifier () "Substitute a payee name. The user is prompted to enter a payee and that is substitued. If - point is in an entry, the payee for that entry is used as the + point is in an xact, the payee for that xact is used as the default." ;; It is intended completion should be available on existing ;; payees, but the list of possible completions needs to be @@ -253,11 +245,11 @@ used to generate the buffer, navigating the buffer, etc." The user is prompted to enter an account name, which can be any regular expression identifying an account. If point is on an account - transaction line for an entry, the full account name on that line is + posting line for an xact, the full account name on that line is the default." ;; It is intended completion should be available on existing account ;; names, but it remains to be implemented. - (ledger-post-read-account-with-prompt "Account")) + (ledger-read-account-with-prompt "Account")) (defun ledger-report-expand-format-specifiers (report-cmd) "Expand %(account) and %(payee) appearing in REPORT-CMD with thing under point." @@ -422,148 +414,6 @@ Optional EDIT the command." (ledger-reports-add ledger-report-name ledger-report-cmd) (ledger-reports-custom-save))))))) -(defconst ledger-line-config - '((entry - (("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*?\\)[ \t]*;\\(.*\\)[ \t]*$" - (date nil status nil nil code payee comment)) - ("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*\\)[ \t]*$" - (date nil status nil nil code payee)))) - (acct-transaction - (("^\\([ \t]+;\\|;\\)\\s-?\\(.*\\)" - (indent comment)) - ("\\(^[ \t]+\\)\\([:A-Za-z0-9]+?\\)\\s-\\s-+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)$" - (indent account commodity amount)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" - (indent account commodity amount nil comment)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\(-?[0-9]+\\(\\.[0-9]*\\)?\\)[ \t]+\\(.*?\\)[ \t]*\\(;[ \t]*\\(.*?\\)[ \t]*$\\|@+\\)" - (indent account amount nil commodity comment)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\(-?[0-9]+\\(\\.[0-9]*\\)?\\)[ \t]+\\(.*?\\)[ \t]*$" - (indent account amount nil commodity)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\(-?\\(\\.[0-9]*\\)\\)[ \t]+\\(.*?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" - (indent account amount nil commodity comment)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\(-?\\(\\.[0-9]*\\)\\)[ \t]+\\(.*?\\)[ \t]*$" - (indent account amount nil commodity)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" - (indent account comment)) - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]*$" - (indent account)) - -;; Bad regexes - ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*$" - (indent account commodity amount nil)) - - )))) - -(defun ledger-extract-context-info (line-type pos) - "Get context info for current line with LINE-TYPE. - -Assumes point is at beginning of line, and the POS argument specifies -where the \"users\" point was." - (let ((linfo (assoc line-type ledger-line-config)) - found field fields) - (dolist (re-info (nth 1 linfo)) - (let ((re (nth 0 re-info)) - (names (nth 1 re-info))) - (unless found - (when (looking-at re) - (setq found t) - (dotimes (i (length names)) - (when (nth i names) - (setq fields (append fields - (list - (list (nth i names) - (match-string-no-properties (1+ i)) - (match-beginning (1+ i)))))))) - (dolist (f fields) - (and (nth 1 f) - (>= pos (nth 2 f)) - (setq field (nth 0 f)))))))) - (list line-type field fields))) - -(defun ledger-context-at-point () - "Return a list describing the context around point. - -The contents of the list are the line type, the name of the field -point containing point, and for selected line types, the content of -the fields in the line in a association list." - (let ((pos (point))) - (save-excursion - (beginning-of-line) - (let ((first-char (char-after))) - (cond ((equal (point) (line-end-position)) - '(empty-line nil nil)) - ((memq first-char '(?\ ?\t)) - (ledger-extract-context-info 'acct-transaction pos)) - ((memq first-char '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) - (ledger-extract-context-info 'entry pos)) - ((equal first-char ?\=) - '(automated-entry nil nil)) - ((equal first-char ?\~) - '(period-entry nil nil)) - ((equal first-char ?\!) - '(command-directive)) - ((equal first-char ?\;) - '(comment nil nil)) - ((equal first-char ?Y) - '(default-year nil nil)) - ((equal first-char ?P) - '(commodity-price nil nil)) - ((equal first-char ?N) - '(price-ignored-commodity nil nil)) - ((equal first-char ?D) - '(default-commodity nil nil)) - ((equal first-char ?C) - '(commodity-conversion nil nil)) - ((equal first-char ?i) - '(timeclock-i nil nil)) - ((equal first-char ?o) - '(timeclock-o nil nil)) - ((equal first-char ?b) - '(timeclock-b nil nil)) - ((equal first-char ?h) - '(timeclock-h nil nil)) - (t - '(unknown nil nil))))))) - -(defun ledger-context-other-line (offset) - "Return a list describing context of line OFFSET from existing position. - -Offset can be positive or negative. If run out of buffer before reaching -specified line, returns nil." - (save-excursion - (let ((left (forward-line offset))) - (if (not (equal left 0)) - nil - (ledger-context-at-point))))) - -(defun ledger-context-line-type (context-info) - (nth 0 context-info)) - -(defun ledger-context-current-field (context-info) - (nth 1 context-info)) - -(defun ledger-context-field-info (context-info field-name) - (assoc field-name (nth 2 context-info))) - -(defun ledger-context-field-present-p (context-info field-name) - (not (null (ledger-context-field-info context-info field-name)))) - -(defun ledger-context-field-value (context-info field-name) - (nth 1 (ledger-context-field-info context-info field-name))) - -(defun ledger-context-field-position (context-info field-name) - (nth 2 (ledger-context-field-info context-info field-name))) - -(defun ledger-context-field-end-position (context-info field-name) - (+ (ledger-context-field-position context-info field-name) - (length (ledger-context-field-value context-info field-name)))) - -(defun ledger-context-goto-field-start (context-info field-name) - (goto-char (ledger-context-field-position context-info field-name))) - -(defun ledger-context-goto-field-end (context-info field-name) - (goto-char (ledger-context-field-end-position context-info field-name))) - (provide 'ldg-report) ;;; ldg-report.el ends here diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index 4f1b3695..6c585f30 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -84,15 +84,15 @@ Optional argument STYLE may be `pending' or `cleared', depending on which type of status the caller wishes to indicate (default is `cleared'). Returns the new status as 'pending 'cleared or nil. This function is rather complicated because it must preserve both -the overall formatting of the ledger entry, as well as ensuring +the overall formatting of the ledger xact, as well as ensuring that the most minimal display format is used. This could be -achieved more certainly by passing the entry to ledger for +achieved more certainly by passing the xact to ledger for formatting, but doing so causes inline math expressions to be dropped." (interactive) (let ((bounds (ledger-current-transaction-bounds)) new-status cur-status) - ;; Uncompact the entry, to make it easier to toggle the + ;; Uncompact the xact, to make it easier to toggle the ;; transaction (save-excursion ;; this excursion checks state of entire ;; transaction and unclears if marked @@ -162,7 +162,7 @@ dropped." (setq new-status inserted)))) (setq inhibit-modification-hooks nil)) - ;; This excursion cleans up the entry so that it displays + ;; This excursion cleans up the xact so that it displays ;; minimally. This means that if all posts are cleared, remove ;; the marks and clear the entire transaction. (save-excursion diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index 31b9818f..b66bba04 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -67,12 +67,12 @@ within the transaction." (overlay-put ovl 'priority 100)))) (defun ledger-xact-payee () - "Return the payee of the entry containing point or nil." + "Return the payee of the transaction containing point or nil." (let ((i 0)) (while (eq (ledger-context-line-type (ledger-context-other-line i)) 'acct-transaction) (setq i (- i 1))) (let ((context-info (ledger-context-other-line i))) - (if (eq (ledger-context-line-type context-info) 'entry) + (if (eq (ledger-context-line-type context-info) 'xact) (ledger-context-field-value context-info 'payee) nil)))) @@ -116,21 +116,6 @@ MOMENT is an encoded date" (goto-char (point-min)) (forward-line (1- line-number))) -(defun ledger-thing-at-point () - "Describe thing at points. Return 'transaction, 'posting, or nil." - (let ((here (point))) - (goto-char (line-beginning-position)) - (cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+") - (goto-char (match-end 0)) - 'transaction) - ((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\(.\\)") - (goto-char (match-beginning 2)) - 'posting) - ((looking-at "^\\(sun\\|mon\\|tue\\|wed\\|thu\\|fri\\|sat\\)\\s-+") - (goto-char (match-end 0)) - 'entry) - (t - (ignore (goto-char here)))))) (defun ledger-copy-transaction-at-point (date) "Ask for a new DATE and copy the transaction under point to that date. Leave point on the first amount." -- cgit v1.2.3 From 33c046d06876915864de397ed1c3d8d671ffd1db Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 8 Apr 2013 10:35:55 -0700 Subject: Added quick balance check to ledger-mode --- doc/ledger-mode.texi | 8 ++++++++ lisp/ldg-mode.el | 17 ++++++++++++++++ lisp/ldg-reconcile.el | 56 ++++++++++++++++++++++++--------------------------- 3 files changed, 51 insertions(+), 30 deletions(-) (limited to 'lisp/ldg-reconcile.el') diff --git a/doc/ledger-mode.texi b/doc/ledger-mode.texi index 34c38dae..d7144112 100644 --- a/doc/ledger-mode.texi +++ b/doc/ledger-mode.texi @@ -233,6 +233,14 @@ automatically place any amounts such that their last digit is aligned to the column specified by @code{ledger-post-amount-alignment-column}, which defaults to 52. @xref{Ledger Post Customization Group}. +@node Quick Balance Display +@subsection Quick Balance Display +You will often want to quickly check the balance of an account. The +easiest way it to position point on the account you are interested in, +and type @code{C-C C-P}. The minibuffer will ask you to verify the name +of the account you want, if it is already correct hit return, then the +balance of the account will be displayed in the minibuffer. + @node Editing Amounts, Marking Transactions, Adding Transactions, The Ledger Buffer @section Editing Amounts GNU Calc is a very powerful Reverse Polish Notation calculator built diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 6dea1735..98236980 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -56,6 +56,21 @@ ": ")))) (read-string default-prompt nil 'ledger-minibuffer-history default))) +(defun ledger-display-balance-at-point () + "Display the cleared-or-pending balance. +And calculate the target-delta of the account being reconciled." + (interactive) + + (let* ((account (ledger-read-account-with-prompt "Account balance to show")) + (pending (ledger-reconcile-get-cleared-or-pending-balance (current-buffer) account))) + (when pending + (if ledger-target + (message "Pending balance: %s, Difference from target: %s" + (ledger-commodity-to-string pending) + (ledger-commodity-to-string (-commodity ledger-target pending))) + (message "Pending balance: %s" + (ledger-commodity-to-string pending)))))) + (defun ledger-magic-tab (&optional interactively) "Decide what to with with . Can be pcomplete, or align-posting" @@ -120,6 +135,7 @@ Can be pcomplete, or align-posting" (define-key map [(control ?c) (control ?t)] 'ledger-insert-effective-date) (define-key map [(control ?c) (control ?u)] 'ledger-schedule-upcoming) (define-key map [(control ?c) (control ?y)] 'ledger-set-year) + (define-key map [(control ?c) (control ?p)] 'ledger-display-balance-at-point) (define-key map [tab] 'ledger-magic-tab) (define-key map [(control ?i)] 'ledger-magic-tab) (define-key map [(control ?c) tab] 'ledger-fully-complete-xact) @@ -163,6 +179,7 @@ Can be pcomplete, or align-posting" (define-key map [toggle-xact] '(menu-item "Toggle Current Transaction" ledger-toggle-current-transaction)) (define-key map [sep4] '(menu-item "--")) (define-key map [recon-account] '(menu-item "Reconcile Account" ledger-reconcile)) + (define-key map [check-balance] '(menu-item "Check Balance" ledger-display-balance-at-point)) (define-key map [sep6] '(menu-item "--")) (define-key map [edit-amount] '(menu-item "Calc on Amount" ledger-post-edit-amount)) (define-key map [sep] '(menu-item "--")) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index e5a5a8e7..ca4d0004 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -73,29 +73,28 @@ reconcile-finish will mark all pending posting cleared." :group 'ledger-reconcile) -(defun ledger-reconcile-get-cleared-or-pending-balance () +(defun ledger-reconcile-get-cleared-or-pending-balance (buffer account) "Calculate the cleared or pending balance of the account." - (interactive) + ;; these vars are buffer local, need to hold them for use in the ;; temp buffer below - (let ((buffer ledger-buf) - (account ledger-acct)) - (with-temp-buffer - ;; note that in the line below, the --format option is - ;; separated from the actual format string. emacs does not - ;; split arguments like the shell does, so you need to - ;; specify the individual fields in the command line. - (if (ledger-exec-ledger buffer (current-buffer) - "balance" "--limit" "cleared or pending" "--empty" "--collapse" - "--format" "%(display_total)" account) - (ledger-split-commodity-string - (buffer-substring-no-properties (point-min) (point-max))))))) + + (with-temp-buffer + ;; note that in the line below, the --format option is + ;; separated from the actual format string. emacs does not + ;; split arguments like the shell does, so you need to + ;; specify the individual fields in the command line. + (if (ledger-exec-ledger buffer (current-buffer) + "balance" "--limit" "cleared or pending" "--empty" "--collapse" + "--format" "%(display_total)" account) + (ledger-split-commodity-string + (buffer-substring-no-properties (point-min) (point-max)))))) (defun ledger-display-balance () "Display the cleared-or-pending balance. And calculate the target-delta of the account being reconciled." (interactive) - (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance))) + (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance ledger-buf ledger-acct))) (when pending (if ledger-target (message "Pending balance: %s, Difference from target: %s" @@ -103,9 +102,6 @@ And calculate the target-delta of the account being reconciled." (ledger-commodity-to-string (-commodity ledger-target pending))) (message "Pending balance: %s" (ledger-commodity-to-string pending)))))) - - - (defun is-stdin (file) "True if ledger FILE is standard input." @@ -169,7 +165,7 @@ Return the number of uncleared xacts found." (let ((curbuf (current-buffer)) (curpoint (point)) (recon-buf (get-buffer ledger-recon-buffer-name))) - (when (buffer-live-p recon-buf) + (when (buffer-live-p recon-buf) (with-current-buffer recon-buf (ledger-reconcile-refresh) (set-buffer-modified-p nil)) @@ -223,7 +219,7 @@ Return the number of uncleared xacts found." (dolist (buf (cons ledger-buf ledger-bufs)) (with-current-buffer buf (save-buffer))) - (with-current-buffer (get-buffer ledger-recon-buffer-name) + (with-current-buffer (get-buffer ledger-recon-buffer-name) (set-buffer-modified-p nil) (ledger-display-balance) (goto-char curpoint) @@ -293,7 +289,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." (xacts (with-temp-buffer (when (ledger-exec-ledger buf (current-buffer) - "--uncleared" "--real" "emacs" account) + "--uncleared" "--real" "emacs" account) (setq ledger-success t) (goto-char (point-min)) (unless (eobp) @@ -326,7 +322,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." 'where where)))) )) (goto-char (point-max)) (delete-char -1)) ;gets rid of the extra line feed at the bottom of the list - (if ledger-success + (if ledger-success (insert (concat "There are no uncleared entries for " account)) (insert "Ledger has reported a problem. Check *Ledger Error* buffer."))) (goto-char (point-min)) @@ -341,7 +337,7 @@ POSTING is used in `ledger-clear-whole-transactions' is nil." 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)))) (when recon-window (fit-window-to-buffer recon-window) @@ -379,7 +375,7 @@ moved and recentered. If they aren't strange things happen." (interactive) (let ((account (ledger-read-account-with-prompt "Account to reconcile")) (buf (current-buffer)) - (rbuf (get-buffer ledger-recon-buffer-name))) + (rbuf (get-buffer ledger-recon-buffer-name))) ;; this means only one *Reconcile* buffer, ever Set up the ;; reconcile buffer (if rbuf ;; *Reconcile* already exists @@ -389,21 +385,21 @@ moved and recentered. If they aren't strange things happen." ;; called from some other ledger-mode buffer (ledger-reconcile-quit-cleanup) (set 'ledger-buf buf)) ;; should already be buffer-local - + (unless (get-buffer-window rbuf) (ledger-reconcile-open-windows buf rbuf))) ;; no recon-buffer, starting from scratch. (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) - - (with-current-buffer (setq rbuf + + (with-current-buffer (setq rbuf (get-buffer-create ledger-recon-buffer-name)) (ledger-reconcile-open-windows buf rbuf) (ledger-reconcile-mode) (make-local-variable 'ledger-target) (set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-acct) account))) - + ;; Narrow the ledger buffer (with-current-buffer rbuf (save-excursion @@ -437,7 +433,7 @@ moved and recentered. If they aren't strange things happen." (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)) @@ -458,7 +454,7 @@ moved and recentered. If they aren't strange things happen." (define-key map [menu-bar ldg-recon-menu fin] '("Finish" . ledger-reconcile-finish)) (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) -- cgit v1.2.3