2

I often use scratch buffers, when I want to take a closer look at some code. However I can't enable flyspell in scratch buffers. Is there a way to also use it when not editing a file ?

EDIT:

I can't enable flyspell-mode while the buffer isn't saved to a file. When I use it in a scratch buffer I only get this message in the echo area Flyspell mode disabled in current buffer. No matter how often I try to activate it.

EDIT:

Thanks to lawlist I found the problem. It seems, that I ignored flyspell-lazy-mode consequently while I was looking for the problem.

This package also forces flyspell-mode off completely for certain buffers.

"Certain buffers" seems to include scratch buffers, but not buffers that are attached to a file. lawlist was right so I reward his correct answer and also his patience.

  • (add-hook 'python-mode-hook 'flyspell-mode) As mentioned in the comment to my answer below, Emacs permits enabling flyspell-mode in a non-file-visiting-buffer -- there is no need to ever save the buffer to use flyspell-mode (unless of course you want to save the buffer). If you cannot enable flyspell-mode in a non-file-visiting-buffer, then recursively bisect your user-configuration by commenting stuff out and restarting Emacs until you find the culprit for the non-default behavior. No one will be able to guess what is in your user-configuration that may be causing the need to save. – lawlist Nov 15 '16 at 17:00
  • The following is an alternative approach that does not require using a major-mode hook. (defun python-scratch () (interactive) (switch-to-buffer (get-buffer-create "*python-scratch*")) (python-mode) (flyspell-mode 1)) This example works with no user-configuration whatsoever except (setq ispell-program-name "/path/to/your/spelling/program/such/as/aspell"). – lawlist Nov 15 '16 at 18:07
2

The default major-mode for the *Scratch* buffer is lisp-interaction-mode. In this example, we use the emacs-lisp-mode-hook -- lisp-interaction-mode is derived from emacs-lisp-mode.

(add-hook 'emacs-lisp-mode-hook 'flyspell-mode)

Another method is to use the lisp-interaction-mode-hook:

(add-hook 'lisp-interaction-mode-hook 'flyspell-mode)

Another method is to call flyspell-mode manually with: M-x flyspell-mode

  • This does not work with flyspell-mode. I can't even enable it manually. But as soon as I have saved the buffer it works. – bertfred Nov 14 '16 at 17:56
  • Flyspell works out-of-the-box on a non-file-visiting-buffer such as *Scratch*. To test this theory, open Emacs 25 without any user configuration whatsoever -- e.g., emacs -q. Go to the *Scratch* buffer. Then, type M-x eval-expression RET (setq ispell-program-name "/path/to/your/spelling/program/such/as/aspell") RET. Then type M-x flyspell-mode and have fun. If your current user-configuration is causing a conflict, then you may wish to recursively bisect it by commenting stuff out until you find the problem. – lawlist Nov 14 '16 at 18:10
  • When you see a message "Flyspell mode disabled in current buffer", that means it was already enabled (i.e., it was already running) and you disabled it. One way to check whether flyspell-mode is running, is to type M-x describe-mode and see the listing in the *Help* buffer (at the very top) of all minor modes that are active. – lawlist Nov 14 '16 at 18:20
  • No because I would also see that it is enabled after I disabled it in the echo area. It only shows the message that it is disabled. But thanks for the hint with emacs -q. I removed every line of config related to flyspell and it still won't work. And it seems a little odd to me, that it works when I save the buffer ? – bertfred Nov 14 '16 at 18:28
  • Removing whatever you believe is relevant from your user-configuration is not the best way to troubleshoot whether something in your user-configuration is causing problems that differ from the default behavior of Emacs 25. To truly test how Emacs 25 behaves by default, you should try it without any user-configuration whatsoever -- i.e., nothing, zip, zero, zilch, nada. :) If you cannot achieve the results described in the second comment, then your Emacs installation is likely broken somehow. – lawlist Nov 14 '16 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.