reddit / emacs

How do I make flycheck lint the buffer only when I enter evil normal state?

wormsheep8 · 2022-03-24 22:45
e: I use flycheck with lsp-mode, btw.
tonicinhibition · 2022-03-24 23:01
I'm not coming in with a complete answer, but here's some direction. If you look at the docs for evil-mode, you can find the [hooks](https://evil.readthedocs.io/en/latest/hooks.html). Here is an example from my own config that uses hooks: (defun rewrite-the-greeks () (setq prettify-symbols-alist prettify-greek-lower) (prettify-symbols-mode t)) (add-hook 'lisp-mode-hook 'rewrite-the-greeks) Note that `'rewrite-the-greeks` could also be a lambda expression. Using `M-x` auto-completion we can search for possible functions to use: `flyspell-buffer` and when you need to clear it (on normal-mode exit or some other hook) you can use either of the following functions from `flyspell.el`: `turn-off-flyspell` `flyspell-delete-all-overlays` Those functions are not interactive, so you'll need to test them with `M-:`, or `eval-expression` I found those last two functions by searching the autocomplete list for candidates using Emac's function help (`counsel-describe-function`): `C-h f flyspell-`
wormsheep8 · 2022-03-25 00:11
This hook: ``` (use-package lsp-mode :init *(add-hook 'evil-normal-state-entry-hook 'flycheck-buffer)* (setq lsp-keymap-prefix "C-c l") (setq lsp-enable-symbol-highlighting nil) :hook (c-mode-common . lsp) :commands lsp) ``` Yields: `Symbol’s function definition is void: flycheck-buffer` E: oops I was talking about flycheck You're talking about flyspell
tonicinhibition · 2022-03-25 00:28
Oh, my mistake - I don't use Flycheck myself. The same principles should hold. You may want to check out [this solution](https://github.com/alexmurray/evil-flycheck/blob/master/evil-flycheck.el#L38) They are using a slightly different different syntax to do something similar. You might have to make subtle changes if it doesn't do exactly what you want. I can't test it on my end without downloading packages.
wormsheep8 · 2022-03-25 00:57
I've tried that but it didn't work (probably because I am a dumbass). It now works after tweaking the source code a bit. Here's what I changed: (warning: this is possibly the worst solution to this, I am a newbie to elisp) flycheck.el: ``` (defcustom flycheck-check-syntax-automatically '(save idle-change new-line mode-enabled [+++]evil-normal-state-entry) ``` ``` (defconst flycheck-hooks-alist [+++]'((evil-normal-state-entry-hook . evil-flycheck-handle-evil-normal-state-entry) (.......) ``` init.el: ``` (defun evil-flycheck-handle-evil-normal-state-entry () "Handle switching to normal state in evil." (flycheck-buffer-automatically 'evil-normal-state-entry)) ```
tonicinhibition · 2022-03-25 01:05
That looks good to me, and if it works that's great! Personally I tend to avoid modifying the source files, since that could get in the way of upgrade paths in the future. Perhaps you ran into a load-error issue? Here's an example of `use-package` that allows you to specify that evil needs to be loaded first, and then specifies custom configuration: (use-package evil-commentary :after evil :config (setq evil-commentary-mode t))