diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ldg-mode.el | 3 | ||||
-rw-r--r-- | lisp/ldg-occur.el | 1 | ||||
-rw-r--r-- | lisp/ldg-reconcile.el | 166 |
3 files changed, 96 insertions, 74 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index f71bb58e..4754e423 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -28,17 +28,16 @@ (defvar ledger-year (ledger-current-year) "Start a ledger session with the current year, but make it customizable to ease retro-entry.") + (defvar ledger-month (ledger-current-month) "Start a ledger session with the current month, but make it customizable to ease retro-entry.") - (defcustom ledger-default-acct-transaction-indent " " "Default indentation for account transactions in an entry." :type 'string :group 'ledger) - (defvar ledger-mode-abbrev-table) ;;;###autoload diff --git a/lisp/ldg-occur.el b/lisp/ldg-occur.el index e830f339..d498b9e4 100644 --- a/lisp/ldg-occur.el +++ b/lisp/ldg-occur.el @@ -46,6 +46,7 @@ (defcustom ledger-occur-use-face-unfolded t "if non-nil use a custom face for xacts shown in ledger-occur mode" + :type 'boolean :group 'ledger) (make-variable-buffer-local 'ledger-occur-use-face-unfolded) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index ee87b1b8..e0ba1ea7 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -24,6 +24,7 @@ (defvar ledger-buf nil) (defvar ledger-bufs nil) (defvar ledger-acct nil) + (defcustom ledger-recon-buffer-name "*Reconcile*" "Name to use for reconciliation window" :group 'ledger) @@ -31,6 +32,20 @@ (defcustom ledger-fold-on-reconcile t "if t, limit transactions shown in main buffer to those matching the reconcile regex" + :type 'boolean + :group 'ledger) + +(defcustom ledger-buffer-tracks-reconcile-buffer t + "if t, then when the cursor is moved to a new xact in the recon + window, then that transaction will be shown in its source + buffer." + :type 'boolean + :group 'ledger) + +(defcustom ledger-reconcile-force-window-bottom nil + "If t make the reconcile window appear along the bottom of the + register window and resize" + :type 'boolean :group 'ledger) (defun ledger-display-balance () @@ -55,8 +70,10 @@ (equal file "/dev/stdin"))) (defun ledger-reconcile-get-buffer (where) - (when (bufferp (car where)) - (car where))) + (if (bufferp (car where)) + (car where) + (error "buffer not set"))) + (defun ledger-reconcile-toggle () (interactive) @@ -64,11 +81,13 @@ (account ledger-acct) (inhibit-read-only t) cleared) +; (when (is-stdin (car where)) +; (with-current-buffer ledger-buf (when (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (setq cleared (ledger-toggle-current-entry))) - ;remove the existing face and add the new face + ;remove the existing face and add the new face (remove-text-properties (line-beginning-position) (line-end-position) (list 'face)) @@ -126,16 +145,25 @@ (delete-region (point) (1+ (line-end-position))) (set-buffer-modified-p t))))) -(defun ledger-reconcile-visit () - (interactive) - (let ((where (get-text-property (point) 'where))) - (when (ledger-reconcile-get-buffer where) - (switch-to-buffer-other-window (ledger-reconcile-get-buffer where)) - (goto-char (cdr where)) - (recenter)))) +(defun ledger-reconcile-visit (&optional come-back) + (progn + (beginning-of-line) + (let* ((where (get-text-property (1+ (point)) 'where)) + (target-buffer (if where + (ledger-reconcile-get-buffer where) + nil)) + (cur-buf (current-buffer))) + (when target-buffer + (switch-to-buffer-other-window target-buffer) + (goto-char (cdr where)) + (recenter) + (if come-back + (switch-to-buffer-other-window cur-buf)))))) (defun ledger-reconcile-save () (interactive) +; (with-current-buffer ledger-buf +; (save-buffer)) (dolist (buf (cons ledger-buf ledger-bufs)) (with-current-buffer buf (save-buffer))) @@ -145,6 +173,9 @@ (defun ledger-reconcile-quit () (interactive) (let ((buf ledger-buf)) + (with-current-buffer ledger-buf + (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t)) + ;Make sure you delete the window before you delete the buffer, ;otherwise, madness ensues (delete-window (get-buffer-window (current-buffer))) @@ -152,40 +183,19 @@ (if ledger-fold-on-reconcile (ledger-occur-quit-buffer buf)))) -(defun ledger-reconcile-finish () - (interactive) - (save-excursion - (goto-char (point-min)) - (while (not (eobp)) - (let ((where (get-text-property (point) 'where)) - (face (get-text-property (point) 'face))) - (if (and (eq face 'bold) - (ledger-reconcile-get-buffer where)) - (with-current-buffer (ledger-reconcile-get-buffer where) - (goto-char (cdr where)) - (ledger-toggle-current 'cleared)))) - (forward-line 1))) - (ledger-reconcile-save)) - (defun ledger-marker-where-xact-is (emacs-xact) "find the position of the xact in the ledger-buf buffer using - the emacs output from ledger, return a marker to the beginning - of the xact in the buffer" - (let ((buf (if (is-stdin emacs-xact) - ledger-buf - (find-file-noselect (nth 0 item))))) - (with-current-buffer buf ;use the ledger-buf buffer + the emacs output from ledger, return the buffer and a marker + to the beginning of the xact in that buffer" + (let ((buf (if (is-stdin (nth 0 emacs-xact)) + ledger-buf + (find-file-noselect (nth 0 emacs-xact))))) + (with-current-buffer buf (cons buf - (if ledger-clear-whole-entries ;determines whether to - ;clear on the payee line - ;or posting line - (save-excursion - (goto-line (nth 1 item)) - (point-marker)) - (save-excursion - (goto-line (nth 0 xact)) - (point-marker))))))) + (save-excursion + (goto-line (nth 1 emacs-xact)) + (point-marker)))))) (defun ledger-do-reconcile () "get the uncleared transactions in the account and display them @@ -201,28 +211,29 @@ (unless (looking-at "(") (error (buffer-string))) (read (current-buffer)))))) - (setq ledger-bufs ()) (if (> (length items) 0) - (dolist (item items) - (let ((index 1)) - (dolist (xact (nthcdr 5 item)) - (let ((beg (point)) - (where (ledger-marker-where-xact-is item))) - (add-to-list 'ledger-bufs (car where)) - (insert (format "%s %-4s %-30s %-30s %15s\n" - (format-time-string "%Y/%m/%d" (nth 2 item)) - (if (nth 3 item) - (nth 3 item) - "") - (nth 4 item) (nth 1 xact) (nth 2 xact))) - (if (nth 3 xact) - (set-text-properties beg (1- (point)) - (list 'face 'ledger-font-reconciler-cleared-face - 'where where)) - (set-text-properties beg (1- (point)) - (list 'face 'ledger-font-reconciler-uncleared-face - 'where where)))) - (setq index (1+ index))))) + (progn + (dolist (item items) + (let ((index 1)) + (dolist (xact (nthcdr 5 item)) + (let ((beg (point)) + (where (ledger-marker-where-xact-is item))) + (insert (format "%s %-4s %-30s %-30s %15s\n" + (format-time-string "%Y/%m/%d" (nth 2 item)) + (if (nth 3 item) + (nth 3 item) + "") + (nth 4 item) (nth 1 xact) (nth 2 xact))) + (if (nth 3 xact) + (set-text-properties beg (1- (point)) + (list 'face 'ledger-font-reconciler-cleared-face + 'where where)) + (set-text-properties beg (1- (point)) + (list 'face 'ledger-font-reconciler-uncleared-face + 'where where)))) + (setq index (1+ index))))) + (goto-char (point-max)) + (delete-char -1)) (insert (concat "There are no uncleared entries for " account))) (goto-char (point-min)) (set-buffer-modified-p nil) @@ -242,7 +253,17 @@ (goto-char (point-max)) (recenter -1)) - (select-window recon-window)))) + (select-window recon-window) + (add-hook 'post-command-hook 'ledger-reconcile-track-xact nil t) + (ledger-reconcile-visit t)))) + +(defun ledger-reconcile-track-xact () + (if (member this-command (list 'next-line + 'previous-line + 'mouse-set-point + 'ledger-reconcile-toggle)) + (save-excursion + (ledger-reconcile-visit t)))) (defun ledger-reconcile (account) (interactive "sAccount to reconcile: ") @@ -252,17 +273,20 @@ (progn (quit-window (get-buffer-window rbuf)) (kill-buffer rbuf))) - (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save) + (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) (if ledger-fold-on-reconcile (ledger-occur-mode account buf)) - ;create the *Reconcile* window directly below the ledger buffer. (with-current-buffer - (progn - (set-window-buffer - (split-window (get-buffer-window (current-buffer)) nil nil) - (get-buffer-create ledger-recon-buffer-name)) - (get-buffer ledger-recon-buffer-name)) + (if ledger-reconcile-force-window-bottom + ;create the *Reconcile* window directly below the ledger + ;buffer. + (progn + (set-window-buffer + (split-window (get-buffer-window (current-buffer)) nil nil) + (get-buffer-create ledger-recon-buffer-name)) + (get-buffer ledger-recon-buffer-name)) + (pop-to-buffer (get-buffer-create ledger-recon-buffer-name))) (ledger-reconcile-mode) (set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-acct) account) @@ -275,8 +299,6 @@ (let ((map (make-sparse-keymap))) (define-key map [(control ?m)] 'ledger-reconcile-visit) (define-key map [return] 'ledger-reconcile-visit) - (define-key map [(control ?c) (control ?c)] 'ledger-reconcile-finish) - (define-key map [(control ?x) (control ?s)] 'ledger-reconcile-save) (define-key map [(control ?l)] 'ledger-reconcile-refresh) (define-key map [? ] 'ledger-reconcile-toggle) (define-key map [?a] 'ledger-reconcile-add) @@ -308,4 +330,4 @@ (use-local-map map))) -(provide 'ldg-reconcile) +(provide 'ldg-reconcile)
\ No newline at end of file |