* predicate group-p to see if a group exists?
@ 2008-01-31 23:03 Drew Adams
2008-02-01 6:40 ` martin rudalics
0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2008-01-31 23:03 UTC (permalink / raw)
To: Emacs-Devel
There seems to be no predicate to test whether a particular group is
defined. Should there be one? (group-p 'foo)
For example, consider a library that could be used with different Emacs
versions. Suppose that a group `foo' exists in one Emacs version but not in
another (Buffer-menu is an example - doesn't exist in Emacs 20).
Suppose I want to define a new group `my-foo'. I want it to have group `foo'
as parent, if group `foo' exists'. If not, I want it to have whatever
parent(s) `foo' has in the Emacs versions where `foo' is defined.
For that, I could do this, if predicate `group-p' existed:
(defgroup my-foo nil "jjjj"
:group (if (group-p 'foo) 'foo 'bar))
Yes, I could just do this:
(defgroup my-foo nil "jjjj"
:group 'foo :group 'bar)
But in the later Emacs versions, `my-foo' will also have `bar' as parent,
not just `foo', which is a bit less tidy.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: predicate group-p to see if a group exists?
2008-01-31 23:03 predicate group-p to see if a group exists? Drew Adams
@ 2008-02-01 6:40 ` martin rudalics
2008-02-01 7:11 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2008-02-01 6:40 UTC (permalink / raw)
To: Drew Adams; +Cc: Emacs-Devel
> There seems to be no predicate to test whether a particular group is
> defined. Should there be one? (group-p 'foo)
>
> For example, consider a library that could be used with different Emacs
> versions. Suppose that a group `foo' exists in one Emacs version but not in
> another (Buffer-menu is an example - doesn't exist in Emacs 20).
>
> Suppose I want to define a new group `my-foo'. I want it to have group `foo'
> as parent, if group `foo' exists'. If not, I want it to have whatever
> parent(s) `foo' has in the Emacs versions where `foo' is defined.
>
> For that, I could do this, if predicate `group-p' existed:
>
> (defgroup my-foo nil "jjjj"
> :group (if (group-p 'foo) 'foo 'bar))
>
> Yes, I could just do this:
>
> (defgroup my-foo nil "jjjj"
> :group 'foo :group 'bar)
>
> But in the later Emacs versions, `my-foo' will also have `bar' as parent,
> not just `foo', which is a bit less tidy.
You could write
(defgroup my-foo nil "jjjj"
:group (if (get 'foo 'custom-group) 'foo 'bar))
because it's unlikely that a custom group doesn't have any members
(except for the case when you're just specifying it - like my-foo).
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: predicate group-p to see if a group exists?
2008-02-01 6:40 ` martin rudalics
@ 2008-02-01 7:11 ` Drew Adams
2008-02-01 14:53 ` Stefan Monnier
2008-02-02 7:39 ` Richard Stallman
0 siblings, 2 replies; 6+ messages in thread
From: Drew Adams @ 2008-02-01 7:11 UTC (permalink / raw)
To: 'martin rudalics'; +Cc: 'Emacs-Devel'
> > There seems to be no predicate to test whether a particular group is
> > defined. Should there be one? (group-p 'foo)
>
> You could write
>
> (defgroup my-foo nil "jjjj"
> :group (if (get 'foo 'custom-group) 'foo 'bar))
>
> because it's unlikely that a custom group doesn't have any members
> (except for the case when you're just specifying it - like my-foo).
Yes, but that wouldn't occur to most people. Using `defgroup', `defcustom',
and `defface' shouldn't require knowledge of how Customize is implemented.
Granted, most users of `defgroup', `defcustom', and `defface' will not need
to test whether a given group exists, but some will. I still have the
question whether we shouldn't have a function `group-p'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: predicate group-p to see if a group exists?
2008-02-01 7:11 ` Drew Adams
@ 2008-02-01 14:53 ` Stefan Monnier
2008-02-01 15:00 ` Lennart Borgman (gmail)
2008-02-02 7:39 ` Richard Stallman
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2008-02-01 14:53 UTC (permalink / raw)
To: Drew Adams; +Cc: 'martin rudalics', 'Emacs-Devel'
> Granted, most users of `defgroup', `defcustom', and `defface' will not need
> to test whether a given group exists, but some will. I still have the
> question whether we shouldn't have a function `group-p'.
IIRC I've looked into it at some point. The problem is that currently,
the data necessary to write custom-group-p is absent.
`customize-read-group' uses the following predicate for completion
purposes:
(lambda (symbol)
(or (and (get symbol 'custom-loads)
(not (get symbol 'custom-autoload)))
(get symbol 'custom-group)))
So we could use the above as the definition of custom-group-p, but IIRC
it's not 100% reliable/correct, and the lack of comments explaining why
we check (and (get symbol 'custom-loads) (not (get symbol 'custom-autoload)))
is also a significant problem.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: predicate group-p to see if a group exists?
2008-02-01 14:53 ` Stefan Monnier
@ 2008-02-01 15:00 ` Lennart Borgman (gmail)
0 siblings, 0 replies; 6+ messages in thread
From: Lennart Borgman (gmail) @ 2008-02-01 15:00 UTC (permalink / raw)
To: Stefan Monnier
Cc: 'martin rudalics', Drew Adams, 'Emacs-Devel'
Stefan Monnier wrote:
>> Granted, most users of `defgroup', `defcustom', and `defface' will not need
>> to test whether a given group exists, but some will. I still have the
>> question whether we shouldn't have a function `group-p'.
>
> IIRC I've looked into it at some point. The problem is that currently,
> the data necessary to write custom-group-p is absent.
>
> `customize-read-group' uses the following predicate for completion
> purposes:
>
> (lambda (symbol)
> (or (and (get symbol 'custom-loads)
> (not (get symbol 'custom-autoload)))
> (get symbol 'custom-group)))
>
> So we could use the above as the definition of custom-group-p, but IIRC
> it's not 100% reliable/correct, and the lack of comments explaining why
> we check (and (get symbol 'custom-loads) (not (get symbol 'custom-autoload)))
> is also a significant problem.
But why not use this? It will at least be consisten?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: predicate group-p to see if a group exists?
2008-02-01 7:11 ` Drew Adams
2008-02-01 14:53 ` Stefan Monnier
@ 2008-02-02 7:39 ` Richard Stallman
1 sibling, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2008-02-02 7:39 UTC (permalink / raw)
To: Drew Adams; +Cc: rudalics, emacs-devel
Granted, most users of `defgroup', `defcustom', and `defface' will not need
to test whether a given group exists, but some will. I still have the
question whether we shouldn't have a function `group-p'.
Until we see a more than a handful of cases where testing
the existence of a custom group is the right thing to do,
let's not spend any time on this.
Every function added to Emacs has a real cost, which includes writing
it, maintaining it, documenting it, etc. It requires a justification
stronger than "maybe someone will find it useful". In this case,
justification is not present.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-02-02 7:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-31 23:03 predicate group-p to see if a group exists? Drew Adams
2008-02-01 6:40 ` martin rudalics
2008-02-01 7:11 ` Drew Adams
2008-02-01 14:53 ` Stefan Monnier
2008-02-01 15:00 ` Lennart Borgman (gmail)
2008-02-02 7:39 ` 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).