Bug 892 re-enable pending mode and reconcile-finish
This should do it, and it should work across multiple files.
This commit is contained in:
parent
316055ff86
commit
28659c58c3
3 changed files with 91 additions and 53 deletions
|
|
@ -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 ?y)] 'ledger-set-year)
|
||||||
(define-key map [(control ?c) (control ?m)] 'ledger-set-month)
|
(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 ?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 ?r)] 'ledger-reconcile)
|
||||||
(define-key map [(control ?c) (control ?s)] 'ledger-sort-region)
|
(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-test-run)
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,12 @@
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'ledger)
|
: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 ()
|
(defun ledger-display-balance ()
|
||||||
"Calculate the cleared balance of the account being reconciled"
|
"Calculate the cleared balance of the account being reconciled"
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
@ -79,22 +85,29 @@
|
||||||
(let ((where (get-text-property (point) 'where))
|
(let ((where (get-text-property (point) 'where))
|
||||||
(account ledger-acct)
|
(account ledger-acct)
|
||||||
(inhibit-read-only t)
|
(inhibit-read-only t)
|
||||||
cleared)
|
status)
|
||||||
(when (ledger-reconcile-get-buffer where)
|
(when (ledger-reconcile-get-buffer where)
|
||||||
(with-current-buffer (ledger-reconcile-get-buffer where)
|
(with-current-buffer (ledger-reconcile-get-buffer where)
|
||||||
(goto-char (cdr 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 the existing face and add the new face
|
||||||
(remove-text-properties (line-beginning-position)
|
(remove-text-properties (line-beginning-position)
|
||||||
(line-end-position)
|
(line-end-position)
|
||||||
(list 'face))
|
(list 'face))
|
||||||
(if cleared
|
(cond ((eq status 'pending)
|
||||||
(add-text-properties (line-beginning-position)
|
(add-text-properties (line-beginning-position)
|
||||||
(line-end-position)
|
(line-end-position)
|
||||||
(list 'face 'ledger-font-reconciler-cleared-face ))
|
(list 'face 'ledger-font-reconciler-pending-face )))
|
||||||
|
((eq status 'cleared)
|
||||||
(add-text-properties (line-beginning-position)
|
(add-text-properties (line-beginning-position)
|
||||||
(line-end-position)
|
(line-end-position)
|
||||||
(list 'face 'ledger-font-reconciler-uncleared-face ))))
|
(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)
|
(forward-line)
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(ledger-display-balance)))
|
(ledger-display-balance)))
|
||||||
|
|
@ -167,9 +180,8 @@
|
||||||
(while (not (eobp))
|
(while (not (eobp))
|
||||||
(let ((where (get-text-property (point) 'where))
|
(let ((where (get-text-property (point) 'where))
|
||||||
(face (get-text-property (point) 'face)))
|
(face (get-text-property (point) 'face)))
|
||||||
(if (and (eq face 'bold)
|
(if (eq face 'ledger-font-reconciler-pending-face)
|
||||||
(when (is-stdin (car where))))
|
(with-current-buffer (ledger-reconcile-get-buffer where)
|
||||||
(with-current-buffer ledger-buf
|
|
||||||
(goto-char (cdr where))
|
(goto-char (cdr where))
|
||||||
(ledger-toggle-current 'cleared))))
|
(ledger-toggle-current 'cleared))))
|
||||||
(forward-line 1)))
|
(forward-line 1)))
|
||||||
|
|
@ -240,9 +252,13 @@
|
||||||
"")
|
"")
|
||||||
(nth 4 xact) (nth 1 posting) (nth 2 posting)))
|
(nth 4 xact) (nth 1 posting) (nth 2 posting)))
|
||||||
(if (nth 3 posting)
|
(if (nth 3 posting)
|
||||||
|
(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))
|
(set-text-properties beg (1- (point))
|
||||||
(list 'face 'ledger-font-reconciler-cleared-face
|
(list 'face 'ledger-font-reconciler-cleared-face
|
||||||
'where where))
|
'where where)))
|
||||||
(set-text-properties beg (1- (point))
|
(set-text-properties beg (1- (point))
|
||||||
(list 'face 'ledger-font-reconciler-uncleared-face
|
(list 'face 'ledger-font-reconciler-uncleared-face
|
||||||
'where where)))) ))
|
'where where)))) ))
|
||||||
|
|
@ -327,6 +343,7 @@
|
||||||
(define-key map [(control ?m)] 'ledger-reconcile-visit)
|
(define-key map [(control ?m)] 'ledger-reconcile-visit)
|
||||||
(define-key map [return] 'ledger-reconcile-visit)
|
(define-key map [return] 'ledger-reconcile-visit)
|
||||||
(define-key map [(control ?l)] 'ledger-reconcile-refresh)
|
(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 [? ] 'ledger-reconcile-toggle)
|
||||||
(define-key map [?a] 'ledger-reconcile-add)
|
(define-key map [?a] 'ledger-reconcile-add)
|
||||||
(define-key map [?d] 'ledger-reconcile-delete)
|
(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 bal] '("Show Cleared Balance" . ledger-display-balance))
|
||||||
(define-key map [menu-bar ldg-recon-menu sep4] '("--"))
|
(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 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 ref] '("Refresh" . ledger-reconcile-refresh))
|
||||||
(define-key map [menu-bar ldg-recon-menu sav] '("Save" . ledger-reconcile-save))
|
(define-key map [menu-bar ldg-recon-menu sav] '("Save" . ledger-reconcile-save))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,26 @@
|
||||||
((looking-at "\\*\\s-*") 'cleared)
|
((looking-at "\\*\\s-*") 'cleared)
|
||||||
(t (ledger-transaction-state)))))
|
(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.
|
"Toggle the cleared status of the transaction under point.
|
||||||
Optional argument STYLE may be `pending' or `cleared', depending
|
Optional argument STYLE may be `pending' or `cleared', depending
|
||||||
on which type of status the caller wishes to indicate (default is
|
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
|
This function is rather complicated because it must preserve both
|
||||||
the overall formatting of the ledger entry, as well as ensuring
|
the overall formatting of the ledger entry, as well as ensuring
|
||||||
that the most minimal display format is used. This could be
|
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."
|
dropped."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((bounds (ledger-current-transaction-bounds))
|
(let ((bounds (ledger-current-transaction-bounds))
|
||||||
clear cleared)
|
new-status cur-status)
|
||||||
;; Uncompact the entry, to make it easier to toggle the
|
;; Uncompact the entry, to make it easier to toggle the
|
||||||
;; transaction
|
;; transaction
|
||||||
(save-excursion
|
(save-excursion ;this excursion unclears the posting
|
||||||
(goto-char (car bounds))
|
(goto-char (car bounds)) ;beginning of xact
|
||||||
(skip-chars-forward "0-9./= \t")
|
(skip-chars-forward "0-9./= \t") ;skip the date
|
||||||
(setq cleared (and (member (char-after) '(?\* ?\!))
|
(setq cur-status (and (member (char-after) '(?\* ?\!))
|
||||||
(char-after)))
|
(ledger-state-from-char (char-after)))) ;if the next char is !, * store it
|
||||||
(when cleared
|
;;if cur-status if !, or * then delete the marker
|
||||||
|
(when cur-status
|
||||||
(let ((here (point)))
|
(let ((here (point)))
|
||||||
(skip-chars-forward "*! ")
|
(skip-chars-forward "*! ")
|
||||||
(let ((width (- (point) here)))
|
(let ((width (- (point) here)))
|
||||||
|
|
@ -82,17 +98,19 @@ dropped."
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(while (looking-at "[ \t]")
|
(while (looking-at "[ \t]")
|
||||||
(skip-chars-forward " \t")
|
(skip-chars-forward " \t")
|
||||||
(insert cleared " ")
|
(insert (ledger-char-from-state cur-status) " ")
|
||||||
(if (search-forward " " (line-end-position) t)
|
(if (search-forward " " (line-end-position) t)
|
||||||
(delete-char 2))
|
(delete-char 2))
|
||||||
(forward-line))))
|
(forward-line))
|
||||||
;; Toggle the individual transaction
|
(setq new-status nil)))
|
||||||
|
|
||||||
|
;;this excursion marks the posting pending or cleared
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (line-beginning-position))
|
(goto-char (line-beginning-position))
|
||||||
(when (looking-at "[ \t]")
|
(when (looking-at "[ \t]")
|
||||||
(skip-chars-forward " \t")
|
(skip-chars-forward " \t")
|
||||||
(let ((here (point))
|
(let ((here (point))
|
||||||
(cleared (member (char-after) '(?\* ?\!))))
|
(cur-status (ledger-state-from-char (char-after))))
|
||||||
(skip-chars-forward "*! ")
|
(skip-chars-forward "*! ")
|
||||||
(let ((width (- (point) here)))
|
(let ((width (- (point) here)))
|
||||||
(when (> width 0)
|
(when (> width 0)
|
||||||
|
|
@ -101,18 +119,18 @@ dropped."
|
||||||
(if (search-forward " " (line-end-position) t)
|
(if (search-forward " " (line-end-position) t)
|
||||||
(insert (make-string width ? ))))))
|
(insert (make-string width ? ))))))
|
||||||
(let (inserted)
|
(let (inserted)
|
||||||
(if cleared
|
(if cur-status
|
||||||
(if (and style (eq style 'cleared))
|
(if (and style (eq style 'cleared))
|
||||||
(progn
|
(progn
|
||||||
(insert "* ")
|
(insert "* ")
|
||||||
(setq inserted t)))
|
(setq inserted 'cleared)))
|
||||||
(if (and style (eq style 'pending))
|
(if (and style (eq style 'pending))
|
||||||
(progn
|
(progn
|
||||||
(insert "! ")
|
(insert "! ")
|
||||||
(setq inserted t))
|
(setq inserted 'pending))
|
||||||
(progn
|
(progn
|
||||||
(insert "* ")
|
(insert "* ")
|
||||||
(setq inserted t))))
|
(setq inserted 'cleared))))
|
||||||
(if (and inserted
|
(if (and inserted
|
||||||
(re-search-forward "\\(\t\\| [ \t]\\)"
|
(re-search-forward "\\(\t\\| [ \t]\\)"
|
||||||
(line-end-position) t))
|
(line-end-position) t))
|
||||||
|
|
@ -123,26 +141,25 @@ dropped."
|
||||||
(delete-char 2))
|
(delete-char 2))
|
||||||
((looking-at " ")
|
((looking-at " ")
|
||||||
(delete-char 1))))
|
(delete-char 1))))
|
||||||
(setq clear inserted)))))
|
(setq new-status inserted)))))
|
||||||
;; Clean up the entry so that it displays minimally
|
|
||||||
|
;; This excursion cleans up the entry so that it displays minimally
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (car bounds))
|
(goto-char (car bounds))
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(let ((first t)
|
(let ((first t)
|
||||||
(state ? )
|
(state nil)
|
||||||
(hetero nil))
|
(hetero nil))
|
||||||
(while (and (not hetero) (looking-at "[ \t]"))
|
(while (and (not hetero) (looking-at "[ \t]"))
|
||||||
(skip-chars-forward " \t")
|
(skip-chars-forward " \t")
|
||||||
(let ((cleared (if (member (char-after) '(?\* ?\!))
|
(let ((cur-status (ledger-state-from-char (char-after))))
|
||||||
(char-after)
|
|
||||||
? )))
|
|
||||||
(if first
|
(if first
|
||||||
(setq state cleared
|
(setq state cur-status
|
||||||
first nil)
|
first nil)
|
||||||
(if (/= state cleared)
|
(if (not (eq state cur-status))
|
||||||
(setq hetero t))))
|
(setq hetero t))))
|
||||||
(forward-line))
|
(forward-line))
|
||||||
(when (and (not hetero) (/= state ? ))
|
(when (and (not hetero) (not (eq state nil)))
|
||||||
(goto-char (car bounds))
|
(goto-char (car bounds))
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(while (looking-at "[ \t]")
|
(while (looking-at "[ \t]")
|
||||||
|
|
@ -158,7 +175,8 @@ dropped."
|
||||||
(forward-line))
|
(forward-line))
|
||||||
(goto-char (car bounds))
|
(goto-char (car bounds))
|
||||||
(skip-chars-forward "0-9./= \t")
|
(skip-chars-forward "0-9./= \t")
|
||||||
(insert state " ")
|
(insert (ledger-char-from-state state) " ")
|
||||||
|
(setq new-status state)
|
||||||
(if (re-search-forward "\\(\t\\| [ \t]\\)"
|
(if (re-search-forward "\\(\t\\| [ \t]\\)"
|
||||||
(line-end-position) t)
|
(line-end-position) t)
|
||||||
(cond
|
(cond
|
||||||
|
|
@ -168,7 +186,7 @@ dropped."
|
||||||
(delete-char 2))
|
(delete-char 2))
|
||||||
((looking-at " ")
|
((looking-at " ")
|
||||||
(delete-char 1)))))))
|
(delete-char 1)))))))
|
||||||
clear))
|
new-status))
|
||||||
|
|
||||||
(defun ledger-toggle-current (&optional style)
|
(defun ledger-toggle-current (&optional style)
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
@ -182,21 +200,22 @@ dropped."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(not (eq 'transaction (ledger-thing-at-point)))))
|
(not (eq 'transaction (ledger-thing-at-point)))))
|
||||||
(if (looking-at "\\s-+[*!]")
|
(if (looking-at "\\s-+[*!]")
|
||||||
(ledger-toggle-current-transaction nil))
|
(ledger-toggle-current-transaction style))
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(goto-char (line-beginning-position))))
|
(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)
|
(interactive)
|
||||||
(let (clear)
|
(let (status)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(when (or (looking-at "^[0-9]")
|
(when (or (looking-at "^[0-9]")
|
||||||
(re-search-backward "^[0-9]" nil t))
|
(re-search-backward "^[0-9]" nil t))
|
||||||
(skip-chars-forward "0-9./=")
|
(skip-chars-forward "0-9./=")
|
||||||
(delete-horizontal-space)
|
(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
|
(progn
|
||||||
(delete-char 1)
|
(delete-char 1)
|
||||||
(if (and style (eq style 'cleared))
|
(if (and style (eq style 'cleared))
|
||||||
|
|
@ -204,7 +223,7 @@ dropped."
|
||||||
(if (and style (eq style 'pending))
|
(if (and style (eq style 'pending))
|
||||||
(insert " ! ")
|
(insert " ! ")
|
||||||
(insert " * "))
|
(insert " * "))
|
||||||
(setq clear t))))
|
(setq status t))))
|
||||||
clear))
|
status))
|
||||||
|
|
||||||
(provide 'ldg-state)
|
(provide 'ldg-state)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue