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.el53
1 files changed, 49 insertions, 4 deletions
diff --git a/lisp/ledger-complete.el b/lisp/ledger-complete.el
index c4ac43ef..5bb69dc2 100644
--- a/lisp/ledger-complete.el
+++ b/lisp/ledger-complete.el
@@ -145,9 +145,38 @@ 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 ()
- "Do appropriate completion for the thing at point."
- (interactive)
+ "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."
(while (pcomplete-here
(if (eq (save-excursion
(ledger-thing-at-point)) 'transaction)
@@ -168,8 +197,24 @@ Return list."
(goto-char (line-end-position))
(search-backward ";" (line-beginning-position) t)
(skip-chars-backward " \t0123456789.,")
- (throw 'pcompleted t)))
- (ledger-accounts)))))
+ (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)))
+
+(defun pcomplete/ledger-mode/acct-transaction/comment ()
+ "Complete when at amount in transaction."
+ (pcomplete-here (ledger-find-metadata-in-buffer)))
(defun ledger-fully-complete-xact ()
"Completes a transaction if there is another matching payee in the buffer.