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.el79
1 files changed, 77 insertions, 2 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el
index 6090a312..caa57e8e 100644
--- a/lisp/ldg-mode.el
+++ b/lisp/ldg-mode.el
@@ -19,6 +19,7 @@
(defvar ledger-mode-abbrev-table)
+
;;;###autoload
(define-derived-mode ledger-mode text-mode "Ledger"
"A mode for editing ledger data files."
@@ -51,8 +52,41 @@
(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 ?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 [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 so] '("Sort Buffer" . ledger-sort))
+ (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)))
+
+
+
(ledger-report-patch-reports (current-buffer)))
(defun ledger-time-less-p (t1 t2)
@@ -76,6 +110,47 @@ Return the difference in the format of a time value."
(if (ledger-time-less-p moment date)
(throw 'found t)))))))
+(defun ledger-iterate-entries (callback)
+ (goto-char (point-min))
+ (let* ((now (current-time))
+ (current-year (nth 5 (decode-time now))))
+ (while (not (eobp))
+ (when (looking-at
+ (concat "\\(Y\\s-+\\([0-9]+\\)\\|"
+ "\\([0-9]\\{4\\}+\\)?[./]?"
+ "\\([0-9]+\\)[./]\\([0-9]+\\)\\s-+"
+ "\\(\\*\\s-+\\)?\\(.+\\)\\)"))
+ (let ((found (match-string 2)))
+ (if found
+ (setq current-year (string-to-number found))
+ (let ((start (match-beginning 0))
+ (year (match-string 3))
+ (month (string-to-number (match-string 4)))
+ (day (string-to-number (match-string 5)))
+ (mark (match-string 6))
+ (desc (match-string 7)))
+ (if (and year (> (length year) 0))
+ (setq year (string-to-number year)))
+ (funcall callback start
+ (encode-time 0 0 0 day month
+ (or year current-year))
+ mark desc)))))
+ (forward-line))))
+
+(defun ledger-set-year (newyear)
+ "Set ledger's idea of the current year to the prefix argument."
+ (interactive "p")
+ (if (= newyear 1)
+ (setq ledger-year (read-string "Year: " (ledger-current-year)))
+ (setq ledger-year (number-to-string newyear))))
+
+(defun ledger-set-month (newmonth)
+ "Set ledger's idea of the current month to the prefix argument."
+ (interactive "p")
+ (if (= newmonth 1)
+ (setq ledger-month (read-string "Month: " (ledger-current-month)))
+ (setq ledger-month (format "%02d" newmonth))))
+
(defun ledger-add-entry (entry-text &optional insert-at-point)
(interactive "sEntry: ")
(let* ((args (with-temp-buffer
@@ -95,7 +170,7 @@ Return the difference in the format of a time value."
(insert
(with-temp-buffer
(setq exit-code
- (apply #'ledger-run-ledger ledger-buf "entry"
+ (apply #'ledger-exec-ledger ledger-buf ledger-buf "entry"
(mapcar 'eval args)))
(goto-char (point-min))
(if (looking-at "Error: ")