unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* don't understand setq-default
@ 2021-04-18 11:40 Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 13:02 ` Omar Polo
  2021-04-18 21:55 ` don't understand setq-default Jean Louis
  0 siblings, 2 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-18 11:40 UTC (permalink / raw)
  To: help-gnu-emacs

I don't understand `setq-default', maybe I never did, unsure.

The docstring isn't good, it only describes how it will
happens which is intuitive at that (well, that's good that
it) but not how and why it is used.

You assign a variable I understand

  ultra-hd = 2160

ikr? ultra-hd is 2160!

but full-hd is assigned the default value 1080

  full-hd d= 1080

what does that mean, except for the obvious that d stands for
"diversion"?

the only thing I can make up, is that if the common-sense
variable is unset, it falls back to 1080?

but then where is this value stored?
( actual . default ) won't work
(or actual default)  cool but also won't work
property?

surely you don't have to look for it explicitly?

built-in in some really clever way (really clever =
everything you don't understand. stupid = everything you
already know. and right in between? number 1)

Here is the docstring, it gives the impression everyone
already knows about it. And, if so, I have to give it to it,
probably it makes a whole lot more sense, reight?

(setq-default [VAR VALUE]...)

  Probably introduced at or before Emacs version 18.

Set the default value of variable VAR to VALUE.
VAR, the variable name, is literal (not evaluated);
VALUE is an expression: it is evaluated and its value returned.
The default value of a variable is seen in buffers
that do not have their own values for the variable.

More generally, you can use multiple variables and values, as in
  (setq-default VAR VALUE VAR VALUE...)
This sets each VAR’s default value to the corresponding VALUE.
The VALUE for the Nth VAR can refer to the new default values
of previous VARs.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 11:40 don't understand setq-default Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-18 13:02 ` Omar Polo
  2021-04-18 13:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 21:55 ` don't understand setq-default Jean Louis
  1 sibling, 1 reply; 23+ messages in thread
From: Omar Polo @ 2021-04-18 13:02 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

> I don't understand `setq-default', maybe I never did, unsure.
>
> The docstring isn't good, it only describes how it will
> happens which is intuitive at that (well, that's good that
> it) but not how and why it is used.
>
> [...]

buffer can have local version of some variables.  In addition, some
variables automatically becomes buffer-local when set (like
`indent-tabs-mode' for instance.)

The docstring seems pretty clear to me:

> [...]
>
> (setq-default [VAR VALUE]...)
>
>   Probably introduced at or before Emacs version 18.
>
> Set the default value of variable VAR to VALUE.
> VAR, the variable name, is literal (not evaluated);
> VALUE is an expression: it is evaluated and its value returned.
> **The default value of a variable is seen in buffers
> that do not have their own values for the variable.**

(emphasis mine)

So the question becomes: "when can a buffer have a non-default value for a
variable?"

(info "(elisp) Buffer-Local Variables") should have more information on
the matter

> [...]



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 13:02 ` Omar Polo
@ 2021-04-18 13:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 13:40     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-18 13:39 UTC (permalink / raw)
  To: help-gnu-emacs

Omar Polo wrote:

> The docstring seems pretty clear to me:
>
>> [...]
>>
>> (setq-default [VAR VALUE]...)
>>
>>   Probably introduced at or before Emacs version 18.
>>
>> Set the default value of variable VAR to VALUE.
>> VAR, the variable name, is literal (not evaluated);
>> VALUE is an expression: it is evaluated and its value returned.
>> **The default value of a variable is seen in buffers
>> that do not have their own values for the variable.**

You are right, didn't even see that, had to check but it was
indeed there :)

OK, that explains it, buffer local values, I can't even keep
track of the buffers...

More Emacs than Lisp tho it is a sliding scale... Thanks.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 13:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-18 13:40     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 14:19       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-18 13:40 UTC (permalink / raw)
  To: help-gnu-emacs

> OK, that explains it, buffer local values, I can't even keep
> track of the buffers...

I have used it 8 times, maybe change to setq to force everywhere...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 13:40     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-18 14:19       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 14:59         ` Omar Polo
  2021-04-18 21:59         ` Jean Louis
  0 siblings, 2 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-18 14:19 UTC (permalink / raw)
  To: help-gnu-emacs

