emacs-devel
[Top][All Lists]
Advanced

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

Re: Warnings about keymaps


From: Stefan Monnier
Subject: Re: Warnings about keymaps
Date: Thu, 17 Sep 2009 10:02:49 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

>> - most importantly: it doesn't solve the problem at hand which is how
>> to get rid of the other warning.
> The other warning?
>> - what's its use?  It's not like we've seen lots of bugs where people
>> use both defconst and defvar for a variable.
> It simply replaces the current "variable assignment to a constant"
> warning with a slightly more informative one, as you suggested.

Sorry, I misread your patch.  So you actually completely remove the
defvar if var was already defconst'd.  That's an attractive approach,
tho it's a bit risky, because byte-compile-const-variables only contains
variables that "may have been defconst'd", not those that "we know for
sure have been defconst'd".  E.g. try it with code such as

  (when toto
    (defconst foo bar))
  (defvar foo nil)

with your patch, you'd end up with `foo' undefined in the case where
toto is nil.  It may seem like a braindead case, but when comparing
"broken code in corner cases" vs "incorrect warning in some cases",
I prefer the incorrect warning.

>> - Finally, if the defconst+defvar is really what you want to do (as in
>> the present case where the defconst and the defvar both come from
>> macros that we may not want to change), how do you silence
>> the warning?

> The same way you silence the current one about variable assignment to
> a constant. :)

The difference is that the current one is incorrect, so the act of
silencing it needs to be done in bytecomp.el.  Whereas yours is meant to
be correct, in which case silencing it would need to be done by tweaking
the code and/or using with-no-warnings (which I profoundly disklike).

> I think it would be better to change define-derived-mode to not defvar
> the map if it is already defined;

I don't know how to do that.

> or to change easy-mode-defmap to not use defconst

That might be an acceptable workaround.  But the underlying problem will
still be there.

> (are you saying users should not add key bindings to
> log-edit-mode-map, for example?).

That's unrelated: defconst only says that the variable's binding won't
change, not that the object it is bound to is immutable.  My locally
hacked Emacs has "strong defconst" which really makes the variable
immutable, so (setq log-edit-mode-map <blabla>) signals an error, but
(define-key log-edit-mode-map [foo] 'bar) still works just fine.


        Stefan




reply via email to

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