From 509ac5d09f00df1fba3429af732626f218508e1f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 9 Sep 2021 16:36:47 -0500 Subject: Add `flymake-inhibit', etc. Should make this a package. --- init.el | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'init.el') diff --git a/init.el b/init.el index b17b21a..ab2e693 100644 --- a/init.el +++ b/init.el @@ -937,7 +937,53 @@ successive invocations." "C-c l v" #'find-variable)) (setup flymake - (:hook-into prog-mode) + + (defvar flymake-inhibit-major-modes nil + "Which major-modes NOT to enable `flymake' in.") + + (defvar flymake-inhibit-file-name-regexps '("init\\.el\\'" + "early-init\\.el\\'") + "List of file regexps NOT to enable `flymake' in.") + + (defvar flymake-inhibit-buffer-name-regexps (list (rx "*scratch*")) + "List of buffer-name regexps NOT to enable `flymake' in.") + + (defun list-string-match-p (string regexp-list) + "Return t if at least one regex in RETGEXP-LIST matches STRING, else nil." + (when string ; if STRING is nil, return nil. + (catch 'found + (dolist (regexp regexp-list) + (when (string-match regexp string) + (throw 'found t)))))) + + (defun flymake-unless () + "Turn on `flymake-mode', UNLESS it's inhibited. +There are three methods to inhibit flymake in a file. From most +specific to most general, they are these: + +- `flymake-inhibit': a file-local-variable + +- `flymake-inhibit-buffer-name-regexps': a list of regexps to + match the buffer name against. If one of them matches, inhibit + `flymake-mode'. + +- `flymake-inhibit-file-name-regexps': a list of regexps to match + the filename against. If one of them matches, inhibit + `flymake-mode'. + +- `flymake-inhibit-major-modes': a list of major-modes in which + to inhibit `flymake-mode'. Really only useful if you want to + generally add `flymake-mode' to `prog-mode-hook'." + (unless (or (bound-and-true-p flymake-inhibit) ; file-local variable + (list-string-match-p (buffer-name) + flymake-inhibit-buffer-name-regexps) + (list-string-match-p (buffer-file-name) + flymake-inhibit-file-name-regexps) + (apply #'derived-mode-p flymake-inhibit-major-modes)) + (flymake-mode-on))) + + (add-hook 'prog-mode-hook #'flymake-unless) + (:bind "M-n" #'flymake-goto-next-error "M-p" #'flymake-goto-prev-error)) -- cgit 1.4.1-21-gabe81