From 6316fc9b141eb9a8cc7bfc367f1ee17b32705221 Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 23 Dec 2020 18:08:49 +0100 Subject: [PATCH] expanded company for whole transactions --- user-global/elisp/beancount.el | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/user-global/elisp/beancount.el b/user-global/elisp/beancount.el index 4dcc5d1..d3b9fa8 100644 --- a/user-global/elisp/beancount.el +++ b/user-global/elisp/beancount.el @@ -482,6 +482,31 @@ Only useful if you have not installed Beancount properly in your PATH") (pcomplete-uniqify-list (nreverse commodities-list)))) +(defun beancount-company--regexp-filter (regexp list) + "Use REGEXP to filter LIST of strings." + (let (new) + (dolist (string list) + (when (string-match regexp string) + (setq new (cons string new)))) + ;;new +; (nreverse new))) + new)) + +(defun beancount-get-transactions-in-buffer () + "Return a list of all transactions." + (beancount-company--regexp-filter + "[0-9][0-9][0-9][0-9][-/][0-9][0-9][-/][0-9][0-9]" + (mapcar (lambda (s) (substring s 1)) + (split-string (buffer-string) "^$" t)))) + +(defun beancount-company--fuzzy-word-match (prefix candidate) + "Return non-nil if each (partial) word in PREFIX is also in CANDIDATE." + (eq nil + (memq nil + (mapcar + (lambda (pre) (string-match-p (regexp-quote pre) candidate)) + (split-string prefix))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Finishing setup @@ -585,11 +610,19 @@ COMMAND, ARG, and IGNORED the regular meanings." ;; if the preceding text is allowed before an account, offer accounts ;; TODO: Not yet working! (string-match-p beancount-timestamped-accounts-regexp (thing-at-point 'line))) - (delq nil + (delq nil (mapcar (lambda (c) (message c) (and (string-prefix-p arg c) c)) beancount-accounts-cache))) + ;; new function for whole transactions! + ;; source https://github.com/debanjum/company-ledger/blob/master/company-ledger.el + ;; these suggestions go when there are no matches for the stuff before + ;;TODO matches only work for first word, + ((delq nil + (cl-remove-if-not + (lambda (c) (beancount-company--fuzzy-word-match arg c)) + (beancount-get-transactions-in-buffer)))) )))) ;;;###autoload