* Q: Testing forthe existence of a function
@ 2009-10-27 13:11 grkuntzmd
2009-10-27 16:32 ` Giles Chamberlin
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: grkuntzmd @ 2009-10-27 13:11 UTC (permalink / raw)
To: Help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 697 bytes --]
I am trying to share my .emacs file across multiple hosts, some of which have
emacs compiled for X and some which do not.
On the ones that don't, the statement
(tool-bar-mode nil)
causes an error: Symbol's function definition is void: tool-bar-mode
I would like to add a statement of the form
(if (defined 'tool-bar-mode) (tool-bar-mode nil))
but I can't find the proper format -- is there a defined-p predicate?
I checked the elisp manual but could not find it.
Thanks
-----
G. Ralph Kuntz, MD
--
View this message in context: http://www.nabble.com/Q%3A-Testing-forthe-existence-of-a-function-tp26077455p26077455.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
[-- Attachment #2: Type: text/html, Size: 978 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Q: Testing forthe existence of a function
2009-10-27 13:11 Q: Testing forthe existence of a function grkuntzmd
@ 2009-10-27 16:32 ` Giles Chamberlin
2009-10-27 16:49 ` Drew Adams
2009-10-27 16:44 ` Drew Adams
[not found] ` <mailman.9565.1256661618.2239.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 9+ messages in thread
From: Giles Chamberlin @ 2009-10-27 16:32 UTC (permalink / raw)
To: help-gnu-emacs
grkuntzmd <grk@usa.net> writes:
> I would like to add a statement of the form
> (if (defined 'tool-bar-mode) (tool-bar-mode nil))
It's not the function you should be testing for but the feature which
implements it:
(if (featurep 'tool-bar) ...)
--
Giles
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Q: Testing forthe existence of a function
2009-10-27 16:32 ` Giles Chamberlin
@ 2009-10-27 16:49 ` Drew Adams
2009-10-27 17:06 ` Giles Chamberlin
0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2009-10-27 16:49 UTC (permalink / raw)
To: 'Giles Chamberlin', help-gnu-emacs
> > I would like to add a statement of the form
> > (if (defined 'tool-bar-mode) (tool-bar-mode nil))
>
> It's not the function you should be testing for but the feature which
> implements it: (if (featurep 'tool-bar) ...)
I disagree. Usually, it is better to test whether the function or variable that
you will use is defined. That provides finer granularity. `featurep' tells you
whether a library that provides a feature with that name has been loaded, but
different versions of libraries can have different sets of defined functions
(and it's even possible for different libraries to provide the same feature).
On the other hand, different libraries can sometimes define functions that have
the same name. In such a case, a `featurep' test can be more helpful than
`fboundp'.
In sum, it helps to know a bit about the function and library in question, and
even whether other libraries are common that might define a function with the
same name.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Q: Testing forthe existence of a function
2009-10-27 16:49 ` Drew Adams
@ 2009-10-27 17:06 ` Giles Chamberlin
0 siblings, 0 replies; 9+ messages in thread
From: Giles Chamberlin @ 2009-10-27 17:06 UTC (permalink / raw)
To: help-gnu-emacs
"Drew Adams" <drew.adams@oracle.com> writes:
> Usually, it is better to test whether the function or variable that
> you will use is defined. That provides finer granularity.
Interesting. I was thinking of my usual use case where I may or may not
have a particular library loaded, which admittedly was not the wording
of the original question.
> In sum, it helps to know a bit about the function and library in question, and
> even whether other libraries are common that might define a function with the
> same name.
Now that I can't argue with!
--
Giles
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Testing forthe existence of a function
2009-10-27 13:11 Q: Testing forthe existence of a function grkuntzmd
2009-10-27 16:32 ` Giles Chamberlin
@ 2009-10-27 16:44 ` Drew Adams
[not found] ` <mailman.9565.1256661618.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2009-10-27 16:44 UTC (permalink / raw)
To: 'grkuntzmd', Help-gnu-emacs
Function `fboundp' is what you're looking for.
--
Be aware that `fboundp' checks only whether its argument is defined, in the
sense of having something in its function cell. This does not necessarily mean
that the arg is a Lisp function - it could be also a macro or special form. If
you need to test whether the thing in question is in fact a function, use
`functionp'.
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.9565.1256661618.2239.help-gnu-emacs@gnu.org>]
* Re: Q: Testing forthe existence of a function
[not found] ` <mailman.9565.1256661618.2239.help-gnu-emacs@gnu.org>
@ 2009-10-27 19:08 ` Ilya Zakharevich
0 siblings, 0 replies; 9+ messages in thread
From: Ilya Zakharevich @ 2009-10-27 19:08 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-10-27, Giles Chamberlin <giles.chamberlin@tandberg.com> wrote:
> grkuntzmd <grk@usa.net> writes:
>
>> I would like to add a statement of the form
>> (if (defined 'tool-bar-mode) (tool-bar-mode nil))
>
> It's not the function you should be testing for but the feature which
> implements it:
>
> (if (featurep 'tool-bar) ...)
If one want to guard a call to tool-bar-mode(), then one should test
for function tool-bar-mode(), not some [possibly unrelated] feature.
Hope this helps,
Ilya
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.9564.1256660727.2239.help-gnu-emacs@gnu.org>]
end of thread, other threads:[~2009-10-27 19:08 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-27 13:11 Q: Testing forthe existence of a function grkuntzmd
2009-10-27 16:32 ` Giles Chamberlin
2009-10-27 16:49 ` Drew Adams
2009-10-27 17:06 ` Giles Chamberlin
2009-10-27 16:44 ` Drew Adams
[not found] ` <mailman.9565.1256661618.2239.help-gnu-emacs@gnu.org>
2009-10-27 19:08 ` Q: " Ilya Zakharevich
[not found] <mailman.9564.1256660727.2239.help-gnu-emacs@gnu.org>
2009-10-27 16:41 ` Colin S. Miller
2009-10-27 17:43 ` grkuntzmd
[not found] ` <mailman.9573.1256665424.2239.help-gnu-emacs@gnu.org>
2009-10-27 17:57 ` Colin S. Miller
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).