diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ldg-mode.el | 2 | ||||
-rw-r--r-- | lisp/ldg-reconcile.el | 49 | ||||
-rw-r--r-- | lisp/ldg-state.el | 93 |
3 files changed, 91 insertions, 53 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 628b4b8a..95b02fdd 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -75,7 +75,7 @@ customizable to ease retro-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 ?c)] 'ledger-toggle-current) - (define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-entry) + (define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-transaction) (define-key map [(control ?c) (control ?r)] 'ledger-reconcile) (define-key map [(control ?c) (control ?s)] 'ledger-sort-region) (define-key map [(control ?c) (control ?t)] 'ledger-test-run) diff --git a/lisp/ldg-reconcile.el b/lisp/ldg-reconcile.el index 6179428f..61db2472 100644 --- a/lisp/ldg-reconcile.el +++ b/lisp/ldg-reconcile.el @@ -48,6 +48,12 @@ :type 'boolean :group 'ledger) +(defcustom ledger-reconcile-toggle-to-pending t + "if true then toggle between uncleared and pending. + reconcile-finish will mark all pending posting cleared. " + :type 'boolean + :group 'ledger) + (defun ledger-display-balance () "Calculate the cleared balance of the account being reconciled" (interactive) @@ -79,22 +85,29 @@ (let ((where (get-text-property (point) 'where)) (account ledger-acct) (inhibit-read-only t) - cleared) + status) (when (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) - (setq cleared (ledger-toggle-current))) + (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending + 'pending + 'cleared)))) ;remove the existing face and add the new face (remove-text-properties (line-beginning-position) (line-end-position) (list 'face)) - (if cleared - (add-text-properties (line-beginning-position) - (line-end-position) - (list 'face 'ledger-font-reconciler-cleared-face )) - (add-text-properties (line-beginning-position) - (line-end-position) - (list 'face 'ledger-font-reconciler-uncleared-face )))) + (cond ((eq status 'pending) + (add-text-properties (line-beginning-position) + (line-end-position) + (list 'face 'ledger-font-reconciler-pending-face ))) + ((eq status 'cleared) + (add-text-properties (line-beginning-position) + (line-end-position) + (list 'face 'ledger-font-reconciler-cleared-face ))) + (t + (add-text-properties (line-beginning-position) + (line-end-position) + (list 'face 'ledger-font-reconciler-uncleared-face ))))) (forward-line) (beginning-of-line) (ledger-display-balance))) @@ -167,9 +180,8 @@ (while (not (eobp)) (let ((where (get-text-property (point) 'where)) (face (get-text-property (point) 'face))) - (if (and (eq face 'bold) - (when (is-stdin (car where)))) - (with-current-buffer ledger-buf + (if (eq face 'ledger-font-reconciler-pending-face) + (with-current-buffer (ledger-reconcile-get-buffer where) (goto-char (cdr where)) (ledger-toggle-current 'cleared)))) (forward-line 1))) @@ -240,9 +252,13 @@ "") (nth 4 xact) (nth 1 posting) (nth 2 posting))) (if (nth 3 posting) - (set-text-properties beg (1- (point)) - (list 'face 'ledger-font-reconciler-cleared-face - 'where where)) + (if (eq (nth 3 posting) 'pending) + (set-text-properties beg (1- (point)) + (list 'face 'ledger-font-reconciler-pending-face + 'where where)) + (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)))) )) @@ -327,6 +343,7 @@ (define-key map [(control ?m)] 'ledger-reconcile-visit) (define-key map [return] 'ledger-reconcile-visit) (define-key map [(control ?l)] 'ledger-reconcile-refresh) + (define-key map [(control ?c) (control ?c)] 'ledger-reconcile-finish) (define-key map [? ] 'ledger-reconcile-toggle) (define-key map [?a] 'ledger-reconcile-add) (define-key map [?d] 'ledger-reconcile-delete) @@ -353,6 +370,8 @@ (define-key map [menu-bar ldg-recon-menu bal] '("Show Cleared Balance" . ledger-display-balance)) (define-key map [menu-bar ldg-recon-menu sep4] '("--")) (define-key map [menu-bar ldg-recon-menu rna] '("Reconcile New Account" . ledger-reconcile)) + (define-key map [menu-bar ldg-recon-menu sep5] '("--")) + (define-key map [menu-bar ldg-recon-menu fin] '("Finish" . ledger-reconcile-finish)) (define-key map [menu-bar ldg-recon-menu ref] '("Refresh" . ledger-reconcile-refresh)) (define-key map [menu-bar ldg-recon-menu sav] '("Save" . ledger-reconcile-save)) diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el index 443cb350..7c499d3e 100644 --- a/lisp/ldg-state.el +++ b/lisp/ldg-state.el @@ -50,11 +50,26 @@ ((looking-at "\\*\\s-*") 'cleared) (t (ledger-transaction-state))))) -(defun ledger-toggle-current-transaction (&optional style) +(defun ledger-char-from-state (state) + (if state + (if (eq state 'pending) + "!" + "*") + "")) + +(defun ledger-state-from-char (state-char) + (cond ((eql state-char ?\!) + 'pending) + ((eql state-char ?\*) + 'cleared) + (t + nil))) + +(defun ledger-toggle-current-posting (&optional style) "Toggle the cleared status of the transaction under point. Optional argument STYLE may be `pending' or `cleared', depending on which type of status the caller wishes to indicate (default is -`cleared'). +`cleared'). Returns the new status as 'pending 'cleared or nil. This function is rather complicated because it must preserve both the overall formatting of the ledger entry, as well as ensuring that the most minimal display format is used. This could be @@ -63,15 +78,16 @@ formatting, but doing so causes inline math expressions to be dropped." (interactive) (let ((bounds (ledger-current-transaction-bounds)) - clear cleared) + new-status cur-status) ;; Uncompact the entry, to make it easier to toggle the ;; transaction - (save-excursion - (goto-char (car bounds)) - (skip-chars-forward "0-9./= \t") - (setq cleared (and (member (char-after) '(?\* ?\!)) - (char-after))) - (when cleared + (save-excursion ;this excursion unclears the posting + (goto-char (car bounds)) ;beginning of xact + (skip-chars-forward "0-9./= \t") ;skip the date + (setq cur-status (and (member (char-after) '(?\* ?\!)) + (ledger-state-from-char (char-after)))) ;if the next char is !, * store it + ;;if cur-status if !, or * then delete the marker + (when cur-status (let ((here (point))) (skip-chars-forward "*! ") (let ((width (- (point) here))) @@ -82,17 +98,19 @@ dropped." (forward-line) (while (looking-at "[ \t]") (skip-chars-forward " \t") - (insert cleared " ") + (insert (ledger-char-from-state cur-status) " ") (if (search-forward " " (line-end-position) t) (delete-char 2)) - (forward-line)))) - ;; Toggle the individual transaction - (save-excursion + (forward-line)) + (setq new-status nil))) + + ;;this excursion marks the posting pending or cleared + (save-excursion (goto-char (line-beginning-position)) (when (looking-at "[ \t]") (skip-chars-forward " \t") (let ((here (point)) - (cleared (member (char-after) '(?\* ?\!)))) + (cur-status (ledger-state-from-char (char-after)))) (skip-chars-forward "*! ") (let ((width (- (point) here))) (when (> width 0) @@ -101,18 +119,18 @@ dropped." (if (search-forward " " (line-end-position) t) (insert (make-string width ? )))))) (let (inserted) - (if cleared + (if cur-status (if (and style (eq style 'cleared)) (progn (insert "* ") - (setq inserted t))) + (setq inserted 'cleared))) (if (and style (eq style 'pending)) (progn (insert "! ") - (setq inserted t)) + (setq inserted 'pending)) (progn (insert "* ") - (setq inserted t)))) + (setq inserted 'cleared)))) (if (and inserted (re-search-forward "\\(\t\\| [ \t]\\)" (line-end-position) t)) @@ -123,26 +141,25 @@ dropped." (delete-char 2)) ((looking-at " ") (delete-char 1)))) - (setq clear inserted))))) - ;; Clean up the entry so that it displays minimally + (setq new-status inserted))))) + + ;; This excursion cleans up the entry so that it displays minimally (save-excursion (goto-char (car bounds)) (forward-line) (let ((first t) - (state ? ) + (state nil) (hetero nil)) (while (and (not hetero) (looking-at "[ \t]")) (skip-chars-forward " \t") - (let ((cleared (if (member (char-after) '(?\* ?\!)) - (char-after) - ? ))) + (let ((cur-status (ledger-state-from-char (char-after)))) (if first - (setq state cleared + (setq state cur-status first nil) - (if (/= state cleared) + (if (not (eq state cur-status)) (setq hetero t)))) (forward-line)) - (when (and (not hetero) (/= state ? )) + (when (and (not hetero) (not (eq state nil))) (goto-char (car bounds)) (forward-line) (while (looking-at "[ \t]") @@ -158,7 +175,8 @@ dropped." (forward-line)) (goto-char (car bounds)) (skip-chars-forward "0-9./= \t") - (insert state " ") + (insert (ledger-char-from-state state) " ") + (setq new-status state) (if (re-search-forward "\\(\t\\| [ \t]\\)" (line-end-position) t) (cond @@ -168,7 +186,7 @@ dropped." (delete-char 2)) ((looking-at " ") (delete-char 1))))))) - clear)) + new-status)) (defun ledger-toggle-current (&optional style) (interactive) @@ -182,21 +200,22 @@ dropped." (save-excursion (not (eq 'transaction (ledger-thing-at-point))))) (if (looking-at "\\s-+[*!]") - (ledger-toggle-current-transaction nil)) + (ledger-toggle-current-transaction style)) (forward-line) (goto-char (line-beginning-position)))) - (ledger-toggle-current-entry style)) - (ledger-toggle-current-transaction style))) + (ledger-toggle-current-transaction style)) + (ledger-toggle-current-posting style))) -(defun ledger-toggle-current-entry (&optional style) +(defun ledger-toggle-current-transaction (&optional style) (interactive) - (let (clear) + (let (status) (save-excursion (when (or (looking-at "^[0-9]") (re-search-backward "^[0-9]" nil t)) (skip-chars-forward "0-9./=") (delete-horizontal-space) - (if (member (char-after) '(?\* ?\!)) + (if (or (eq (ledger-state-from-char (char-after)) 'pending) + (eq (ledger-state-from-char (char-after)) 'cleared)) (progn (delete-char 1) (if (and style (eq style 'cleared)) @@ -204,7 +223,7 @@ dropped." (if (and style (eq style 'pending)) (insert " ! ") (insert " * ")) - (setq clear t)))) - clear)) + (setq status t)))) + status)) (provide 'ldg-state) |