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

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

Re: Why didn't setq work here?


From: Tim X
Subject: Re: Why didn't setq work here?
Date: Sat, 08 Jan 2011 09:50:02 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Eric Lilja <mindcooler@gmail.com> writes:

> On 2011-01-07 15:26, Tassilo Horn wrote:
>> Eric Lilja<mindcooler@gmail.com>  writes:
>>
>>> I have one final question though. fill-column does seem to be a
>>> variable.
>>
>> It is.
>>
>>> It can be described using C-h v and set using M-x
>>> set-variable. However, if I replace (set-fill-column 76) with (setq
>>> fill-column 76) the variable value is never changed (and no byte
>>> compiler warning btw).
>>
>> I presume, your observation is false.  In fact, `set-fill-column' does
>> nothing except reading its argument and then doing (setq fill-column
>> arg) itself.
>>
>> Bye,
>> Tassilo
>>
>>
>>
>
> Thanks for your reply Mr Horn. Either my mind is playing tricks on me or there
> is some stochastic error here which makes setq sometimes not stick. I tried it
> ten times in a row and one time it claimed fill-column was at the default
> value. Anyway, I documented my .emacs like the following and I now consider
> this case closed. I learned quite a bit about configuring emacs in this little
> thread so I am happy! I will look out for set-fill-column not "sticking" as it
> should if my brain was indeed not fooling me.
>

Something to be aware of is that emacs has what are called buffer local
variables, that behave a little differently from normal global
variables. 

Essentially, a buffer will use the global value for a buffer local
variable until that variable is modified/changed. From that point
onwards, the buffer will have its own copy of that variable with a new
value and will use that value instead of the global value. 

What this means in practice is that the value you see for a buffer local
variable may be different depending on what buffer you are in when you
examine the value. So, if you are changing the value of fill-column,
which is a buffer local variable, in a specific mode via a mode hook,
you need to make sure you are in a buffer of that mode before you look
at the value of fill-column to see what it is now set to. This could
possibly explain why you observed what appeared to be inconsistent
behavior. Note also that if you use a function to set a buffer local
variable, you need to ensure it is associated with the appropriate
buffer, either via a mode hook or by switching to that buffer and doing
it via the interactive form of set variable. 

HTH

Tim

P.S. Newer versions of emacs come with "An Introduction to Emacs Lisp"
by Robert J. Chassell (normally in info format). This is an excellent
starting point on emacs lisp and is not too taxing - very gentle in
fact. You can also get it on-line via the FSF website. I would strongly
recommend a quick read. It will clarify some of the terminology and key
concepts, saving you lots of time in the long run. 




-- 
tcross (at) rapttech dot com dot au


reply via email to

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