refactor(beancount): move autoloads to sub-directory

This commit is contained in:
Henrik Lissner
2025-05-22 16:21:23 +02:00
parent 5d13d6ce99
commit b173fedaff
2 changed files with 64 additions and 59 deletions

View File

@ -0,0 +1,62 @@
;;; lang/beancount/autoload/advice.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +beancount--flymake-bean-check--run-a (report-fn &rest _ignored)
(unless (executable-find flymake-bean-check-executable)
(error "The executable %s doesn't exist. See `flymake-bean-check-executable'"
flymake-bean-check-executable))
(when (and flymake-bean-check-process
(process-live-p flymake-bean-check-process))
(kill-process flymake-bean-check-process))
(let* ((source (current-buffer))
(buffer (generate-new-buffer "*flymake-bean-check*"))
(cache-file (flymake-bean-check-cache-filename (buffer-file-name))))
(setq flymake-bean-check-process
(make-process :buffer buffer
:name "flymake-bean-check"
:noquery t
:connection-type 'pipe
:command (list flymake-bean-check-executable
"/dev/stdin"
"--cache-filename" cache-file)
:sentinel
(lambda (proc _event)
(when (memq (process-status proc) '(exit signal))
(unwind-protect
(with-current-buffer buffer
(goto-char (point-min))
(let (result)
(while (re-search-forward flymake-bean-check-location-regexp
nil t)
(pcase-let*
((message (match-string 2))
(`(,begin . ,end) (flymake-diag-region
source
(string-to-number (match-string 1)))))
(push (flymake-make-diagnostic source begin end
:error message)
result)))
(funcall report-fn (nreverse result))))
(kill-buffer buffer))))))
(process-send-string
flymake-bean-check-process
(save-restriction
(widen)
(with-temp-buffer
(save-excursion (insert-buffer-substring source))
(while (re-search-forward (rx bol
(or (seq (= 4 num) "-" (= 2 num) "-" (= 2 num) (+ " ")
"document" (+ " ")
(+ (or alnum ":" "_" "-")))
"include"
(seq "option" (+ " ") "\"documents\""))
(+ " ") "\""
(group (+ (not "\""))))
nil t)
(replace-match (expand-file-name
(match-string-no-properties 1))
t t nil 1))
(buffer-substring-no-properties (point-min) (point-max)))))
(process-send-eof flymake-bean-check-process)))
;;; advice.el ends here

View File

@ -1,4 +1,4 @@
;;; lang/beancount/autoload.el -*- lexical-binding: t; -*-
;;; lang/beancount/autoload/beancount.el -*- lexical-binding: t; -*-
;;
;;; Helpers
@ -240,61 +240,4 @@ Return non-nil if successful."
"\\|" beancount-transaction-regexp)))
('search-failed (goto-char pos) nil))))
;;;###autoload
(defun +beancount--flymake-bean-check--run-a (report-fn &rest _ignored)
(unless (executable-find flymake-bean-check-executable)
(error "The executable %s doesn't exist. See `flymake-bean-check-executable'"
flymake-bean-check-executable))
(when (and flymake-bean-check-process
(process-live-p flymake-bean-check-process))
(kill-process flymake-bean-check-process))
(let* ((source (current-buffer))
(buffer (generate-new-buffer "*flymake-bean-check*"))
(cache-file (flymake-bean-check-cache-filename (buffer-file-name))))
(setq flymake-bean-check-process
(make-process :buffer buffer
:name "flymake-bean-check"
:noquery t
:connection-type 'pipe
:command (list flymake-bean-check-executable
"/dev/stdin"
"--cache-filename" cache-file)
:sentinel
(lambda (proc _event)
(when (memq (process-status proc) '(exit signal))
(unwind-protect
(with-current-buffer buffer
(goto-char (point-min))
(let (result)
(while (re-search-forward flymake-bean-check-location-regexp
nil t)
(pcase-let*
((message (match-string 2))
(`(,begin . ,end) (flymake-diag-region
source
(string-to-number (match-string 1)))))
(push (flymake-make-diagnostic source begin end
:error message)
result)))
(funcall report-fn (nreverse result))))
(kill-buffer buffer))))))
(process-send-string
flymake-bean-check-process
(save-restriction
(widen)
(with-temp-buffer
(save-excursion (insert-buffer-substring source))
(while (re-search-forward (rx bol
(or (seq (= 4 num) "-" (= 2 num) "-" (= 2 num) (+ " ")
"document" (+ " ")
(+ (or alnum ":" "_" "-")))
"include"
(seq "option" (+ " ") "\"documents\""))
(+ " ") "\""
(group (+ (not "\""))))
nil t)
(replace-match (expand-file-name
(match-string-no-properties 1))
t t nil 1))
(buffer-substring-no-properties (point-min) (point-max)))))
(process-send-eof flymake-bean-check-process)))
;;; beancount.el ends here