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

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

Re: setq and setq-default


From: robert . thorpe
Subject: Re: setq and setq-default
Date: 14 Sep 2006 11:42:04 -0700
User-agent: G2/1.0

jronald wrote:
> I think setq-default set a global variable, and setq set a variable in its
> scope,

Yes.

> which may override the global one.
> If so, can setq set a global variable when it is in the global scope.

If there is no local variable called "foo" then you will set the global
value of foo by doing:-
(setq foo 56)
If there is a local var with that name then setq will set that.

If you were able to write elisp in the global scope then setq would
always update the global variable.  However all emacs code exists in
the context of some mode.

> If tab-width and default-tab-width both exsists, what is the priority emacs
> treats them?

They have no priority, both update the same variable.  If you do
(setq-default tab-width 29) then open a new buffer tabs will be 29
spaces.  If you do (setq default-tab-width 10) and open some more new
buffers tabs will be 10 spaces in those.

Emacs is rather like an object orientated system.  To a C++ person it's
best described in those terms:

Fundamental-mode is the basic editing class. Things like CC-mode are
classes derived from fundamental-mode. C-mode and Java-mode are classes
derived in turn from CC-mode.  Each open buffer is an instance of some
class/mode.

The buffer local variables are fields local to each object instance (ie
buffer).  Global variables, like those defined with setq-default are
the same as "class variables".

Things like mode-hooks are rather like virtual methods for use by the
user.



reply via email to

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