diff options
author | John Wiegley <johnw@newartisans.com> | 2013-01-16 12:18:33 -0800 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2013-01-16 12:18:33 -0800 |
commit | 6ff7dac73f78e885637b2827457ac5e4acfded67 (patch) | |
tree | 61e53a8960a3dbd54f3ba11e3361525c506430de /lisp/ldg-mode.el | |
parent | d922f4659570c87a06352b0da9d877f047ec442c (diff) | |
parent | 855432c4cd32b03b0751cffb0e215f2ceefdc6e5 (diff) | |
download | fork-ledger-6ff7dac73f78e885637b2827457ac5e4acfded67.tar.gz fork-ledger-6ff7dac73f78e885637b2827457ac5e4acfded67.tar.bz2 fork-ledger-6ff7dac73f78e885637b2827457ac5e4acfded67.zip |
Merge pull request #122 from enderw88/Lisp-fixes
Fix ledger-add-entry
Diffstat (limited to 'lisp/ldg-mode.el')
-rw-r--r-- | lisp/ldg-mode.el | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 6090a312..04c6ee1b 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -76,6 +76,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 +136,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: ") |