New account switching functions.
authorSteve Youngs <steve@sxemacs.org>
Sat, 14 Oct 2017 02:09:03 +0000 (12:09 +1000)
committerSteve Youngs <steve@sxemacs.org>
Sat, 14 Oct 2017 02:09:03 +0000 (12:09 +1000)
This brings 3 new user functions for ease of switching accounts...

  `emoney-goto-default-account' -- switches directly to the default
    account.  See: `emoney-default-account'.
    Binding: `C-c d'

  `emoney-walk-accounts-next' -- switch to the 'next' account.
    Binding: `M-n'

  `emoney-walk-accounts-previous' -- switch to the 'previous' account.
    Binding: `M-p'

* emoney.el (emoney-goto-default-account): New convenience
function for quickly switching to the default account.
(emoney-walk-accounts): New. Walk through account list.
(emoney-walk-accounts-next): New. Switch to 'next' account in
list.
(emoney-walk-accounts-previous): New. Switch to 'previous' account
in list.
(emoney-mode-map): Add bindings for walk/goto-default functions.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
emoney.el

index 3788fdf..fe24973 100644 (file)
--- a/emoney.el
+++ b/emoney.el
@@ -564,6 +564,43 @@ in the current buffer."
                  (concat emoney-current-account-name ".emy")))
   (run-hooks 'emoney-switch-account-hook))
 
+(defun emoney-goto-default-account ()
+  "Switch to `emoney-default-account'."
+  (interactive)
+  (emoney-switch-to-account emoney-default-account))
+
+;:*=======================
+;:* Walk accounts
+(defun emoney-walk-accounts (direction)
+  "Move to account in direction, DIRECTION."
+  (let ((dl-acc-list (mapfam #'identity
+                            emoney-chart-of-accounts
+                            :result-type 'dllist)))
+    ;; Line up the dllist's car with the current account
+    (while (not (equal (dllist-car dl-acc-list) 
+                      (concat emoney-current-account-name ".emy")))
+      (dllist-rrotate dl-acc-list))
+    (cond
+     ((eq direction 'next)
+      (progn
+       (dllist-lrotate dl-acc-list)
+       (emoney-switch-to-account (dllist-car dl-acc-list))))
+     ((eq direction 'previous)
+      (progn
+       (dllist-rrotate dl-acc-list)
+       (emoney-switch-to-account (dllist-car dl-acc-list))))
+     (t (error 'invalid-argument)))))
+
+(defun emoney-walk-accounts-next ()
+  "Switch to the 'next' account in the chart of accounts."
+  (interactive)
+  (emoney-walk-accounts 'next))
+
+(defun emoney-walk-accounts-previous ()
+  "Switch to the 'previous' account in the chart of accounts."
+  (interactive)
+  (emoney-walk-accounts 'previous))
+
 (defconst emoney-accounts-buffer-map
   (let* ((map (make-sparse-keymap 'emoney-accounts-buffer-map)))
     (define-key map [button2] #'emoney-mouse-switch-to-account)
@@ -715,8 +752,11 @@ transactions.")
     (define-key map [(control c) b]           #'emoney-go-to-bank)
     (define-key map [(control c) c]           #'emoney-calc)
     (define-key map [(control c) s]           #'emoney-switch-to-account)
+    (define-key map [(control c) d]           #'emoney-goto-default-account)
     (define-key map [(control c) q]           #'emoney-quit)
     (define-key map [(control c) (control q)] #'emoney-recalc-and-exit)
+    (define-key map [(meta n)]                #'emoney-walk-accounts-next)
+    (define-key map [(meta p)]                #'emoney-walk-accounts-previous)
     map)
   "Keymap for emoney buffer.")