4

What's the idiomatic Emacs way to soft-require a feature, then use that feature if it's available?

The require function allows “soft require” by specifying a non-nil third argument:

(require 'projectile nil 'missing-okay)

What's the best way to then use that feature to do more things, only if the feature is now present?

(if succeeds
 (require 'projectile nil 'missing-okay)
 (do-some-stuff-that-needs-projectile))

or

(require 'projectile nil 'missing-okay)
(when feature-is-available 'projectile
 (do-some-stuff-that-needs-projectile))

or something else?

bignose
  • 627
  • 3
  • 15

1 Answers1

7

You just test with featurep:

(require 'projectile nil t)
(when (featurep 'projectile)
 (do-some-stuff-that-needs-projectile))

or you use that the require returns nil if it is not possible to load:

(when (require 'projectile nil t)
  (do-some-stuff-that-needs-projectile)
bignose
  • 627
  • 3
  • 15
Andrew Swann
  • 3,436
  • 2
  • 15
  • 43