mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
feat(beancount): support lines only read by linter
Adds support for meta lines that only the flymake linter will see. These are lines prefixed by any number of semicolons followed by a hash then space. E.g. ;# include "../config.beancount" ;# 2025-01-01 pad Assets:Bank Equity:Opening-Balances This is useful for silencing the linter in multi-file beancount projects rather than suffer the usual deluge of multiple-include errors and redundancies.
This commit is contained in:
@ -44,7 +44,11 @@
|
|||||||
(widen)
|
(widen)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(save-excursion (insert-buffer-substring source))
|
(save-excursion (insert-buffer-substring source))
|
||||||
(while (re-search-forward (rx bol
|
(save-excursion
|
||||||
|
(while (re-search-forward "^;+# " nil t)
|
||||||
|
(replace-match "" t t)))
|
||||||
|
(while (re-search-forward
|
||||||
|
(rx bol
|
||||||
(or (seq (= 4 num) "-" (= 2 num) "-" (= 2 num) (+ " ")
|
(or (seq (= 4 num) "-" (= 2 num) "-" (= 2 num) (+ " ")
|
||||||
"document" (+ " ")
|
"document" (+ " ")
|
||||||
(+ (or alnum ":" "_" "-")))
|
(+ (or alnum ":" "_" "-")))
|
||||||
@ -53,9 +57,10 @@
|
|||||||
(+ " ") "\""
|
(+ " ") "\""
|
||||||
(group (+ (not "\""))))
|
(group (+ (not "\""))))
|
||||||
nil t)
|
nil t)
|
||||||
|
(unless (file-name-absolute-p (match-string-no-properties 1))
|
||||||
(replace-match (expand-file-name
|
(replace-match (expand-file-name
|
||||||
(match-string-no-properties 1))
|
(match-string-no-properties 1))
|
||||||
t t nil 1))
|
t t nil 1)))
|
||||||
(buffer-substring-no-properties (point-min) (point-max)))))
|
(buffer-substring-no-properties (point-min) (point-max)))))
|
||||||
(process-send-eof flymake-bean-check-process)))
|
(process-send-eof flymake-bean-check-process)))
|
||||||
|
|
||||||
|
@ -27,10 +27,24 @@
|
|||||||
:around #'beancount--fava-filter
|
:around #'beancount--fava-filter
|
||||||
(funcall fn process (ansi-color-filter-apply output)))
|
(funcall fn process (ansi-color-filter-apply output)))
|
||||||
|
|
||||||
;; HACK: Widens the buffer so flymake never operates on partial buffer
|
;; HACK: This makes a couple adjustments to beancount-mode's flymake linter:
|
||||||
;; contents. Also replaces any relative file paths in include and document
|
;;
|
||||||
;; directives with an absolute path, so bean-check doesn't throw false
|
;; 1. Widens the buffer so bean-check can see the full buffer and won't
|
||||||
;; positives due to flymake-bean's implementation.
|
;; complain about missing context.
|
||||||
|
;; 2. Replaces any relative file paths in include and document directives
|
||||||
|
;; with an absolute path, so bean-check doesn't throw false positives
|
||||||
|
;; about missing files relative to /dev (because flymake-bean is piping
|
||||||
|
;; context to /dev/stdin).
|
||||||
|
;; 3. Adds support for meta lines that only the flymake linter will see.
|
||||||
|
;; These are lines prefixed by any number of semicolons followed by a hash
|
||||||
|
;; then space. E.g.
|
||||||
|
;;
|
||||||
|
;; ;# include "../config.beancount"
|
||||||
|
;; ;# 2025-01-01 pad Assets:Bank Equity:Opening-Balances
|
||||||
|
;;
|
||||||
|
;; Used to silence the linter in multi-file beancount projects without
|
||||||
|
;; dealing with multiple-include errors and redundancies.
|
||||||
|
;; REVIEW: PR features 1 and 2 upstream! 3 needs discussing.
|
||||||
(advice-add #'flymake-bean-check--run :override #'+beancount--flymake-bean-check--run-a)
|
(advice-add #'flymake-bean-check--run :override #'+beancount--flymake-bean-check--run-a)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user