Browse Source

expanded company for whole transactions

master
Marc 3 years ago
parent
commit
6316fc9b14
1 changed files with 34 additions and 1 deletions
  1. 35
      user-global/elisp/beancount.el

35
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)))) (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 ;; Finishing setup
@ -585,11 +610,19 @@ COMMAND, ARG, and IGNORED the regular meanings."
;; if the preceding text is allowed before an account, offer accounts ;; if the preceding text is allowed before an account, offer accounts
;; TODO: Not yet working! ;; TODO: Not yet working!
(string-match-p beancount-timestamped-accounts-regexp (thing-at-point 'line))) (string-match-p beancount-timestamped-accounts-regexp (thing-at-point 'line)))
(delq nil
(delq nil
(mapcar (lambda (c) (mapcar (lambda (c)
(message c) (message c)
(and (string-prefix-p arg c) c)) (and (string-prefix-p arg c) c))
beancount-accounts-cache))) 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 ;;;###autoload

Loading…
Cancel
Save