I'm trying to bind projectile-find-file to a keyboard shorcut and running in to this error.

Apparently projectile is installed, because M-x listing shows at least a dozen projectile prefixed commands.

enter image description here


Projectile might not be loaded. (require 'projectile) should work fine.

Some projectile functions, listed by M-x, are just prepared to be autoloaded.

EDIT: Thanks, @Basil

The answer above is not wrong. But in your init.el, writing (require 'projectile) is not recommended, because projectile can be loaded on your first time to use one of the projectile functions prepared to be autoloaded. Writing require in init.el lead longer startup time of Emacs. So replace the BODY... with provided define-keys on below code:

(with-eval-after-load 'projectile BODY...)

BODY in with-eval-after-load is evaluated after loading of projectile. So this code makes sure that BODY is evaluated after defining projectile-mode-map.

On the other hand, if you just want to try the key binds only on the current sesstion, requiring projectile and evaluating them are easy, i think.

Technical Words: "Require" has almost same meanings as "load." It means reading el(c) file and making the feature available.

  • 1
    It's often better to write (with-eval-after-load 'projectile (define-key projectile-mode-map ...)) than to eagerly load (require 'projectile) in an init file, as the latter slows down Emacs startup. See (info "(elisp) Hooks for Loading"). – Basil May 10 at 7:51
  • @Basil You are right. Almost all the setting of PACKAGE is surrounded by (with-eval-after-load 'PACKAGE ...). In this case, M-x projectile-mode(more recommended) or (require 'projectile) should be run to use projectile. – ROCKTAKEY May 10 at 7:58
  • Sure, but the question is not about how to load projectile, it's about how to safely bind keys in its keymaps before it is loaded. Which is why I'm suggesting mentioning with-eval-after-load (or even use-package). – Basil May 10 at 8:05
  • @Basil I've thought with-eval-after-load is better and what s/he needs, too. I just forgot the word, "besides." Sorry for my mistake. I'll edit the answer. – ROCKTAKEY May 10 at 9:24
  • No mistake, thanks! – Basil May 10 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.