* writing an own version of setq?
@ 2002-10-09 10:34 Klaus Berndl
2002-10-09 13:09 ` Thomas Link
2002-10-10 11:53 ` Dave Pearson
0 siblings, 2 replies; 6+ messages in thread
From: Klaus Berndl @ 2002-10-09 10:34 UTC (permalink / raw)
I have written the code below to give me a save setq which only sets the new
value if the symbol is not already saved via customize:
,----
| (defmacro custom-saved-p (option)
| "Return only not nil if OPTION is a defcustom-option and has a saved
| value. "
| `(and (get ,option 'custom-type)
| (get ,option 'saved-value)))
|
| (defmacro setq-save (option value)
| "Sets OPTION to VALUE if and only if OPTION is not already saved by
| customize."
| `(and (not (custom-saved-p ,option))
| (set ,option ,value)))
`----
OK, calls like (setq-save 'klaus (+ 1 2)) work fine but I'm not really
satisfied because i want to write (setq-save klaus (+ 1 2)). Note the missing
quote! How can i achieve this?
(I know, for a complete setq-save i have to add the semantic for many
symbol-value-pairs like in the *setq* but this should not be a big problem...)
many thanks in advance!
Klaus
--
Klaus Berndl mailto: klaus.berndl@sdm.de
sd&m AG http://www.sdm.de
software design & management
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: writing an own version of setq?
2002-10-09 10:34 writing an own version of setq? Klaus Berndl
@ 2002-10-09 13:09 ` Thomas Link
2002-10-09 13:48 ` Klaus Berndl
2002-10-10 11:53 ` Dave Pearson
1 sibling, 1 reply; 6+ messages in thread
From: Thomas Link @ 2002-10-09 13:09 UTC (permalink / raw)
> OK, calls like (setq-save 'klaus (+ 1 2)) work fine but I'm not really
> satisfied because i want to write (setq-save klaus (+ 1 2)). Note the missing
> quote! How can i achieve this?
You could possibly replace ,option with (quote ,option) like in:
(defmacro setq-save (option value)
"Sets OPTION to VALUE if and only if OPTION is not already saved by
customize."
`(and (not (custom-saved-p ,option))
(set (quote ,option) ,value)))
(setq-save x 1)
Setting the variable with setq or defvar is ok for you?
Cheers,
Thomas.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: writing an own version of setq?
2002-10-09 13:09 ` Thomas Link
@ 2002-10-09 13:48 ` Klaus Berndl
2002-10-09 14:20 ` Thomas Link
0 siblings, 1 reply; 6+ messages in thread
From: Klaus Berndl @ 2002-10-09 13:48 UTC (permalink / raw)
On Wed, 09 Oct 2002, Thomas Link wrote:
> > OK, calls like (setq-save 'klaus (+ 1 2)) work fine but I'm not really
> > satisfied because i want to write (setq-save klaus (+ 1 2)). Note the
> > missing quote! How can i achieve this?
>
> You could possibly replace ,option with (quote ,option) like in:
>
> (defmacro setq-save (option value)
> "Sets OPTION to VALUE if and only if OPTION is not already saved by
> customize."
> `(and (not (custom-saved-p ,option))
> (set (quote ,option) ,value)))
>
> (setq-save x 1)
Yes, (quote ...) works, thanks!
> Setting the variable with setq or defvar is ok for you?
Hmm, what do you mean? I do not understand...
Ciao,
Klaus
--
Klaus Berndl mailto: klaus.berndl@sdm.de
sd&m AG http://www.sdm.de
software design & management
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: writing an own version of setq?
2002-10-09 13:48 ` Klaus Berndl
@ 2002-10-09 14:20 ` Thomas Link
2002-10-09 14:44 ` Klaus Berndl
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Link @ 2002-10-09 14:20 UTC (permalink / raw)
>> Setting the variable with setq or defvar is ok for you?
>
>
> Hmm, what do you mean? I do not understand...
Well ... ah ... Me neither. But I think I meant: I had the idea that it
could also be useful to check if the symbol hasn't been bound yet --
using either setq or defvar etc. This could be done by replacing
custom-saved-p with boundp. So the question was: considering this
possibility, this is no issue for you?
Cheers,
Thomas.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: writing an own version of setq?
2002-10-09 14:20 ` Thomas Link
@ 2002-10-09 14:44 ` Klaus Berndl
0 siblings, 0 replies; 6+ messages in thread
From: Klaus Berndl @ 2002-10-09 14:44 UTC (permalink / raw)
On Wed, 09 Oct 2002, Thomas Link wrote:
> >> Setting the variable with setq or defvar is ok for you?
> > Hmm, what do you mean? I do not understand...
>
> Well ... ah ... Me neither. But I think I meant: I had the idea that it
> could also be useful to check if the symbol hasn't been bound yet -- using
> either setq or defvar etc. This could be done by replacing custom-saved-p
> with boundp. So the question was: considering this possibility, this is no
> issue for you?
ah, OK, now it's clear...Good point, but this is no issue for me.
Klaus
--
Klaus Berndl mailto: klaus.berndl@sdm.de
sd&m AG http://www.sdm.de
software design & management
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: writing an own version of setq?
2002-10-09 10:34 writing an own version of setq? Klaus Berndl
2002-10-09 13:09 ` Thomas Link
@ 2002-10-10 11:53 ` Dave Pearson
1 sibling, 0 replies; 6+ messages in thread
From: Dave Pearson @ 2002-10-10 11:53 UTC (permalink / raw)
* Klaus Berndl <Klaus.Berndl@sdm.de>:
> ,----
> | (defmacro setq-save (option value)
> | "Sets OPTION to VALUE if and only if OPTION is not already saved by
> | customize."
> | `(and (not (custom-saved-p ,option))
> | (set ,option ,value)))
> `----
>
> OK, calls like (setq-save 'klaus (+ 1 2)) work fine but I'm not really
> satisfied because i want to write (setq-save klaus (+ 1 2)). Note the
> missing quote! How can i achieve this?
How about this:
-- cut here ----------------------------------------------------------------
(defmacro setq-save (option value)
"Sets OPTION to VALUE if and only if OPTION is not already saved by
customize."
`(and (not (custom-saved-p ',option))
(setq ,option ,value)))
-- cut here ----------------------------------------------------------------
It might not be important to you but you might want to note that your `setq'
doesn't quite work the same as `setq' itself. `setq' takes multiple sym/val
pairs.
--
Dave Pearson: | lbdb.el - LBDB interface.
http://www.davep.org/ | sawfish.el - Sawfish mode.
Emacs: | uptimes.el - Record emacs uptimes.
http://www.davep.org/emacs/ | quickurl.el - Recall lists of URLs.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-10-10 11:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-09 10:34 writing an own version of setq? Klaus Berndl
2002-10-09 13:09 ` Thomas Link
2002-10-09 13:48 ` Klaus Berndl
2002-10-09 14:20 ` Thomas Link
2002-10-09 14:44 ` Klaus Berndl
2002-10-10 11:53 ` Dave Pearson
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.