>> OK, that explains it, buffer local values, I can't even
>> keep track of the buffers...
>
> I have used it 8 times, maybe change to setq to force
> everywhere...

Worst thing that can happen, it will show, where I need even
more force...

Wait, I sense there is something wrong with this thinking...

with setq, global var

with setq-default default val for var if not buffer-local

how do you look for the buffer-local var?

I take it that takes precedence?

yeah, it is the compass needle all over that acts on the
GLOBAL Earth's magnet, only put the local magnet next to
the compass, proximity overrules size

you set the buffer-locals or they set themselves thru hooks
or implications from setq "automatically when set"

how do I know my globals - me thinking them are - aren't
actually as they gets trapped in some Elisp file where
I eval'd them which has nothing to do with it, even?
Eval a config file for ERC, all that goes into the Elisp
file LOL.

How do you tell a var should be buffer-local when set? Nah,
I don't want to know. They are not part of my strategy.
But please tell my all buzzwords so I can go on pruning
my Elisp, always a good feeling :)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 14:19       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-18 14:59         ` Omar Polo
  2021-04-19  3:06           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 21:59         ` Jean Louis
  1 sibling, 1 reply; 23+ messages in thread
From: Omar Polo @ 2021-04-18 14:59 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

>>> OK, that explains it, buffer local values, I can't even
>>> keep track of the buffers...
>>
>> I have used it 8 times, maybe change to setq to force
>> everywhere...
>
> Worst thing that can happen, it will show, where I need even
> more force...
>
> Wait, I sense there is something wrong with this thinking...
>
> with setq, global var
>
> with setq-default default val for var if not buffer-local
>
> how do you look for the buffer-local var?
>
> I take it that takes precedence?
>
> yeah, it is the compass needle all over that acts on the
> GLOBAL Earth's magnet, only put the local magnet next to
> the compass, proximity overrules size
>
> you set the buffer-locals or they set themselves thru hooks
> or implications from setq "automatically when set"
>
> how do I know my globals - me thinking them are - aren't
> actually as they gets trapped in some Elisp file where
> I eval'd them which has nothing to do with it, even?
> Eval a config file for ERC, all that goes into the Elisp
> file LOL.
>
> How do you tell a var should be buffer-local when set? Nah,
> I don't want to know. They are not part of my strategy.
> But please tell my all buzzwords so I can go on pruning
> my Elisp, always a good feeling :)

[ keep in mind that I'm not really an expert elisp hacker ]

Try to keep it simple.  buffer-local variables sometimes are useful.
Let's take the indent-tabs-mode variable for instance: you set it to t
to enable hard tabs, or nil if you don't.  For some modes you may want
to use tabs (e.g. C, or Go), while for others spaces (may) be mandatory
(i.e. python), so a global variable won't do it  (you won't be able to
switch between C and python files without messing up the indentation :P)

Another example: I'm writing a chat application in elisp.  I have a,
say, toxe-friend-name that holds the name of the chat you've opened.
It's useful to keep this a buffer-local, so it gets a different value
per chat-buffer, and the elisp code is simple.

Sometimes this don't make sense: emacs-version probably doesn't need to
be buffer local, so judgement is needed.

C-h v tells you when a variable becomes buffer-local when set, or if
it's local to the current buffer, so you may want to check that.  It
even tells you its "default" and "local" value, which can get useful.

You get the buffer-local value when you're running a bit of elisp inside
that buffer.  (I don't know how to retrieve the global value, but a
short trip to the manual should tell me that)

