* add-list local value
@ 2008-03-12 0:54 Lennart Borgman (gmail)
2008-03-12 1:51 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-12 0:54 UTC (permalink / raw)
To: Emacs Devel
Wouldn't it be practical to allow add-list to add to the buffer local
value, like add-hook allows? At least I need it ...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add-list local value
2008-03-12 0:54 add-list local value Lennart Borgman (gmail)
@ 2008-03-12 1:51 ` Stefan Monnier
2008-03-12 2:18 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2008-03-12 1:51 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Emacs Devel
> Wouldn't it be practical to allow add-list to add to the buffer local value,
> like add-hook allows? At least I need it ...
It makes sense for add-hook because buffer-local values of hook include
a special entry t which means "run the global value of this hook".
For lists, it doesn't make much sense I believe. Either the list is
global or it's local. If it's local, just make it local with
make-local-variable.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add-list local value
2008-03-12 1:51 ` Stefan Monnier
@ 2008-03-12 2:18 ` Lennart Borgman (gmail)
2008-03-12 8:41 ` Juanma Barranquero
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-12 2:18 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Emacs Devel
Stefan Monnier wrote:
>> Wouldn't it be practical to allow add-list to add to the buffer local value,
>> like add-hook allows? At least I need it ...
>
> It makes sense for add-hook because buffer-local values of hook include
> a special entry t which means "run the global value of this hook".
>
> For lists, it doesn't make much sense I believe. Either the list is
> global or it's local. If it's local, just make it local with
> make-local-variable.
And if I have a local value and want to add to the global value with
add-to-list?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add-list local value
2008-03-12 2:18 ` Lennart Borgman (gmail)
@ 2008-03-12 8:41 ` Juanma Barranquero
2008-03-12 8:49 ` Lennart Borgman (gmail)
2008-03-12 13:51 ` Stefan Monnier
2008-03-12 17:51 ` Richard Stallman
2 siblings, 1 reply; 7+ messages in thread
From: Juanma Barranquero @ 2008-03-12 8:41 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Stefan Monnier, Emacs Devel
On Wed, Mar 12, 2008 at 3:18 AM, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:
> And if I have a local value and want to add to the global value with
> add-to-list?
(with-temp-buffer (add-to-list 'my-variable 'my-value))
unless the variable is automatically buffer-local. If it is, I think
it would be uncommon to modify the global value (it would be more
logical to just set it up with defvar), but you can always skip the
`add-to-list' and assign to my-variable with setq-default.
Juanma
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add-list local value
2008-03-12 8:41 ` Juanma Barranquero
@ 2008-03-12 8:49 ` Lennart Borgman (gmail)
0 siblings, 0 replies; 7+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-12 8:49 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Stefan Monnier, Emacs Devel
Juanma Barranquero wrote:
> On Wed, Mar 12, 2008 at 3:18 AM, Lennart Borgman (gmail)
> <lennart.borgman@gmail.com> wrote:
>
>> And if I have a local value and want to add to the global value with
>> add-to-list?
>
> (with-temp-buffer (add-to-list 'my-variable 'my-value))
>
> unless the variable is automatically buffer-local. If it is, I think
> it would be uncommon to modify the global value (it would be more
> logical to just set it up with defvar), but you can always skip the
> `add-to-list' and assign to my-variable with setq-default.
Thanks, yes, something like this perhaps
(defun add-to-global-list (list-var element &optional append compare-fn)
(let ((global-val (default-value list-var)))
(add-to-list 'global-val element append compare-fn)
(set-default list-var global-val)))
But I would prefer that add-to-list did it for me.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add-list local value
2008-03-12 2:18 ` Lennart Borgman (gmail)
2008-03-12 8:41 ` Juanma Barranquero
@ 2008-03-12 13:51 ` Stefan Monnier
2008-03-12 17:51 ` Richard Stallman
2 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2008-03-12 13:51 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Emacs Devel
>>> Wouldn't it be practical to allow add-list to add to the buffer local value,
>>> like add-hook allows? At least I need it ...
>>
>> It makes sense for add-hook because buffer-local values of hook include
>> a special entry t which means "run the global value of this hook".
>>
>> For lists, it doesn't make much sense I believe. Either the list is
>> global or it's local. If it's local, just make it local with
>> make-local-variable.
> And if I have a local value and want to add to the global value with
> add-to-list?
A good reason why add-to-list is a bad function.
You can use
(require 'cl)
(pushnew <val> (default-value '<sym>))
or
(setq-default <sym> (cons <var> (default-value '<sym>)))
or
(unless (member <val> (default-value '<sym>))
(setq-default <sym> (cons <var> (default-value '<sym>))))
-- Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add-list local value
2008-03-12 2:18 ` Lennart Borgman (gmail)
2008-03-12 8:41 ` Juanma Barranquero
2008-03-12 13:51 ` Stefan Monnier
@ 2008-03-12 17:51 ` Richard Stallman
2 siblings, 0 replies; 7+ messages in thread
From: Richard Stallman @ 2008-03-12 17:51 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: monnier, emacs-devel
And if I have a local value and want to add to the global value with
add-to-list?
It isn't hard to do this "by hand", and it is rare, so it isn't worth
defining (and documenting!) a new feature. It would be a change for
the worse.
Emacs is already very complex. If we added new primitive features
for things like this, it would become far more complex.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-03-12 17:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-12 0:54 add-list local value Lennart Borgman (gmail)
2008-03-12 1:51 ` Stefan Monnier
2008-03-12 2:18 ` Lennart Borgman (gmail)
2008-03-12 8:41 ` Juanma Barranquero
2008-03-12 8:49 ` Lennart Borgman (gmail)
2008-03-12 13:51 ` Stefan Monnier
2008-03-12 17:51 ` Richard Stallman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).