diff options
author | Craig Earls <enderw88@gmail.com> | 2013-02-01 15:17:33 -0800 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2013-02-01 15:17:33 -0800 |
commit | 0f3fef427fe7c4566375bfa274e80aa2361bad61 (patch) | |
tree | 849c97ac942bd7ad9b16141245b6453ecd0e0a06 | |
parent | fdb9d0c2cae9a7827d9eaf6f7e7ba56ccc86a3fb (diff) | |
parent | 36e77bd357e41dc02b79617401845640d02963f6 (diff) | |
download | fork-ledger-0f3fef427fe7c4566375bfa274e80aa2361bad61.tar.gz fork-ledger-0f3fef427fe7c4566375bfa274e80aa2361bad61.tar.bz2 fork-ledger-0f3fef427fe7c4566375bfa274e80aa2361bad61.zip |
Merge pull request #145 from enderw88/next
Check for ledger executable and version
-rw-r--r-- | lisp/ldg-exec.el | 31 | ||||
-rw-r--r-- | lisp/ldg-mode.el | 70 | ||||
-rw-r--r-- | lisp/ldg-sort.el | 1 |
3 files changed, 70 insertions, 32 deletions
diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el index ab041fec..f13cfa5a 100644 --- a/lisp/ldg-exec.el +++ b/lisp/ldg-exec.el @@ -19,6 +19,12 @@ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. +(defconst ledger-version-needed "3.0.0" + "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") + (defgroup ledger-exec nil "Interface to the Ledger command-line accounting program." :group 'ledger) @@ -52,4 +58,29 @@ (read (current-buffer)) (kill-buffer (current-buffer))))) +(defun ledger-version-greater-p (needed) + "verify the ledger binary is usable for ledger-mode" + (let ((buffer ledger-buf) + (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)))) + +(defun ledger-check-version () + (interactive) + (setq ledger-works (ledger-version-greater-p ledger-version-needed)) + (if ledger-works + (message "Good Ledger Version") + (message "Bad Ledger Version"))) + (provide 'ldg-exec) 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." diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el index e1988413..9cecefa4 100644 --- a/lisp/ldg-sort.el +++ b/lisp/ldg-sort.el @@ -39,7 +39,6 @@ (save-excursion (save-restriction (ledger-next-record-function) ;make sure point is at the beginning of a xact - (message "beg: %s end: %s" new-beg new-end) (setq new-beg (point)) (goto-char end) (ledger-next-record-function) ;make sure end of region is at the beginning of |