|
|
@ -3,7 +3,6 @@ |
|
|
|
;; A humble try to port leder-mode to beancount |
|
|
|
|
|
|
|
;;; Code: |
|
|
|
;(require 'beancount-regex) |
|
|
|
|
|
|
|
(require 'font-lock) |
|
|
|
(require 'company) ; for company-mode |
|
|
@ -93,11 +92,6 @@ |
|
|
|
"[:alnum:]-_:" |
|
|
|
"Allowed account characters.") |
|
|
|
|
|
|
|
;beancount-account-regexp original |
|
|
|
;"\\(?:A\\(?:ktiva\\|ssets\\|ufwendungen\\)\\|E\\(?:igenkapital\\|quity\\|rtraege\\|xpenses\\)\\|Income\\|Liabilities\\|Verbindlichkeiten\\)\\(?::[[:upper:]][[:alnum:]-_]+\\)+" |
|
|
|
|
|
|
|
;"\\(?:A\\(?:ktiva\\|ssets\\|ufwendungen\\)\\|E\\(?:igenkapital\\|quity\\|rtraege\\|xpenses\\)\\|Income\\|Liabilities\\|Verbindlichkeiten\\)\\(?::[[:upper:]][[:alnum:]-_]+\\)+" |
|
|
|
; ^[\s\{2\}][Aufwendungen\|Aktiva\[:[:alnum:]-_]+ |
|
|
|
(defconst beancount-account-regexp |
|
|
|
"^[ ][ ][a-z]+" |
|
|
|
; (concat (regexp-opt beancount-account-categories) |
|
|
@ -118,10 +112,6 @@ |
|
|
|
(defconst beancount-date-regexp |
|
|
|
|
|
|
|
"^[12][901][0-9]\\{2\\}-\\(0[1-9]\\|1[012]\\)-\\([012][0-9]\\|3[01]\\)" |
|
|
|
;"\\(^[12][901][0-9]\\{2\\}-\\(0[1-9]\\|1[012]\\)-\\([012][0-9]\\|3[01]\\)\\)" |
|
|
|
;"\\(^[12][901][0-9]\\{2\\}-\\(0[1-9]\\|1[012]\\)-\\(\\([012][0-9]\\)\\(\\|3[01]\\)\\)\\)" |
|
|
|
; "^[12][901][0-9]\\{2\\}-0[1-9]1[012]-[012][0-9]3[01]" |
|
|
|
; "^[12][901][0-9]\\{2\\}-\\(\\(0[1-9]\\)\\|\\(1[012]\\)\\)-\\(\\([012][0-9]\\)\\|\\(3[01]\\)\\)" |
|
|
|
"Regular expression for dates.") |
|
|
|
|
|
|
|
(defconst beancount-number-regexp |
|
|
@ -196,8 +186,6 @@ |
|
|
|
"\\)$" ; the whole regex looks from the right side of the line |
|
|
|
)) |
|
|
|
|
|
|
|
; "^[12][901][0-9]\\{2\\}-\\(0[1-9]\\|1[012]\\)-\\([012][0-9]\\|3[01]\\)\\(\\s-+[\\*!]\\)\\s-+\"[^\"]*\"\\s-+\"[^\"]*\"\\(?1:\\s-+#\\)" |
|
|
|
; "^[12][901][0-9]\\{2\\}-\\(0[1-9]\\|1[012]\\)-\\([012][0-9]\\|3[01]\\)\\(\\s-+[\\*!]\\)\\s-+\"[^\"\n]*\"\\s-+\"[^\"\n]*\"\\(?1:\\s-+#\\)" |
|
|
|
(defconst beancount-prefix-for-tag-completion-regex |
|
|
|
(concat ;"\\(" |
|
|
|
beancount-date-and-status-regex |
|
|
@ -211,8 +199,6 @@ |
|
|
|
"\\(?1:" |
|
|
|
"[^\"\n]*" |
|
|
|
"\\)" |
|
|
|
|
|
|
|
;"\\)$" ; the whole regex looks from the right side of the line |
|
|
|
)) |
|
|
|
|
|
|
|
(defconst beancount-comments-regex |
|
|
@ -371,10 +357,8 @@ This is a cache of the value computed by `beancount-get-accounts'.") |
|
|
|
(interactive) |
|
|
|
(setq beancount-accounts (beancount-get-accounts-in-buffer)) ;-new |
|
|
|
(pcomplete-uniqify-list (nreverse beancount-accounts)) |
|
|
|
;; (setq beancount-accounts (beancount-get-accounts)) |
|
|
|
(message "Accounts updated.")) |
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
;; Navigation |
|
|
|
|
|
|
@ -419,12 +403,6 @@ Leave point at the beginning of the thing under point.") |
|
|
|
"Replace trailing whitespaces in STR." |
|
|
|
(replace-regexp-in-string "[ \t]*$" "" str)) |
|
|
|
|
|
|
|
;; (defun beancount-fully-complete-xact () |
|
|
|
;; "Completes a transaction if there is another matching payee in the buffer." |
|
|
|
;; (interactive) |
|
|
|
;; (let* ((name (beancount-trim-trailing-whitespace (caar (beancount-parse-arguments)))) |
|
|
|
;; xacf))) |
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
;; Functions for external programs |
|
|
|
|
|
|
@ -475,6 +453,7 @@ Only useful if you have not installed Beancount properly in your PATH") |
|
|
|
(start-process "termx" nil beancount-terminal-name "-e" beancount-fava-exec beancount-filename-main) |
|
|
|
(sleep-for 0.5) ; necessary to prevent an error |
|
|
|
(browse-url "127.0.0.1:5000")) |
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
;; Completions |
|
|
|
|
|
|
@ -500,8 +479,6 @@ Only useful if you have not installed Beancount properly in your PATH") |
|
|
|
"^[0-9- *]*\"\\(?1:.*?\\)\" \"\\(?2:.*?\\)\"" nil t) ; matches are in brackets |
|
|
|
(setq payees-list (cons (match-string-no-properties 1) ; get first match, generally the payee |
|
|
|
payees-list)))) |
|
|
|
; (setq payees-list (cons (match-string-no-properties 2) ; get second match, generally a description |
|
|
|
; payees-list)))) |
|
|
|
(pcomplete-uniquify-list (nreverse payees-list)))) |
|
|
|
|
|
|
|
(defun beancount-get-payee-text-in-buffer () |
|
|
@ -582,18 +559,6 @@ Only useful if you have not installed Beancount properly in your PATH") |
|
|
|
'("Beancount" |
|
|
|
["Customize Ledger Mode" (lambda () (interactive) (customize-group 'beanmode))])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; (defun beancount-get-accounts (&optional string) |
|
|
|
;; "Return list of account names with STRING infix present. |
|
|
|
;; STRING can be multiple words separated by a space." |
|
|
|
;; (let* ((accounts-string (shell-command-to-string |
|
|
|
;; (concat "bean-query -q -f csv " |
|
|
|
;; "/home/marc/Archiv/Finanzen/transactions_ingdiba.beancount " |
|
|
|
;; "'SELECT DISTINCT account ORDER BY ACCOUNT ASC'"))) |
|
|
|
;; (accounts-list (split-string accounts-string))) |
|
|
|
;; accounts-list)) |
|
|
|
|
|
|
|
(defvar beancount-accounts-cache nil |
|
|
|
"List of accounts cached for capf.") |
|
|
|
|
|
|
@ -636,14 +601,6 @@ Only useful if you have not installed Beancount properly in your PATH") |
|
|
|
(setq beancount-tags-cache (beancount-get-tags-in-buffer)) |
|
|
|
(pcomplete-uniquify-list (nreverse beancount-tags-cache)) |
|
|
|
(message "Tags updated.")) |
|
|
|
;; first test for conditional completions |
|
|
|
;; e.g. only account names when completion is after a date |
|
|
|
;; (defun beancount-company-candidates (prefix) |
|
|
|
;; "Check what PREFIX does." |
|
|
|
;; (let* (accounts (beancount-accounts-cache)) |
|
|
|
;; accounts)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;################################## |
|
|
|
;;stuff from https://github.com/debanjum/company-ledger/blob/master/company-ledger.el |
|
|
@ -680,30 +637,6 @@ Only useful if you have not installed Beancount properly in your PATH") |
|
|
|
(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))) |
|
|
|
|
|
|
|
;;NEW;;;;;;;;;;;;; |
|
|
|
;;##################################### |
|
|
|
(defvar beancount-accounts nil |
|
|
|
"A list of accounts available in buffer.") |
|
|
@ -720,8 +653,8 @@ Provide completion info based on COMMAND and ARG. IGNORED, not used." |
|
|
|
"A regular expression to match account names.") |
|
|
|
|
|
|
|
(defun beancount-collect (regexp n &optional files) |
|
|
|
"Return a unique list of REGEXP group N in the current buffer. Optionally |
|
|
|
also look at data in selected files." |
|
|
|
"Return a unique list of REGEXP group N in the current buffer. |
|
|
|
Optionally also look at data in selected FILES." |
|
|
|
(let ((pos (point))) |
|
|
|
(save-excursion |
|
|
|
(save-match-data |
|
|
@ -756,9 +689,6 @@ also look at data in selected files." |
|
|
|
(and (looking-at regexp) |
|
|
|
(>= pos (match-beginning n)) |
|
|
|
(<= pos (match-end n)))) |
|
|
|
;;##################################### |
|
|
|
|
|
|
|
;2022-12-12 ! "Ne" |
|
|
|
|
|
|
|
;;;###autoload |
|
|
|
(defun beancount-completion-at-point () |
|
|
@ -879,71 +809,6 @@ also look at data in selected files." |
|
|
|
;;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) |
|
|
|
(cl-case command |
|
|
|
(`interactive (company-begin-backend 'company-beancount)) |
|
|
|
(`prefix (and (eq major-mode 'beancount-mode) |
|
|
|
(company-grab-symbol))) |
|
|
|
(`candidates |
|
|
|
(cond |
|
|
|
;; if line ends with date and status, at max one quoted text, and an open quote, offer payees and explainations |
|
|
|
((string-match-p beancount-valid-prefix-for-payee-completion-regex (thing-at-point 'line)) |
|
|
|
(delq nil |
|
|
|
(mapcar (lambda (c) |
|
|
|
; (and (string-prefix-p (substring arg 1) c) c) |
|
|
|
(and (string-prefix-p arg c) c)) |
|
|
|
beancount-payees-cache))) |
|
|
|
;; if line starts with date, offer directives |
|
|
|
((string-match-p beancount-valid-prefix-for-directives-regex (thing-at-point 'line)) |
|
|
|
(delq nil |
|
|
|
(mapcar (lambda (c) |
|
|
|
(and (string-prefix-p arg c) c)) |
|
|
|
beancount-timestamped-directive-names))) |
|
|
|
;; if line starts with date, status and payees, offer tags |
|
|
|
((string-match-p beancount-valid-prefix-for-tag-completion-regex (thing-at-point 'line)) |
|
|
|
(delq nil |
|
|
|
(mapcar (lambda (c) |
|
|
|
(and (string-prefix-p (substring arg 1) c) c)) |
|
|
|
beancount-tags-cache))) |
|
|
|
;; if line starts with accounts and amounts, offer commodities |
|
|
|
((string-match-p (concat "^[ ]+[A-Za-z0-9-_:]+[ ]+[-]?[0-9,.]+[ ]+" beancount-currency-regexp) (thing-at-point 'line)) |
|
|
|
(delq nil |
|
|
|
(mapcar (lambda (c) |
|
|
|
(and (string-prefix-p arg c) c)) |
|
|
|
beancount-commodities-cache))) |
|
|
|
;; if line is empty, offer accounts |
|
|
|
((or (string-match-p "^\\s-+" (thing-at-point 'line)) |
|
|
|
;; 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 |
|
|
|
(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. |
|
|
|
;;TODO reverse list, newest one first |
|
|
|
((delq nil |
|
|
|
(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" |
|
|
|
"A mode for editing beancount files. |
|
|
@ -973,7 +838,5 @@ COMMAND, ARG, and IGNORED the regular meanings." |
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
(provide 'beancount) |
|
|
|
|
|
|
|
;;; beancount-mode.el ends here |
|
|
|
;;; beancount.el ends here |