emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Allow inhibiting 'auto-save-visited-mode' on a per-buffer ba


From: Stefan Monnier
Subject: Re: [PATCH] Allow inhibiting 'auto-save-visited-mode' on a per-buffer basis.
Date: Sun, 05 Apr 2020 10:18:58 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> diff --git a/lisp/files.el b/lisp/files.el
>> index 55a0958f54..5132aa456a 100644
>> --- a/lisp/files.el
>> +++ b/lisp/files.el
>> @@ -441,6 +441,7 @@ auto-save-visited-mode
>>             #'save-some-buffers :no-prompt
>>             (lambda ()
>>               (and buffer-file-name
>> +                  auto-save-visited-mode
>>                    (not (and buffer-auto-save-file-name
>>                              auto-save-visited-file-name))))))))
>
> Is this really OK?

Depends what you mean by "this".  The above patch is definitely
OK, yes.  It's actually "standard operation procedure" for a minor mode
to double check its minor mode variable in timers and hooks ;-)

> All minor mode variables, including auto-save-visited-mode, by default
> get the "Setting this variable directly does not take effect"
> documentation string, because we want to use minor mode variables only
> for checking a mode's state and always want users to call the
> mode function.

Indeed the above implies suggestions to do:

    (add-hook 'foo-mode-hook
              (lambda () (setq-local auto-save-visited-mode nil)))

which doesn't go through such functions and is hence arguably "bad
style".  Especially it will likely encourage the use of plain `setq` on
the variable.

This part of what I meant by "...but lacks the rest of the code".
The rest would be something like

    (define-minor-mode auto-save-visited-local-mode ...)

which would do the `setq-local` internally and might take inspiration
from `electric-indent-local-mode`.


        Stefan




reply via email to

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