On Mon, Jan 14, 2008 at 06:21:29PM +1100, Tim Connors wrote:
> 
> Bugger.  I was premature.  When I do the following:
> (autoload 'flyspell-mode-on "flyspell" "On-the-fly ispell." t)
> (add-hook 'TeX-mode-hook     'flyspell-mode-on) ; encompases LaTeX-mode as 
> well
> (add-hook 'text-mode-hook    'flyspell-mode-on)
> (add-hook 'html-mode-hook    'flyspell-mode-on)
> (add-hook 'mail-hook         'flyspell-mode-on)
> (add-hook 'message-hook      'flyspell-mode-on)
> (add-hook 'flyspell-mode-hook 'flyspell-buffer)
> 
> (I don't simply use 'flyspell-mode because it is a toggle, and some modes
> encompass other modes and you end up with flyspell being turned on then
> off immediately.  It's easier for my brain if I add the hook to the modes
> I want explicitly rather than trying to work out which mode is a parent of
> which other mode)

Note that direct use of flyspell-mode-on is discouraged (I do not know why)
in flyspell-mode-on docstring. You can use flyspell mode as e.g.

(add-hook 'sgml-mode-hook (lambda () (flyspell-mode 1)))
(add-hook 'text-mode-hook (lambda () (flyspell-mode 1)))
...
 
> I get the flyspell-buffer being executed in the hook, which made it look
> like it was working.  But if I type nonsense, the bad spelling doesn't get
> picked up - so it looks like the mode isn't turned on even though it had
> to be for the flyspell-mode-hook hook to be executed.

Strange, is working here for both xemacs and emacs once I make sure (in
.emacs) that the same right language is selected for both.

(flyspell-buffer) seems run before 'Local Variables' section is parsed,
so it may be run with a language while flyspell-mode is later restarted
with the real language selected in 'Local Variables'. I have tested this
with a snippet of czech text I have here from another bug report, having
'czech' selected in 'Local variables' and american in ~/.emacs. When
enabling flyspell-mode, flyspell-buffer is run in american, and so overlays
only show the misspellins for the american dict, but later local variables
section is read and flyspell knows the buffer is in czech, so flyspell-mode
is turned to czech and when I click mouse over the misspellings they get
highligted. The same if I write nonsensic text.

The reason for this seems that you are using the wrong hook, there is no
warranty that when flyspell-mode is enabled that way 'Local Variables' are
parsed. What you want may be something like

;; ------------- 8< ---------------------
(add-hook 'find-file-hooks
          (lambda ()
            (when (and (boundp 'flyspell-mode)
                       flyspell-mode)
              (flyspell-buffer))))
;; ------------- 8< ---------------------

find-file-hooks docstring:
List of functions to be called after a buffer is loaded from a file. The
buffer's local variables (if any) will have been processed before the
functions are called.

A side note here about the origin of the bug report. When I was looking at
other code trying to guess which is the right hook for this (I would have
expected something like non-existant (after-file-load-hook) I noticed that
lilypond mode explicitly has

(make-local-hook 'post-command-hook) ; XEmacs requires

I guess that this is because xemacs does not consider this hook
buffer-local. Since that may affect other things I think I will stay with
the original fix, but at least I know why things happened, flyspell.el kept
flyspell-changes global (and surely made other things) to work around this,
but I think things are now cleaner.

There are however some changes in new flyspell-mode-hook behavior different from
before. These are things I noticed checking your code with the new
flyspell.el

* flyspell-buffer is run at both enabling and disabling flyspell-mode. No
  simple way of getting rid of the highlights. Because of the previous issue,
  flyspell-buffer is called during initialization at least 3 times, a nightmare
  if you are dealing with a large buffer

This should not happen with the code I propose. The reason for this is that
define-minor-mode enables three hooks for flyspell-mode, flyspell-mode-hook
(to be run when the mode is either enabled or disabled), as well as
flyspell-mode-{on,off}-hook, while previously flyspell-mode-hook was run
only when enabling the mode. New behavior is probably closer to the behavior
of other modes, but if this is to be left, there is an extra explicit call
in flyspell-mode-on that should be removed. I would like to ask emacs-devel
people about this.

> If I invoke 
> flyspell-mode explicitly, it then works as expected, and then
> flyspell-mode again will turn off the mode as expected.  If I do use
> 'flyspell-mode as the hook, then it works, but I would have to go through
> and change my functions to remove duplicate calls.  Since this works in
> the other flyspell version I have, I presume it is *supposed* to work.
> Can you see what I am doing wrong, or alternatively, what bug I am
> triggering?

In the first case, 'Local Variables' is already parsed and so, things are
different and work. Note that I have the same above problematic behavior in
the czech snippet with a pre 0.90 dictionaries-common, whose flyspell.el
is based on Manuel Serrano version (based in 1.7i). What does not happen
here is the multiple flyspell-mode-hook run, but the other problem is also
present here for former flyspell.el, and I do not see in Manuel changelog
any further change related to this. What is exactly working for you? Please
include info about ~/.emacs and 'Local Variables' ispell-local-dictionary
values if any.

-- 
Agustin



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to