So, for example:

	(defvar my-var 5)

	my-var
	;; => 5

	(with-current-buffer (get-buffer-create "test")
	  (message "my-var is %d" my-var)
	  (make-local-variable 'my-var)
	  (setq my-var 7)
	  (message "my-var is %d" my-var)
	  (setq-default my-var 'foo)
	  (message "my-var is %d" my-var))
	;; my-var is 5
	;; my-var is 7
	;; my-var is 7

	my-var
	;; => foo

HTH



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 11:40 don't understand setq-default Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 13:02 ` Omar Polo
@ 2021-04-18 21:55 ` Jean Louis
  1 sibling, 0 replies; 23+ messages in thread
From: Jean Louis @ 2021-04-18 21:55 UTC (permalink / raw)
  To: help-gnu-emacs

This explains it:
(info "(elisp) Default Value")

docstring is not adequately explaining the context that it relates to
buffer local variables.

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-04-18 14:42]:
> I don't understand `setq-default', maybe I never did, unsure.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 14:19       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-18 14:59         ` Omar Polo
@ 2021-04-18 21:59         ` Jean Louis
  2021-04-18 22:28           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19  3:49           ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 23+ messages in thread
From: Jean Louis @ 2021-04-18 21:59 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-04-18 17:20]:
> >> OK, that explains it, buffer local values, I can't even
> >> keep track of the buffers...
> >
> > I have used it 8 times, maybe change to setq to force
> > everywhere...
> 
> Worst thing that can happen, it will show, where I need even
> more force...
> 
> Wait, I sense there is something wrong with this thinking...
> 
> with setq, global var
> 
> with setq-default default val for var if not buffer-local
> 
> how do you look for the buffer-local var?

Here is how I have defined a buffer local variable:

(defvar-local rcd-tabulated-marked-items nil
  "Collects IDs for tabulated list modes")
(put 'rcd-tabulated-marked-items 'permanent-local t)




-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 21:59         ` Jean Louis
@ 2021-04-18 22:28           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19  6:44             ` Jean Louis
  2021-04-19  3:49           ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-18 22:28 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Here is how I have defined a buffer local variable:
>
> (defvar-local rcd-tabulated-marked-items nil
>   "Collects IDs for tabulated list modes")
> (put 'rcd-tabulated-marked-items 'permanent-local t)

Oh, great! No, didn't find/have any `defvar-local', good, for
me that is, I'm sure it's good for something but to me it
just isn't my style. And my style confirms it, even!

But... from that code above it looks you set it to local
twice, first by defvar-local, then by setting the
permanent-local property to t?

permanent-local, sounds like the default.

So, it is properties as I guessed! \o/

I've used `put' 8 times, but just to change the
disabled property.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 14:59         ` Omar Polo
@ 2021-04-19  3:06           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19  3:23             ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19 12:49             ` Thibaut Verron
  0 siblings, 2 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19  3:06 UTC (permalink / raw)
  To: help-gnu-emacs

Omar Polo wrote:

> [ keep in mind that I'm not really an expert elisp hacker ]

You are getting there...

> Let's take the indent-tabs-mode variable for instance: you
> set it to t to enable hard tabs, or nil if you don't.
> For some modes you may want to use tabs (e.g. C, or Go),

You may, but you don't need tabs in C. (I'm not familiar
with Go.) The only thing that always wants tabs are the
Makefiles, right?
>
> Another example: I'm writing a chat application in elisp.
> I have a, say, toxe-friend-name that holds the name of the
> chat you've opened. It's useful to keep this
> a buffer-local, so it gets a different value per
> chat-buffer, and the elisp code is simple.

That's right, it is a good example, when you have several
buffers of the same kind to hold some data piece or pieces
connected to that particular buffer of whatever the program
in general is suppose to do...

> that buffer. (I don't know how to retrieve the global
> value, but a short trip to the manual should tell me that)
>
> So, for example:
>
> 	(defvar my-var 5)

Heh, OK so now the global has a default as well... let's see
how this goes.

> 	my-var
> 	;; => 5

Right, defined with a default and not set. So it is
the default. What else is there to be.

> 	(with-current-buffer (get-buffer-create "test")
> 	  (message "my-var is %d" my-var) ; my-var is 5

Not changed so this is the global-default (only) version at
this time.

> 	  (make-local-variable 'my-var)
> 	  (setq my-var 7)
> 	  (message "my-var is %d" my-var) ; my-var is 7

Now it is set locally so now it is 7. By locally we mean
buffer-local, that's the only local there is?

> 	  (setq-default my-var 'foo)
> 	  (message "my-var is %d" my-var)) ;; my-var is 7

Now we set the default but since it is set hat doesn't matter.

> 	my-var
> 	;; => foo

And now it isn't anymore so the default is there, great.

So the pecking order is:

   local var
   global var
   local default
   global default

?

and local default and global default are even lower because
they don't do anything if there's a value there already.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  3:06           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-19  3:23             ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19  3:33               ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19 12:49             ` Thibaut Verron
  1 sibling, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19  3:23 UTC (permalink / raw)
  To: help-gnu-emacs

>>	my-var
>> ;; => foo
>
> And now it isn't anymore so the default is there, great.

No, why isn't that 7? argh!

I must write my own version :)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  3:23             ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-19  3:33               ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19  6:40                 ` Omar Polo
  0 siblings, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19  3:33 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg via Users list for the GNU Emacs text editor wrote:

>>>	my-var
>>> ;; => foo
>>
>> And now it isn't anymore so the default is there, great.
>
> No, why isn't that 7? argh!
>
> I must write my own version :)

OK, so after you say it is local with `make-local-variable' it
doesn't matter you do `setq', it won't get global that way?

No, but that's consistent actually, you can setq other local
stuff tho I prefer `let' and do all computation before any of
it is used, but you can, that's right.

setq isn't (always) global unless you make a typo...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 21:59         ` Jean Louis
  2021-04-18 22:28           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-19  3:49           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19  6:52             ` Jean Louis
  1 sibling, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19  3:49 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> (put 'rcd-tabulated-marked-items 'permanent-local t)

What happens if you do it like in the my-var demo only you
use this method, so first you'd actually set the global var,
then you'd tell it to be local!

Gets soo complicated this just so you can have a bunch of
buffer instances store some metadata that is common but
individual. OK, maybe helpful sometimes, sounds like it...

  setq-local
  above put and permanent-local property
  make-local-variable

keep 'em coming...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  3:33               ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-19  6:40                 ` Omar Polo
  2021-04-19 13:39                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 23+ messages in thread
From: Omar Polo @ 2021-04-19  6:40 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

> Emanuel Berg via Users list for the GNU Emacs text editor wrote:
>
>>>>	my-var
>>>> ;; => foo
>>>
>>> And now it isn't anymore so the default is there, great.
>>
>> No, why isn't that 7? argh!

It was a contrived example, sorry.  It is 7 because inside the
(with-current-buffer ...) I did a (setq-default my-var 'foo), and that
affected the global value.

>> I must write my own version :)
>
> OK, so after you say it is local with `make-local-variable' it
> doesn't matter you do `setq', it won't get global that way?

True

> No, but that's consistent actually, you can setq other local
> stuff tho I prefer `let' and do all computation before any of
> it is used, but you can, that's right.
>
> setq isn't (always) global unless you make a typo...

:)

Two more points:

 - re space vs tabs: I didn't want to make an argument on that, I was
   only saying that for some buffer you *may* prefer to have tabs and in
   other plain spaces, but that it's up to the user, buffer-local
   variables are  away to implement such behaviour.  The example of the
   chat was indeed better
 - re "pecking order": I would only think of local and global var, with
   the twist that the latter comes in two flavors ("real" global var and
   buffer-local version.)  It kinda gets more complex than that when you
   throw into the mix file and directory-local variable and dynamic
   scoping tho :P  (I admit I never thought about the full implication
   of all those types of variables)



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-18 22:28           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-19  6:44             ` Jean Louis
  2021-04-19 17:17               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 23+ messages in thread
From: Jean Louis @ 2021-04-19  6:44 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-04-19 01:29]:
> Jean Louis wrote:
> 
> > Here is how I have defined a buffer local variable:
> >
> > (defvar-local rcd-tabulated-marked-items nil
> >   "Collects IDs for tabulated list modes")
> > (put 'rcd-tabulated-marked-items 'permanent-local t)
> 
> Oh, great! No, didn't find/have any `defvar-local', good, for
> me that is, I'm sure it's good for something but to me it
> just isn't my style. And my style confirms it, even!
> 
> But... from that code above it looks you set it to local
> twice, first by defvar-local, then by setting the
> permanent-local property to t?
> 
> permanent-local, sounds like the default.

There is in manual what it is:

(info "(elisp) Creating Buffer-Local")

   A buffer-local variable is “permanent” if the variable name (a
symbol) has a ‘permanent-local’ property that is non-‘nil’.  Such
variables are unaffected by ‘kill-all-local-variables’, and their local
bindings are therefore not cleared by changing major modes.  Permanent
locals are appropriate for data pertaining to where the file came from
or how to save it, rather than with how to edit the contents.

As I am using the variable to extend the tabulated-list-mode, I have
been following the example and explanation in file `tabulated-list.el'
as below:

;; The reason `tabulated-list-format' and other variables are
;; permanent-local is to make it convenient to switch to a different
;; major mode, switch back, and have the original Tabulated List data
;; still valid.  See, for example, ebuff-menu.el.

That may happen sometimes.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  3:49           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-19  6:52             ` Jean Louis
  2021-04-19 17:26               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 23+ messages in thread
From: Jean Louis @ 2021-04-19  6:52 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-04-19 06:50]> Gets soo complicated this just so you can have a bunch of
> buffer instances store some metadata that is common but
> individual. OK, maybe helpful sometimes, sounds like it...

That is what I use all the time over here, for example I search for
people, I can get list of 13 people and mark them, store their ID
numbers in a variable that is same as in other buffer.

In other buffer maybe I mark 2 of them and wish to move them from one
list to other by using buffer, similar like copy/rename in dired.

Let us say there are 2 buffers, you wish to mark 3 people in the list
in one buffer and 4 people in the list in other buffer, but you don't
want to mix them. Their marks go into individual or buffer local
variables that are named same but are different from buffer to buffer.

Buffer 1 would have 3 people with ID numbers like 1, 2 and 3.

Buffer 2 would have 4 people with ID numbers like 23, 28 and 29.

In both cases variable is named `marked-people'

It is possible to switch program execution to other buffer, fetch
those values and switch back.

This may be useful when one needs to merge some information, copy or
rename, probably for many other uses.

One could for example browse a database from Singapore in one buffer,
and other from New York in other buffer and decide to merge some
entries.



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  3:06           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-19  3:23             ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-19 12:49             ` Thibaut Verron
  2021-04-19 17:29               ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 23+ messages in thread
From: Thibaut Verron @ 2021-04-19 12:49 UTC (permalink / raw)
  To: help-gnu-emacs

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.






^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  6:40                 ` Omar Polo
@ 2021-04-19 13:39                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19 13:39 UTC (permalink / raw)
  To: help-gnu-emacs

Omar Polo wrote:

> It was a contrived example, sorry. It is 7 because inside
> the (with-current-buffer ...) I did a (setq-default my-var
> 'foo), and that affected the global value.

I understand now, I think it was a pretty good example
actually. Why don't you keep it and possibly extend it with
more examples that you might stumble upon, or if someone asks
the same thing again...

> Two more points:
>
>  - re space vs tabs: I didn't want to make an argument on
>    that, I was only saying that for some buffer you *may*
>    prefer to have tabs and in other plain spaces, but that
>    it's up to the user, buffer-local variables are away to
>    implement such behaviour.

Yes, so two use cases so far, fine-tuning specific behavior
and the buffer instance metadata, if you will...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  6:44             ` Jean Louis
@ 2021-04-19 17:17               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19 17:17 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> There is in manual what it is:
>
> (info "(elisp) Creating Buffer-Local")
>
> A buffer-local variable is “permanent” if the variable name
> (a symbol) has a ‘permanent-local’ property that is
> non-‘nil’. Such variables are unaffected by
> ‘kill-all-local-variables’, and their local bindings are
> therefore not cleared by changing major modes.
> Permanent locals are appropriate for data pertaining to
> where the file came from or how to save it, rather than
> with how to edit the contents.

OK, so I was wrong, it is yet another type or variation of
the variable concept!

We need a state diagram for this...

And then another one for functions!

After that, if one already knows programming from somewhere
else, it would be enough to just look at these two diagrams.
Because what else is there to programming other than
functions and variables?

Oh, maybe a big note: "Don't do it, son."

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19  6:52             ` Jean Louis
@ 2021-04-19 17:26               ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-04-20  5:44                 ` Rounding percentages... was setq-default Jean Louis
  0 siblings, 1 reply; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19 17:26 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> That is what I use all the time over here, for example
> I search for people, I can get list of 13 people and mark
> them, store their ID numbers in a variable that is same as
> in other buffer.
>
> In other buffer maybe I mark 2 of them and wish to move
> them from one list to other by using buffer, similar like
> copy/rename in dired.
>
> Let us say there are 2 buffers, you wish to mark 3 people
> in the list in one buffer and 4 people in the list in other
> buffer, but you don't want to mix them. Their marks go into
> individual or buffer local variables that are named same
> but are different from buffer to buffer. [...]

This is what you do for a living, move people
between buffers?

But I also have lists of people, .mailrc is one, the other is
a NOC list (Non-Official Cover list) of people climbing in
our tree house [1] - without here being tricked into letting
the authorities score an easy win by me disclosing the list,
let me say that it is a possibility that we currently have 57
people climbing, 52% from se, 16 nationalities, 54% females.

Uganda (or even Africa) isn't represented so please stop by
anyway dear Jessie [2]

[1] https://dataswamp.org/~incal/blog/index.html
[2] https://www.youtube.com/watch?v=AoIiNhWEfoQ

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: don't understand setq-default
  2021-04-19 12:49             ` Thibaut Verron
@ 2021-04-19 17:29               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-19 17:29 UTC (permalink / raw)
  To: help-gnu-emacs

Thibaut Verron wrote:

> - 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.

Okay, good, that makes sense and is the way I think about it
intuitively as well.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Rounding percentages... was setq-default
  2021-04-19 17:26               ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-04-20  5:44                 ` Jean Louis
  2021-04-30  1:04                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 23+ messages in thread
From: Jean Louis @ 2021-04-20  5:44 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-04-19 20:28]> > Let us say there are 2 buffers, you wish to mark 3 people
> > in the list in one buffer and 4 people in the list in other
> > buffer, but you don't want to mix them. Their marks go into
> > individual or buffer local variables that are named same
> > but are different from buffer to buffer. [...]
> 
> This is what you do for a living, move people
> between buffers?

I also may move goods from buffer to buffer.

> But I also have lists of people, .mailrc is one, the other is
> a NOC list (Non-Official Cover list) of people climbing in
> our tree house [1] - without here being tricked into letting
> the authorities score an easy win by me disclosing the list,
> let me say that it is a possibility that we currently have 57
> people climbing, 52% from se, 16 nationalities, 54% females.

(defun pct-of-number-in-total (number total)
  "Return the percentage that NUMBER represents in a TOTAL."
  (/ number total 0.01))

(defun pct-of-number-in-total-1 (number total)
  "Return the percentage that NUMBER represents in a TOTAL."
  (let* ((number (+ number 0.0))
         (total (+ total 0.0))
         (percent (/ total 100.0))
         (percentage (/ number percent 100)))
    percentage))

(defun pct-list (list)
  "Return list that representes percentages of values in a given LIST."
  (let* ((total (apply '+ list)))
    (mapcar (lambda (item) (pct-of-number-in-total item total)) list)))


(pct-list '(31 26)) ⇒ (54.385964912280706 45.614035087719294)

I am not sure how do you get 54% females, maybe one of them is round?

(pct-list '(30 27)) ⇒ (52.63157894736842 47.368421052631575)

The round one must be coming from Sweden according to above math.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Rounding percentages... was setq-default
  2021-04-20  5:44                 ` Rounding percentages... was setq-default Jean Louis
@ 2021-04-30  1:04                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 23+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-04-30  1:04 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> (pct-list '(31 26)) ⇒ (54.385964912280706 45.614035087719294)
>
> I am not sure how do you get 54% females, maybe one of them
> is round?

The output of the program, which is integrated in the NOC so
cannot disclosed by programmer(s), is

  ;; 57 ppl climbing - 52% from se - 54% female

The machine does the counting so I take it is correct :)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-04-30  1:04 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-18 11:40 don't understand setq-default Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-18 13:02 ` Omar Polo
2021-04-18 13:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-18 13:40     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-18 14:19       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-18 14:59         ` Omar Polo
2021-04-19  3:06           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-19  3:23             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-19  3:33               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-19  6:40                 ` Omar Polo
2021-04-19 13:39                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-19 12:49             ` Thibaut Verron
2021-04-19 17:29               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-18 21:59         ` Jean Louis
2021-04-18 22:28           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-19  6:44             ` Jean Louis
2021-04-19 17:17               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-19  3:49           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-19  6:52             ` Jean Louis
2021-04-19 17:26               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-20  5:44                 ` Rounding percentages... was setq-default Jean Louis
2021-04-30  1:04                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-18 21:55 ` don't understand setq-default Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).