use-package flyspell

This commit is contained in:
larstvei 2023-06-12 00:43:36 +02:00
parent b0856a41e6
commit bff3e0b95f

View File

@ -721,33 +721,9 @@
#+end_src #+end_src
* Spelling * Spelling
** Flyspell ** Flyspell
Flyspell offers on-the-fly spell checking. We can enable flyspell for all Flyspell offers on-the-fly spell checking.
text-modes with this snippet.
#+begin_src emacs-lisp
(add-hook 'text-mode-hook 'turn-on-flyspell)
#+end_src
To use flyspell for programming there is =flyspell-prog-mode=, that only
enables spell checking for comments and strings. We can enable it for all
programming modes using the =prog-mode-hook=.
#+begin_src emacs-lisp
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
#+end_src
Tell Emacs what program is used for spell checking.
#+begin_src emacs-lisp
(setq ispell-program-name "aspell")
#+end_src
When working with several languages, we should be able to cycle through the When working with several languages, we should be able to cycle through the
languages we most frequently use. Every buffer should have a separate cycle languages we most frequently use. Every buffer should have a separate cycle
@ -762,7 +738,6 @@
ISPELL-LANGUAGES, and returns an interactive function that cycles ISPELL-LANGUAGES, and returns an interactive function that cycles
the languages in ISPELL-LANGUAGES when invoked." the languages in ISPELL-LANGUAGES when invoked."
(let ((ispell-languages (list "american" "norsk"))) (let ((ispell-languages (list "american" "norsk")))
(ispell-change-dictionary (car ispell-languages))
(lambda () (lambda ()
(interactive) (interactive)
;; Rotates the languages cycle and changes the ispell dictionary. ;; Rotates the languages cycle and changes the ispell dictionary.
@ -771,27 +746,24 @@
#+end_src #+end_src
=flyspell= signals an error if there is no spell-checking tool is installed. We enable =flyspell-mode= for all text-modes, and use =flyspell-prog-mode=
We can advice =turn-on-flyspell= and =flyspell-prog-mode= to only try to for spell checking comments and strings in all programming modes. We bind
enable =flyspell= if a spell-checking tool is available. Also we want to =C-c l= to a function returned from =cycle-languages=, giving a language
enable cycling the languages by typing =C-c l=, so we bind the function switcher for every buffer where flyspell is enabled.
returned from =cycle-languages=.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defadvice turn-on-flyspell (before check nil activate) (use-package flyspell
"Turns on flyspell only if a spell-checking tool is installed." :defer t
(when (executable-find ispell-program-name) :if (executable-find "aspell")
(local-set-key (kbd "C-c l") (cycle-languages)))) :hook ((text-mode . flyspell-mode)
(prog-mode . flyspell-prog-mode)
#+end_src (flyspell-mode . (lambda ()
(local-set-key
#+begin_src emacs-lisp (kbd "C-c l")
(cycle-languages)))))
(defadvice flyspell-prog-mode (before check nil activate) :config
"Turns on flyspell only if a spell-checking tool is installed." (ispell-change-dictionary "american" t))
(when (executable-find ispell-program-name)
(local-set-key (kbd "C-c l") (cycle-languages))))
#+end_src #+end_src