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

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

Re: don't understand setq-default


From: Thibaut Verron
Subject: Re: don't understand setq-default
Date: Mon, 19 Apr 2021 14:49:02 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

On 2021-04-19 5:06 a.m., Emanuel Berg via Users list for the GNU Emacs text editor wrote:
So the pecking order is:
    local var
    global var
    local default
    global default

I'm not sure if that's a good way to look at it.

A global variable has a (global) value. You can give it a buffer-local value in a specific buffer (with make-local-variable or setq-local), in which case what you get is another variable with the same name, which is buffer local. The buffer does not see the global variable anymore. It doesn't have a default value, but its initial value is that of the global variable.

On the other hand, a variable which is buffer-local-when-set is essentially always buffer-local. In that case, it has a default value (which is global) and possibly a buffer-local value. For those variables, setq is the same as setq-local: it creates a buffer-local variable if one does not exist, and sets the buffer-local value.

If you really want to think of it in terms of precedence, it would be local value > default value > global value. But I can't really imagine a situation where a local variable would have the same name as a global variable and a default value different from the global value.

So I find it more natural to think of it as two different situations:

- for a global variable which you made local in some buffer, the precedence is local value > global value;

- for a buffer-local-when-set variable, the precedence is (local) value > (global) default value.






reply via email to

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