summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2014-01-13 13:14:02 -0700
committerCraig Earls <enderw88@gmail.com>2014-01-13 13:14:02 -0700
commitaec2c7af3fb05631573f3a7224232934005748be (patch)
tree07941f82be2f97a76525965a973d70b89e7dc28b /lisp
parent3b5f4965369afb94dfbfcdb2325f2d329fcffaf5 (diff)
downloadfork-ledger-aec2c7af3fb05631573f3a7224232934005748be.tar.gz
fork-ledger-aec2c7af3fb05631573f3a7224232934005748be.tar.bz2
fork-ledger-aec2c7af3fb05631573f3a7224232934005748be.zip
Fix issue in ledger-fully-complete-xact to deal with possible trailing spaces after a payee
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ledger-complete.el21
1 files changed, 13 insertions, 8 deletions
diff --git a/lisp/ledger-complete.el b/lisp/ledger-complete.el
index 516a3a62..effee060 100644
--- a/lisp/ledger-complete.el
+++ b/lisp/ledger-complete.el
@@ -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))))