diff options
author | 4ourbit <4ourbit@gmail.com> | 2013-12-31 02:12:52 +0100 |
---|---|---|
committer | 4ourbit <4ourbit@gmail.com> | 2013-12-31 03:16:57 +0100 |
commit | 383f17f1146b700f3c152129cf8733c80bc79286 (patch) | |
tree | 8510a45721bd9de1348eda306b60a912ec5b2f11 /lisp/ledger-complete.el | |
parent | c00e4eb8c69c5e55a3283cf692df2146c6bc8d9f (diff) | |
download | ledger-383f17f1146b700f3c152129cf8733c80bc79286.tar.gz ledger-383f17f1146b700f3c152129cf8733c80bc79286.tar.bz2 ledger-383f17f1146b700f3c152129cf8733c80bc79286.zip |
Context-aware pcomplete rules.
Provide completions based on information retrieved with 'ledger-context-at-point'.
To support step-by-step completion of transactions some more patterns were added
to 'ledger-line-config'. The actual completion rules mostly reuse some of the
convenient input commands that are buried in ledger-mode. Using the standard
pcomplete termination string (" ") to allow a "context switch" at the end of each
completion step.
Diffstat (limited to 'lisp/ledger-complete.el')
-rw-r--r-- | lisp/ledger-complete.el | 53 |
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. |