Fix issue in ledger-fully-complete-xact to deal with possible trailing spaces after a payee
This commit is contained in:
parent
3b5f496536
commit
aec2c7af3f
1 changed files with 13 additions and 8 deletions
|
|
@ -171,23 +171,28 @@ Return list."
|
|||
(throw 'pcompleted t)))
|
||||
(ledger-accounts)))))
|
||||
|
||||
(defun ledger-trim-trailing-whitespace (str)
|
||||
(let ((s str))
|
||||
(when (string-match "[ \t]*$" s)
|
||||
(replace-match "" nil nil s))))
|
||||
|
||||
(defun ledger-fully-complete-xact ()
|
||||
"Completes a transaction if there is another matching payee in the buffer.
|
||||
Does not use ledger xact"
|
||||
(interactive)
|
||||
(let* ((name (caar (ledger-parse-arguments)))
|
||||
(rest-of-name name)
|
||||
xacts)
|
||||
(let* ((name (ledger-trim-trailing-whitespace (caar (ledger-parse-arguments))))
|
||||
(rest-of-name name)
|
||||
xacts)
|
||||
(save-excursion
|
||||
(when (eq 'transaction (ledger-thing-at-point))
|
||||
(delete-region (point) (+ (length name) (point)))
|
||||
;; Search backward for a matching payee
|
||||
(delete-region (point) (+ (length name) (point)))
|
||||
;; Search backward for a matching payee
|
||||
(when (re-search-backward
|
||||
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.*"
|
||||
(regexp-quote name) ".*\\)" ) nil t)
|
||||
(setq rest-of-name (match-string 3))
|
||||
(setq rest-of-name (match-string 3))
|
||||
;; Start copying the postings
|
||||
(forward-line)
|
||||
(forward-line)
|
||||
(while (looking-at ledger-account-any-status-regex)
|
||||
(setq xacts (cons (buffer-substring-no-properties
|
||||
(line-beginning-position)
|
||||
|
|
@ -198,7 +203,7 @@ Does not use ledger xact"
|
|||
;; Insert rest-of-name and the postings
|
||||
(when xacts
|
||||
(save-excursion
|
||||
(insert rest-of-name ?\n)
|
||||
(insert rest-of-name ?\n)
|
||||
(while xacts
|
||||
(insert (car xacts) ?\n)
|
||||
(setq xacts (cdr xacts))))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue