refactor(beancount): simplify +beancount--open-in-browser-after-starting-fix-a

This commit is contained in:
Henrik Lissner
2025-04-30 04:00:23 -04:00
parent f8f979a581
commit ca7e226e13

View File

@ -18,16 +18,13 @@
(when (modulep! +lsp) (when (modulep! +lsp)
(add-hook 'beancount-mode-local-vars-hook #'lsp! 'append)) (add-hook 'beancount-mode-local-vars-hook #'lsp! 'append))
;; HACK: The intro message changed in newer versions of Fava, plus, the output ;; HACK: The intro message could contain ANSI color codes, causing the regexp
;; could contain ANSI codes, causing the `beancount-fava' command to not ;; in `beancount--fava-filter' to fail to match it (and thus the browser
;; open the server in the browser after the server has started. ;; isn't automatically opened after executing `beancount-fava').
;; REVIEW: PR this upstream! ;; REVIEW: PR this upstream!
(defadvice! +beancount--open-in-browser-after-starting-fix-a (_process output) (defadvice! +beancount--open-in-browser-after-starting-fix-a (fn process output)
:override #'beancount--fava-filter :around #'beancount--fava-filter
(save-match-data (funcall fn process (ansi-color-filter-apply output)))
(let ((output (ansi-color-filter-apply output)))
(when-let ((url (string-match "\\(?:Starting\\|Running\\) Fava on \\(http://.+:[0-9]+\\)\n" output)))
(browse-url (match-string 1 output))))))
(map! :map beancount-mode-map (map! :map beancount-mode-map
:m "[[" #'+beancount/previous-transaction :m "[[" #'+beancount/previous-transaction