doomemacs/modules/lang/beancount/config.el

52 lines
2 KiB
EmacsLisp
Raw Normal View History

2021-04-13 20:09:08 -04:00
;;; lang/beancount/config.el -*- lexical-binding: t; -*-
(use-package! beancount
:mode ("\\.beancount\\'" . beancount-mode)
:hook (beancount-mode . outline-minor-mode)
2021-04-13 20:09:08 -04:00
:init
;; REVIEW Remove once domtronn/all-the-icons.el#272 is merged
2021-04-13 20:09:08 -04:00
(after! all-the-icons
(add-to-list 'all-the-icons-icon-alist
'("\\.beancount\\'" all-the-icons-material "attach_money" :face all-the-icons-lblue))
(add-to-list 'all-the-icons-mode-icon-alist
'(beancount-mode all-the-icons-material "attach_money" :face all-the-icons-lblue)))
2021-04-13 20:09:08 -04:00
:config
(setq beancount-electric-currency t)
2021-04-13 20:09:08 -04:00
(when (featurep! +lsp)
(add-hook 'beancount-mode-local-vars-hook #'lsp!))
(map! :map beancount-mode-map
"TAB" (cmds! (and outline-minor-mode (outline-on-heading-p))
#'beancount-outline-cycle
#'indent-according-to-mode)
2021-04-13 20:09:08 -04:00
:localleader
"b" #'+beancount/balance
"c" #'beancount-check
"l" #'beancount-linked
"q" #'beancount-query
"x" #'beancount-context
(:prefix ("i" . "insert")
"a" #'beancount-insert-account
"p" #'beancount-insert-prices
"d" #'beancount-insert-date))
(defadvice! +beancount--fix-account-currency-a (account)
"Fixes `beancount-electric-currency', which could never find the currency
for the current account. Also allows it to fall back to the operating_currency."
:override #'beancount--account-currency
(save-excursion
(goto-char (point-min))
(when (or (re-search-forward
(concat "^" beancount-date-regexp " +open"
"\\s-+" (regexp-quote account)
"\\s-+\\(" beancount-currency-regexp "\\)\\>")
nil t)
(re-search-forward
(concat "^option\\s-+\"operating_currency\"\\s-+\"\\("
beancount-currency-regexp
"\\)\"")
nil t))
(match-string-no-properties 1)))))