reddit / emacs

Python-mode: English spell checking only for comments and docstrings and regular flake8 checks for the code

wWA5RnA4n2P3w2WvfHq · 2022-11-17 08:27
I'm using Emacs 27, eglot with "python-language-server[all]" and that work well. I see all flake8/pep8 violations live. But the English in my comments and docstrings are not checked. I'm not sure how I can archive that? Maybe it is to complex or not a good idea to activate flake8-code-checking and docstring-spellchecking at the same time? I would also accept a solution where I have to activate the spell checking manually. I'm not sure which one of the components are responsible here? Can eglot do something like that? OR do I have to configure the language server behind? Or is it totally in depended from the python-eglot-configuration? I'm not sure if this would help, but if you want I could post the relevant parts of my init.el here.
snichone · 2022-11-17 08:41
Would `flyspell-prog-mode` suite your needs? You can add a hook to start the mode automatically for `prog-mode` buffers. > Flyspell Prog mode works just like ordinary Flyspell mode, except that it only checks words in comments and string constants. > Flyspell mode is a minor mode that performs automatic spell-checking of the text you type as you type it. When it finds a word that it does not recognize, it highlights that word. > Note that, as Flyspell mode needs to check each word across which you move, it will slow down cursor motion and scrolling commands. It also doesn’t automatically check the text you didn’t type or move across; use `flyspell-region` or `flyspell-buffer` for that. Source – [Emacs manual (spell checking) ](https://www.gnu.org/software/emacs/manual/html_node/emacs/Spelling.html) Note, you need to install a spelling checker program, e.g., Aspell, Hunspell or Enchant, on your OS (if it's not already installed).
jumper047 · 2022-11-19 17:30
Check https://melpa.org/#/spell-fu package, for my taste its easier to made it work than flyspell and by default it only checks comments and doc strings in prog modes
wWA5RnA4n2P3w2WvfHq · 2022-11-20 15:30
Sounds interesting but I can't get it run as expected. "aspell" is installed on my system. I did in "scratch" (spell-fu-dictionary-add (spell-fu-get-ispell-dictionary "en")) In my python buffer I did "spell-fu-mode" and then nearly all words in the docstrings and comments are red underlined. But I don't know why. What can I do so far?
jumper047 · 2022-11-20 15:53
``` (use-package spell-fu :hook ((prog-mode . spell-fu-mode) (org-mode . (lambda () (setq spell-fu-faces-exclude '(org-meta-line org-link org-code)) (spell-fu-mode)))) :config (add-hook 'spell-fu-mode-hook (lambda () (spell-fu-dictionary-add (spell-fu-get-ispell-dictionary "en")) (spell-fu-dictionary-add (spell-fu-get-personal-dictionary "en-personal" "~/.emacs.d/aspell/aspell.en.pws")) (spell-fu-dictionary-add ))) ) ``` This is my config, seems like the difference is where we launching spell-fu-dictionary-add. Try to launch it inside python buffer, may be it will help.