Subject: Re: bug#4366: 23.1; Can't turn off visual-line-mode via html-mode-hook

From: Lennart Borgman <[email-masked]>
Date: Fri, 8 Jan 2010 08:04:34 +0100

On Fri, Jan 8, 2010 at 5:12 AM, Juanma Barranquero <[email-masked]> wrote:
> On Mon, Sep 7, 2009 at 16:14, Allan Gottlieb <[email-masked]> wrote:
>
>> Start emacs -Q
>> (load-file "/tmp/fun.el")
>> (global-visual-line-mode)
>> (add-hook 'html-mode-hook 'visual-off-fill-on)
>> (find-file "/tmp/x.html")   ; non-existent file
>>
>> mode line shows fill as expected, but also shows wrap, the bug.
>>
>> However, if one does instead
>>
>> Start emacs -Q
>> (load-file "/tmp/fun.el")
>> (global-visual-line-mode)
>> (find-file "/tmp/x.html")   ; non-existent file
>> (visual-off-fill-on)
>>
>> then all is well (mode line shows fill and not wrap).
>
> That is not a bug. When you do (global-visual-line-mode)  [which
> should better be (global-visual-line-mode 1), BTW], the function adds
> code to several hooks to check for new buffers (find-file-hook, etc.).
>
> In your first case, the global mode is active (so the hooks are
> active); when you run find-file, it creates the buffer, runs
> html-mode-hook (disabling visual-line-mode), and finally a hook is run
> which activates the mode.
>
> In the second case, you activate the global mode, run find-file (and
> the hooks check that visual mode is active, so do nothing), and
> finally run visual-off-fill-on, deactivating the visual-line mode.
>
> If you want to deactivate the mode automatically after find-file,
> there are several ways, like an `after' advice for find-file, or
> adding code to the relevant hooks, etc.

Hm, maybe someone wants to make a picture that quickly describes the
order of the hooks. That would be useful IMO.