If you use your
.emacs in many places (different machines, different versions of emacs), you cannot always be sure if certain packages or functions are available. The following macros for your
.emacs allow you to do things
only if the package or function is available.
Note: these macros are not very useful by themselves, but we will use them in later entries.
(defmacro require-maybe (feature &optional file)
"*Try to require FEATURE, but don't signal an error if `require' fails."
`(require ,feature ,file 'noerror))
(defmacro when-available (func foo)
"*Do something if FUNCTION is available."
`(when (fboundp ,func) ,foo))
If you place the macros somewhere in the beginning of your
.emacs, you can use them as follows (just some examples):
(when (require-maybe 'cursor-chg) (change-cursor-mode 1) (toggle-cursor-type-when-idle 1))
and
(when-available 'set-fringe-mode ; emacs22+
(set-fringe-mode 2)) ; don't have too much space left of col1
For more information on
installing modes (and other packages), see the
installing packages-entry.
3 comments:
Why make them macros?
Here's what I do:
(when (require 'abbrev nil t) ...)
I'd have to agree; this has the smell of mere tautology.
Post a Comment