summaryrefslogtreecommitdiff
path: root/lisp/ledger-complete.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ledger-complete.el')
-rw-r--r--lisp/ledger-complete.el74
1 files changed, 17 insertions, 57 deletions
diff --git a/lisp/ledger-complete.el b/lisp/ledger-complete.el
index 5bb69dc2..effee060 100644
--- a/lisp/ledger-complete.el
+++ b/lisp/ledger-complete.el
@@ -145,38 +145,9 @@ Return list."
(cdr root))
'string-lessp))))
-(defun ledger-command-at-point ()
- "Do appropriate completion for current context."
- (let ((context (mapcar*
- (lambda(x) (if (symbolp x) (symbol-name x)))
- (ledger-context-at-point))))
- (cond
- ((string= "acct-transaction" (car context))
- (concat (car context) "/" (nth 1 context)))
- ((string= "pmnt-transaction" (car context))
- (concat (car context) "/" (nth 1 context)))
- (t
- (car context)))))
-
(defun ledger-complete-at-point ()
- "Calls the right completion function for first argument completions."
- (ignore
- (funcall (or (pcomplete-find-completion-function
- (ledger-command-at-point))
- pcomplete-default-completion-function))))
-
-(defun pcomplete/ledger-mode/empty-line ()
- "Complete when at empty line."
- (ignore
- (ledger-add-transaction (read-string "Transaction: "
- (ledger-year-and-month)) (point))))
-
-(defun pcomplete/ledger-mode/pmnt-transaction/date ()
- "Complete when at date in transaction."
- (ignore))
-
-(defun pcomplete/ledger-mode/pmnt-transaction/payee ()
- "Complete when at payee in transaction."
+ "Do appropriate completion for the thing at point."
+ (interactive)
(while (pcomplete-here
(if (eq (save-excursion
(ledger-thing-at-point)) 'transaction)
@@ -197,42 +168,31 @@ Return list."
(goto-char (line-end-position))
(search-backward ";" (line-beginning-position) t)
(skip-chars-backward " \t0123456789.,")
- (throw 'pcompleted t)))))))
-
-(defun pcomplete/ledger-mode/acct-transaction/indent ()
- "Complete when at indent in transaction."
- (ignore (ledger-thing-at-point)))
-
-(defun pcomplete/ledger-mode/acct-transaction/account ()
- "Complete when at account in transaction."
- (set (make-local-variable 'pcomplete-termination-string) " ")
- (pcomplete-here (ledger-accounts)))
-
-(defun pcomplete/ledger-mode/acct-transaction/amount ()
- "Complete when at amount in transaction."
- (ignore (ledger-post-edit-amount)))
+ (throw 'pcompleted t)))
+ (ledger-accounts)))))
-(defun pcomplete/ledger-mode/acct-transaction/comment ()
- "Complete when at amount in transaction."
- (pcomplete-here (ledger-find-metadata-in-buffer)))
+(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)
@@ -243,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))))
@@ -266,7 +226,7 @@ ledger-magic-tab would cycle properly"
pcomplete-expand-and-complete
pcomplete-reverse)))
(progn
- (delete-char pcomplete-last-completion-length)
+ (delete-backward-char pcomplete-last-completion-length)
(if (eq this-command 'pcomplete-reverse)
(progn
(push (car (last pcomplete-current-completions))