Browse Source

beancount-company now working with whole transactions

master
Marc 3 years ago
parent
commit
360153f2cb
1 changed files with 79 additions and 7 deletions
  1. 86
      user-global/elisp/beancount.el

86
user-global/elisp/beancount.el

@ -489,7 +489,8 @@ Only useful if you have not installed Beancount properly in your PATH")
(when (string-match regexp string)
(setq new (cons string new))))
;;new
; (nreverse new)))
(setq new (nreverse new))
; (setq new (reverse new))
new))
(defun beancount-get-transactions-in-buffer ()
@ -568,13 +569,77 @@ Only useful if you have not installed Beancount properly in your PATH")
;; (let* (accounts (beancount-accounts-cache))
;; accounts))
;;##################################
;;stuff from https://github.com/debanjum/company-ledger/blob/master/company-ledger.el
(defun company-ledger--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))
(defun company-ledger--get-all-postings ()
"Get all paragraphs in buffer containing YYYY[-/]MM[-/]DD in them."
(company-ledger--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 company-ledger--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)))))
(defun company-ledger--next-line-empty-p ()
"Return non-nil if next line empty else false."
(save-excursion
(beginning-of-line)
(forward-line 1)
(or (looking-at "[[:space:]]*$")
(eolp)
(eobp))))
;; hier werden Vorschläge zeitlich rückwärts gemacht (jüngste Einträge zuerst)!
;;;###autoload
(defun company-beancountGIT (command &optional arg &rest ignored)
"Fuzzy company back-end for ledger, beancount and other ledger-like modes.
Provide completion info based on COMMAND and ARG. IGNORED, not used."
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-beancount))
(`interactive (company-begin-backend 'company-beancount))
(`prefix (and (eq major-mode 'beancount-mode)
(company-grab-symbol)))
; (prefix (and (or (bound-and-true-p beancount-mode)
; (derived-mode-p 'ledger-mode))
; (company-ledger--next-line-empty-p)
; (thing-at-point 'line t)))
(candidates
(cl-remove-if-not
(lambda (c) (company-ledger--fuzzy-word-match arg c))
(company-ledger--get-all-postings)))
(sorted t)))
;;end stuff
;;##################################
;;;###autoload
(defun company-beancount (command &optional arg &rest ignored)
"Company backend for 'beancount-mode'.
COMMAND, ARG, and IGNORED the regular meanings."
(interactive (list 'interactive))
(message arg)
(pcase command
(cl-case command
(`interactive (company-begin-backend 'company-beancount))
(`prefix (and (eq major-mode 'beancount-mode)
(company-grab-symbol)))
@ -618,12 +683,19 @@ COMMAND, ARG, and IGNORED the regular meanings."
;; 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,
;;TODO matches only work for first word.
;;TODO reverse list, newest one first
((delq nil
(cl-remove-if-not
(lambda (c) (beancount-company--fuzzy-word-match arg c))
(beancount-get-transactions-in-buffer))))
))))
(cl-remove-if-not
(lambda (c) (company-ledger--fuzzy-word-match arg c))
(company-ledger--get-all-postings))))
; (cl-remove-if-not
; (lambda (c) (beancount-company--fuzzy-word-match arg c))
; (beancount-get-transactions-in-buffer))))
))
;;erst hier wird Reihenfolge umgekehrt (jüngste zuerst)!
(sorted t)))
;;;###autoload
(define-derived-mode beancount-mode text-mode "Beancount"

Loading…
Cancel
Save