fix(beancount): beancount-fava failing to open browser

This commit is contained in:
Henrik Lissner 2024-07-18 20:56:10 -04:00
parent 3391cb76bb
commit 90bbd7101a
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -15,6 +15,17 @@
(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
;; could contain ANSI codes, causing the `beancount-fava' command to not
;; open the server in the browser after the server has started.
;; REVIEW: PR this uptsream!
(defadvice! +beancount--open-in-browser-after-starting-fix-a (_process output)
:override #'beancount--fava-filter
(save-match-data
(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
"TAB" (cmds! (and outline-minor-mode (outline-on-heading-p)) "TAB" (cmds! (and outline-minor-mode (outline-on-heading-p))
#'beancount-outline-cycle #'beancount-outline-cycle