unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: How to avoid loading file when just testing if function
@ 2012-04-02 14:24 Buchs, Kevin
  2012-04-02 15:00 ` Drew Adams
  0 siblings, 1 reply; 2+ messages in thread
From: Buchs, Kevin @ 2012-04-02 14:24 UTC (permalink / raw)
  To: help-gnu-emacs, wxhgmqzgwmuf

Sebastien,

For the purpose you specify, how about checking what org-mode checks to
determine if there is an active clock? In the end, it simply looks for
an org-clock-marker to exist, i.e. be non-nil. (if org-clock-marker
(...)). You may be interested in the general question for any situation,
how to test whether some autoloaded function has been loaded or not.

Kevin Buchs | Senior Engineer | SPPDG | 507-538-5459 |
buchs.kevin@mayo.edu
Mayo Clinic | 200 First Street SW | Rochester, MN 55905 |
http://www.mayo.edu/sppdg 


Date: Mon, 02 Apr 2012 11:54:15 +0200
From: "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com>
To: help-gnu-emacs@gnu.org
Subject: How to avoid loading file when just testing if function is
	bound?
Message-ID: <80limempbs.fsf@somewhere.org>
Content-Type: text/plain

Hi,

For the purpose of asking whether I eventually need to clock out (from
Org) before exiting Emacs, I've written this chunk of code:

--8<---------------cut here---------------start------------->8---
  (if (and (fboundp 'org-clocking-p)
           (org-clocking-p)
	   (y-or-n-p "You are currently clocking time, clock out? "))
      (org-clock-out)
    t))
--8<---------------cut here---------------end--------------->8---

The problem is that if Org is not yet loaded, the above code does load
it (because `org-clocking-p' is autoloaded) -- and that takes a while...
and I just wanted to exit Emacs...

How to avoid this?

Best regards,
  Seb

--
Sebastien Vauban



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

* RE: How to avoid loading file when just testing if function
  2012-04-02 14:24 How to avoid loading file when just testing if function Buchs, Kevin
@ 2012-04-02 15:00 ` Drew Adams
  0 siblings, 0 replies; 2+ messages in thread
From: Drew Adams @ 2012-04-02 15:00 UTC (permalink / raw)
  To: help-gnu-emacs

FWIW - I believe that someone else has already pointed out that the test for
whether a symbol is bound to a function and not just to an autoloaded object
(which is a promise of loading a function) is this:

(defun funp (symbol)
  "SYMBOL's function definition is non-void and not an autoload object."
  (and (fboundp symbol)
       (not (eq 'autoload (car-safe (symbol-function symbol))

Such a function should perhaps be predefined for Emacs, but it is not.  There
are at least three things to keep in mind when testing whether a symbol is
defined as an Emacs-Lisp "function", depending on what you need: `fboundp',
`functionp', and the above test (`funp').

Other tests are sometimes relevant too: `subrp' and `byte-code-functionp'.  And
remember that `functionp' returns non-nil also for some non-symbols: lambda
forms, closures, and byte-code functions.  And `fboundp' returns non-nil for
some non-functions such as macros and special forms.

Then there's the fact that a Lisp "function" does not necessarily implement a
(mathematical) function...  Yes, the terminology can be confusing.  The Elisp
manual is your friend, as is the Emacs source code.




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

end of thread, other threads:[~2012-04-02 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-02 14:24 How to avoid loading file when just testing if function Buchs, Kevin
2012-04-02 15:00 ` Drew Adams

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