Add `flymake-inhibit', etc.

Should make this a package.
This commit is contained in:
Case Duckworth 2021-09-09 16:36:47 -05:00
parent 78f6579c49
commit 509ac5d09f
1 changed files with 47 additions and 1 deletions

48
init.el
View File

@ -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))