bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36837: 26.2; whitespace-mode: whitespace-line-column is not set to l


From: Štěpán Němec
Subject: bug#36837: 26.2; whitespace-mode: whitespace-line-column is not set to local fill-column
Date: Fri, 02 Aug 2019 16:57:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Mon, 29 Jul 2019 11:17:56 +0200
tastytea@tastytea.de wrote:

> whitespace-mode will highlight long lines starting at 70 characters
> instead of what fill-column is set to, if whitespace-line-column is set
> to nil.
>
> To reproduce:
>
> 1. Create the file test.cfg with this as the first line:
>
> # -*- fill-column: 200 -*-
>
> 2. Run emacs -Q
>
> 3. Execute the following commands:
>
> (setq whitespace-line-column nil)
> (add-hook 'conf-mode-hook
>           (lambda () (whitespace-mode)))
>
> 4. Open test.cfg and type more than 70 characters
>
> After disabling whitespace-mode and enabling it again,
> whitespace-line-column is set correctly to 200.

Yes, unfortunately, file-local variables are only setup (via
`hack-local-variables') _after_ the mode hooks are run (cf.
`run-mode-hooks'), so `whitespace-color-on' still sees the original
`fill-column' the first time.

Intuitively this order seems backwards to me, but I assume there must be
a (good?) reason? I'd like to hear it, in any case.

You can work around this by hacking^W having `hack-local-variables' also
run in your hook function:

 (add-hook 'conf-mode-hook 
           (lambda () (hack-local-variables) (whitespace-mode))

BTW, it's usually better (e.g. for debugging purposes,
removal/modification etc.) not to put lambdas into hooks. If you only
need a particular mode, i.e. a single function/command, the lambda is
redundant anyway:

  (add-hook 'some-hook #'some-mode)

If you need more I suggest defining a named function.

HTH,

-- 
Štěpán





reply via email to

[Prev in Thread] Current Thread [Next in Thread]