New account switching functions.
[emoney] / 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.")