summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorSteve Purcell <steve@sanityinc.com>2013-12-11 08:15:34 +0000
committerSteve Purcell <steve@sanityinc.com>2013-12-11 08:31:07 +0000
commitaaf20ab07f18356f927e09f5a040b6b0f3d733ed (patch)
tree44da5295500a6ec28cc669e443dc7bb3e3d37d79 /lisp
parent2b94b264beaa705896f96c6e23dd9ba122b791a3 (diff)
downloadfork-ledger-aaf20ab07f18356f927e09f5a040b6b0f3d733ed.tar.gz
fork-ledger-aaf20ab07f18356f927e09f5a040b6b0f3d733ed.tar.bz2
fork-ledger-aaf20ab07f18356f927e09f5a040b6b0f3d733ed.zip
ledger-mode: Use easymenu to remove boilerplate
Among other benefits, this lets us define the menu entries from top to bottom, rather than in reverse.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ledger-mode.el84
-rw-r--r--lisp/ledger-reconcile.el56
-rw-r--r--lisp/ledger-report.el35
3 files changed, 90 insertions, 85 deletions
diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el
index b9f77ba6..021835b7 100644
--- a/lisp/ledger-mode.el
+++ b/lisp/ledger-mode.el
@@ -29,6 +29,7 @@
(require 'ledger-regex)
(require 'esh-util)
(require 'esh-arg)
+(require 'easymenu)
(require 'ledger-commodities)
(require 'ledger-complete)
(require 'ledger-context)
@@ -210,51 +211,50 @@ Can indent, complete or align depending on context."
(define-key map [(meta ?p)] 'ledger-post-prev-xact)
(define-key map [(meta ?n)] 'ledger-post-next-xact)
-
- (define-key map [menu-bar] (make-sparse-keymap "ledger-menu"))
- (define-key map [menu-bar ledger-menu] (cons "Ledger" map))
-
- (define-key map [report-kill] '(menu-item "Kill Report" ledger-report-kill :enable ledger-works))
- (define-key map [report-edit] '(menu-item "Edit Report" ledger-report-edit :enable ledger-works))
- (define-key map [report-save] '(menu-item "Save Report" ledger-report-save :enable ledger-works))
- (define-key map [report-rrun] '(menu-item "Re-run Report" ledger-report-redo :enable ledger-works))
- (define-key map [report-goto] '(menu-item "Goto Report" ledger-report-goto :enable ledger-works))
- (define-key map [report-run] '(menu-item "Run Report" ledger-report :enable ledger-works))
- (define-key map [sep5] '(menu-item "--"))
- (define-key map [set-month] '(menu-item "Set Month" ledger-set-month :enable ledger-works))
- (define-key map [set-year] '(menu-item "Set Year" ledger-set-year :enable ledger-works))
- (define-key map [cust] '(menu-item "Customize Ledger Mode" (lambda ()
- (interactive)
- (customize-group 'ledger))))
- (define-key map [sep1] '("--"))
- (define-key map [effective-date] '(menu-item "Set effective date" ledger-insert-effective-date))
- (define-key map [sort-end] '(menu-item "Mark Sort End" ledger-sort-insert-end-mark))
- (define-key map [sort-start] '(menu-item "Mark Sort Beginning" ledger-sort-insert-start-mark))
- (define-key map [sort-buff] '(menu-item "Sort Buffer" ledger-sort-buffer))
- (define-key map [sort-reg] '(menu-item "Sort Region" ledger-sort-region :enable mark-active))
- (define-key map [align-xact] '(menu-item "Align Xact" ledger-post-align-xact))
- (define-key map [align-reg] '(menu-item "Align Region" ledger-post-align-postings :enable mark-active))
- (define-key map [clean-buf] '(menu-item "Clean-up Buffer" ledger-mode-clean-buffer))
- (define-key map [sep2] '(menu-item "--"))
- (define-key map [copy-xact] '(menu-item "Copy Trans at Point" ledger-copy-transaction-at-point))
- (define-key map [toggle-post] '(menu-item "Toggle Current Posting" ledger-toggle-current))
- (define-key map [toggle-xact] '(menu-item "Toggle Current Transaction" ledger-toggle-current-transaction))
- (define-key map [sep4] '(menu-item "--"))
- (define-key map [recon-account] '(menu-item "Reconcile Account" ledger-reconcile :enable ledger-works))
- (define-key map [check-balance] '(menu-item "Check Balance" ledger-display-balance-at-point :enable ledger-works))
- (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 "--"))
- (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-xact))
- (define-key map [add-xact] '(menu-item "Add Transaction (ledger xact)" ledger-add-transaction :enable ledger-works))
- (define-key map [add-xact] '(menu-item "Show upcoming transactions" ledger-schedule-upcoming :enable ledger-schedule-available))
- (define-key map [sep3] '(menu-item "--"))
- (define-key map [stats] '(menu-item "Ledger Statistics" ledger-display-ledger-stats :enable ledger-works))
- (define-key map [fold-buffer] '(menu-item "Narrow to REGEX" ledger-occur))
map)
"Keymap for `ledger-mode'.")
+(easy-menu-define ledger-mode-menu ledger-mode-map
+ "Ledger menu"
+ '("Ledger"
+ ["Narrow to REGEX" ledger-occur]
+ ["Ledger Statistics" ledger-display-ledger-stats ledger-works]
+ "---"
+ ["Show upcoming transactions" ledger-schedule-upcoming ledger-schedule-available]
+ ["Add Transaction (ledger xact)" ledger-add-transaction ledger-works]
+ ["Complete Transaction" ledger-fully-complete-xact]
+ ["Delete Transaction" ledger-delete-current-transaction]
+ "---"
+ ["Calc on Amount" ledger-post-edit-amount]
+ "---"
+ ["Check Balance" ledger-display-balance-at-point ledger-works]
+ ["Reconcile Account" ledger-reconcile ledger-works]
+ "---"
+ ["Toggle Current Transaction" ledger-toggle-current-transaction]
+ ["Toggle Current Posting" ledger-toggle-current]
+ ["Copy Trans at Point" ledger-copy-transaction-at-point]
+ "---"
+ ["Clean-up Buffer" ledger-mode-clean-buffer]
+ ["Align Region" ledger-post-align-postings mark-active]
+ ["Align Xact" ledger-post-align-xact]
+ ["Sort Region" ledger-sort-region mark-active]
+ ["Sort Buffer" ledger-sort-buffer]
+ ["Mark Sort Beginning" ledger-sort-insert-start-mark]
+ ["Mark Sort End" ledger-sort-insert-end-mark]
+ ["Set effective date" ledger-insert-effective-date]
+ "---"
+ ["Customize Ledger Mode" (lambda () (interactive) (customize-group 'ledger))]
+ ["Set Year" ledger-set-year ledger-works]
+ ["Set Month" ledger-set-month ledger-works]
+ "---"
+ ["Run Report" ledger-report ledger-works]
+ ["Goto Report" ledger-report-goto ledger-works]
+ ["Re-run Report" ledger-report-redo ledger-works]
+ ["Save Report" ledger-report-save ledger-works]
+ ["Edit Report" ledger-report-edit ledger-works]
+ ["Kill Report" ledger-report-kill ledger-works]
+ ))
+
;;;###autoload
(define-derived-mode ledger-mode text-mode "Ledger"
"A mode for editing ledger data files."
diff --git a/lisp/ledger-reconcile.el b/lisp/ledger-reconcile.el
index e15d0a67..63950366 100644
--- a/lisp/ledger-reconcile.el
+++ b/lisp/ledger-reconcile.el
@@ -27,6 +27,8 @@
;;; Code:
+(require 'easymenu)
+
(defvar ledger-buf nil)
(defvar ledger-bufs nil)
(defvar ledger-acct nil)
@@ -455,35 +457,37 @@ moved and recentered. If they aren't strange things happen."
(define-key map [(control ?c) (control ?d)] (ledger-reconcile-change-sort-key-and-refresh "(date)"))
(define-key map [(control ?c) (control ?p)] (ledger-reconcile-change-sort-key-and-refresh "(payee)"))
-
- (define-key map [menu-bar] (make-sparse-keymap "ledger-recon-menu"))
- (define-key map [menu-bar ledger-recon-menu] (cons "Reconcile" map))
- (define-key map [menu-bar ledger-recon-menu qui] '("Quit" . ledger-reconcile-quit))
- (define-key map [menu-bar ledger-recon-menu sep1] '("--"))
- (define-key map [menu-bar ledger-recon-menu pre] '("Previous Entry" . previous-line))
- (define-key map [menu-bar ledger-recon-menu vis] '("Visit Source" . ledger-reconcile-visit))
- (define-key map [menu-bar ledger-recon-menu nex] '("Next Entry" . next-line))
- (define-key map [menu-bar ledger-recon-menu sep2] '("--"))
- (define-key map [menu-bar ledger-recon-menu del] '("Delete Entry" . ledger-reconcile-delete))
- (define-key map [menu-bar ledger-recon-menu add] '("Add Entry" . ledger-reconcile-add))
- (define-key map [menu-bar ledger-recon-menu tog] '("Toggle Entry" . ledger-reconcile-toggle))
- (define-key map [menu-bar ledger-recon-menu sep3] '("--"))
- (define-key map [menu-bar ledger-recon-menu sort-orig] `("Sort by file order" . ,(ledger-reconcile-change-sort-key-and-refresh "(0)")))
- (define-key map [menu-bar ledger-recon-menu sort-amt] `("Sort by amount" . ,(ledger-reconcile-change-sort-key-and-refresh "(amount)")))
- (define-key map [menu-bar ledger-recon-menu sort-pay] `("Sort by date" . ,(ledger-reconcile-change-sort-key-and-refresh "(date)")))
- (define-key map [menu-bar ledger-recon-menu sort-dat] `("Sort by payee" . ,(ledger-reconcile-change-sort-key-and-refresh "(payee)")))
- (define-key map [menu-bar ledger-recon-menu sep4] '("--"))
- (define-key map [menu-bar ledger-recon-menu bal] '("Show Cleared Balance" . ledger-display-balance))
- (define-key map [menu-bar ledger-recon-menu tgt] '("Change Target Balance" . ledger-reconcile-change-target))
- (define-key map [menu-bar ledger-recon-menu sep5] '("--"))
- (define-key map [menu-bar ledger-recon-menu rna] '("Reconcile New Account" . ledger-reconcile))
- (define-key map [menu-bar ledger-recon-menu sep6] '("--"))
- (define-key map [menu-bar ledger-recon-menu fin] '("Finish" . ledger-reconcile-finish))
- (define-key map [menu-bar ledger-recon-menu ref] '("Refresh" . ledger-reconcile-refresh))
- (define-key map [menu-bar ledger-recon-menu sav] '("Save" . ledger-reconcile-save))
map)
"Keymap for `ledger-reconcile-mode'.")
+(easy-menu-define ledger-reconcile-mode-menu ledger-reconcile-mode-map
+ "Ledger reconcile menu"
+ `("Reconcile"
+ ["Save" ledger-reconcile-save]
+ ["Refresh" ledger-reconcile-refresh]
+ ["Finish" ledger-reconcile-finish]
+ "---"
+ ["Reconcile New Account" ledger-reconcile]
+ "---"
+ ["Change Target Balance" ledger-reconcile-change-target]
+ ["Show Cleared Balance" ledger-display-balance]
+ "---"
+ ["Sort by payee" ,(ledger-reconcile-change-sort-key-and-refresh "(payee)")]
+ ["Sort by date" ,(ledger-reconcile-change-sort-key-and-refresh "(date)")]
+ ["Sort by amount" ,(ledger-reconcile-change-sort-key-and-refresh "(amount)")]
+ ["Sort by file order" ,(ledger-reconcile-change-sort-key-and-refresh "(0)")]
+ "---"
+ ["Toggle Entry" ledger-reconcile-toggle]
+ ["Add Entry" ledger-reconcile-add]
+ ["Delete Entry" ledger-reconcile-delete]
+ "---"
+ ["Next Entry" next-line]
+ ["Visit Source" ledger-reconcile-visit]
+ ["Previous Entry" previous-line]
+ "---"
+ ["Quit" ledger-reconcile-quit]
+ ))
+
(define-derived-mode ledger-reconcile-mode text-mode "Reconcile"
"A mode for reconciling ledger entries.")
diff --git a/lisp/ledger-report.el b/lisp/ledger-report.el
index 022cb6f6..c99c0066 100644
--- a/lisp/ledger-report.el
+++ b/lisp/ledger-report.el
@@ -25,6 +25,7 @@
;;; Code:
+(require 'easymenu)
(eval-when-compile
(require 'cl))
@@ -103,26 +104,26 @@ text that should replace the format specifier."
(define-key map [(control ?c) (control ?l) (control ?e)]
'ledger-report-edit)
(define-key map [return] 'ledger-report-visit-source)
-
-
- (define-key map [menu-bar] (make-sparse-keymap "ledger-rep"))
- (define-key map [menu-bar ledger-rep] (cons "Reports" map))
-
- (define-key map [menu-bar ledger-rep lrq] '("Quit" . ledger-report-quit))
- (define-key map [menu-bar ledger-rep s2] '("--"))
- (define-key map [menu-bar ledger-rep lrd] '("Scroll Down" . scroll-down))
- (define-key map [menu-bar ledger-rep vis] '("Visit Source" . ledger-report-visit-source))
- (define-key map [menu-bar ledger-rep lru] '("Scroll Up" . scroll-up))
- (define-key map [menu-bar ledger-rep s1] '("--"))
- (define-key map [menu-bar ledger-rep rev] '("Reverse report order" . ledger-report-reverse-lines))
- (define-key map [menu-bar ledger-rep s0] '("--"))
- (define-key map [menu-bar ledger-rep lrk] '("Kill Report" . ledger-report-kill))
- (define-key map [menu-bar ledger-rep lrr] '("Re-run Report" . ledger-report-redo))
- (define-key map [menu-bar ledger-rep lre] '("Edit Report" . ledger-report-edit))
- (define-key map [menu-bar ledger-rep lrs] '("Save Report" . ledger-report-save))
map)
"Keymap for `ledger-report-mode'.")
+(easy-menu-define ledger-report-mode-menu ledger-report-mode-map
+ "Ledger report menu"
+ '("Reports"
+ ["Save Report" ledger-report-save]
+ ["Edit Report" ledger-report-edit]
+ ["Re-run Report" ledger-report-redo]
+ ["Kill Report" ledger-report-kill]
+ "---"
+ ["Reverse report order" ledger-report-reverse-lines]
+ "---"
+ ["Scroll Up" scroll-up]
+ ["Visit Source" ledger-report-visit-source]
+ ["Scroll Down" scroll-down]
+ "---"
+ ["Quit" ledger-report-quit]
+ ))
+
(define-derived-mode ledger-report-mode text-mode "Ledger-Report"
"A mode for viewing ledger reports.")