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

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

RE: [External] : The operation of default-value


From: Drew Adams
Subject: RE: [External] : The operation of default-value
Date: Fri, 2 Dec 2022 02:49:04 +0000

> > I think node `Creating Buffer-Local' explains this.
> >
> > If you don't create/set a buffer-local value in
> > buffer A for a variable then its global, "default"
> > value applies in buffer A. It's as simple as that.
> 
> Meaning that a package can change the buffer-local variable,
> with the default-value being different.

A package, or anything else, can set a buffer-local
value, yes.

> Thusly, the variable used in the buffer is either
> the default value when the local
> value is nil, or the local value when they differ.

You can think of it being a different variable, yes.
Or you can think of it as being the same variable,
with both (1) a default value and (2) a buffer-local
value; that is, with two kinds of _bindings_.  The
doc generally speaks of it in this second way:

  “buffer-local” bindings, which apply only in one
   buffer.  Having different values for a variable
   in different buffers

But it also talks about "buffer-local variables" (not
just buffer-local variable bindings):

   A buffer-local variable has a buffer-local binding
   associated with a particular buffer.

"Buffer-local variable" refers to the buffer-local
binding of a variable.

`setq-local' sets the buffer-local value for the
current buffer.  So does `setq', if the variable
has already been made buffer-local in the buffer.

`make-local-variable' makes a variable's value be
buffer-local in the current buffer.
`make-variable-buffer-local' makes a variable always
be buffer-local, in every buffer.

If you look at the definition of `setq-local' you'll
see that it's just this, since `make-local-variable'
conveniently returns the variable (symbol).

  (set (make-local-variable 'VARIABLE VALUE))

> Meaning that I cannot rely completely on default-value,
> because the local value might be set up differently.

As usual, your meaning isn't clear.  Specify what
you mean by "rely completely on".

Even when a variable has a buffer-local value, you
can always access -- get or set -- its default value.
Functions `default-value' and `setq-default' do that,
respectively.

If this explanation helps, I suggest you reread the
doc that covers this subject.  With the added
understanding you may get more out of it on a second
reading.  If this didn't help, hopefully someone else
can help better.  But you really owe it to yourself,
as well as those who try to help you, to make clearer
what you're asking.

reply via email to

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