summaryrefslogtreecommitdiff
path: root/lisp/ldg-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ldg-mode.el')
-rw-r--r--lisp/ldg-mode.el70
1 files changed, 39 insertions, 31 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el
index 001ec8eb..91bfb973 100644
--- a/lisp/ldg-mode.el
+++ b/lisp/ldg-mode.el
@@ -41,10 +41,18 @@ customizable to ease retro-entry.")
(defvar ledger-mode-abbrev-table)
+(defmacro ledger-run-if-works (func-to-call)
+ "Macro to run func-to-call only if the ledger-works variable is non-nil"
+ `(lambda ()
+ (interactive)
+ (if ledger-works
+ (funcall ,func-to-call)
+ (message "Cannot run ledger, check your ledger executable"))))
;;;###autoload
(define-derived-mode ledger-mode text-mode "Ledger"
"A mode for editing ledger data files."
+ (ledger-check-version)
(ledger-post-setup)
(set (make-local-variable 'comment-start) " ; ")
@@ -62,50 +70,50 @@ customizable to ease retro-entry.")
(set (make-local-variable 'pcomplete-termination-string) "")
(let ((map (current-local-map)))
- (define-key map [(control ?c) (control ?a)] 'ledger-add-entry)
+ (define-key map [(control ?c) (control ?a)] (ledger-run-if-works 'ledger-add-entry))
(define-key map [(control ?c) (control ?d)] 'ledger-delete-current-entry)
- (define-key map [(control ?c) (control ?y)] 'ledger-set-year)
- (define-key map [(control ?c) (control ?m)] 'ledger-set-month)
+ (define-key map [(control ?c) (control ?y)] (ledger-run-if-works 'ledger-set-year))
+ (define-key map [(control ?c) (control ?m)] (ledger-run-if-works 'ledger-set-month))
(define-key map [(control ?c) (control ?c)] 'ledger-toggle-current)
(define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-entry)
- (define-key map [(control ?c) (control ?r)] 'ledger-reconcile)
+ (define-key map [(control ?c) (control ?r)] (ledger-run-if-works 'ledger-reconcile))
(define-key map [(control ?c) (control ?s)] 'ledger-sort-region)
- (define-key map [(control ?c) (control ?t)] 'ledger-test-run)
+ (define-key map [(control ?c) (control ?t)] (ledger-run-if-works 'ledger-test-run))
(define-key map [tab] 'pcomplete)
(define-key map [(control ?i)] 'pcomplete)
(define-key map [(control ?c) tab] 'ledger-fully-complete-entry)
(define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-entry)
- (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 [(control ?c) (control ?o) (control ?r)] (ledger-run-if-works 'ledger-report))
+ (define-key map [(control ?c) (control ?o) (control ?g)] (ledger-run-if-works 'ledger-report-goto))
+ (define-key map [(control ?c) (control ?o) (control ?a)] (ledger-run-if-works 'ledger-report-redo))
+ (define-key map [(control ?c) (control ?o) (control ?s)] (ledger-run-if-works 'ledger-report-save))
+ (define-key map [(control ?c) (control ?o) (control ?e)] (ledger-run-if-works 'ledger-report-edit))
+ (define-key map [(control ?c) (control ?o) (control ?k)] (ledger-run-if-works '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 so1] '("Sort Buffer" . ledger-sort-buffer))
- (define-key map [menu-bar ldg-menu so2] '("Sort Region" . ledger-sort-region))
- (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))))
+ (define-key map [report-kill] '(menu-item "Kill Report" ledger-report-kill :enable ledger-works))
+ (define-key map [report-edit] '(menu-item "Edit Report" ledger-report-edit :enable ledger-works))
+ (define-key map [report-save] '(menu-item "Save Report" ledger-report-save :enable ledger-works))
+ (define-key map [report-rrun] '(menu-item "Re-run Report" ledger-report-redo :enable ledger-works))
+ (define-key map [report-goto] '(menu-item "Goto Report" ledger-report-goto :enable ledger-works))
+ (define-key map [report-run] '(menu-item "Run Report" ledger-report :enable ledger-works))
+ (define-key map [sep5] '(menu-item "--"))
+ (define-key map [set-month] '(menu-item "Set Month" ledger-set-month :enable ledger-works))
+ (define-key map [set-year] '(menu-item "Set Year" ledger-set-year :enable ledger-works))
+ (define-key map [sep1] '("--"))
+ (define-key map [sort-buff] '(menu-item "Sort Buffer" ledger-sort-buffer))
+ (define-key map [sort-reg] '(menu-item "Sort Region" ledger-sort-region :enable mark-active))
+ (define-key map [sep2] '(menu-item "--"))
+ (define-key map [toggle-post] '(menu-item "Toggle Current Posting" ledger-toggle-current))
+ (define-key map [toggle-xact] '(menu-item "Toggle Current Transaction" ledger-toggle-current-entry))
+ (define-key map [sep4] '(menu-item "--"))
+ (define-key map [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))))
(defun ledger-time-less-p (t1 t2)
"Say whether time value T1 is less than time value T2."