Why Emacs project C-c p is undefined?

2.8k views Asked by At

I am new to Emacs. I have installed Projectile.

When I do C-c p, it says:

C-c p is undefined

Wondering what is wrong?

Following is my ~/.emacs file.

(require 'package)

(add-to-list 'package-archives
                      '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)

(defvar required-packages
  '(
    projectile
    ) "a list of packages to ensure are installed at launch.")

(require 'cl)

                    ; method to check if all packages are installed
(defun packages-installed-p ()
  (loop for p in required-packages
    when (not (package-installed-p p)) do (return nil)
    finally (return t)))

                    ; if not all packages are installed, check one by one and install the missing ones.
(unless (packages-installed-p)
                    ; check for new packages (package versions)
  (message "%s" "Emacs is now refreshing its package database...")
  (package-refresh-contents)
  (message "%s" " done.")
                    ; install the missing packages
  (dolist (p required-packages)
    (when (not (package-installed-p p))
      (package-install p))))

(require 'projectile)
(projectile-global-mode)

Edit

My .projectile file

-/venv
-*.pyc
-*.pyc~
-.git
-.gitignore
-.DS_Store

Edit 2

C-h v output for projectile-keymap-prefix as below:

projectile-keymap-prefix is a variable defined in `projectile.el'.
Its value is "^Cp"

Documentation:
Projectile keymap prefix.

You can customize this variable

Edit 3

I am using OS X 10.10.4. I start emacs from command line $emacs. I have installed Emacs using following commands:

brew install emacs --with-cocoa 

And, very first time (when I launch emacs). If do M-x, I don't get project-switch-project, rather I get project-switch-to-buffer. After switching buffer, I can switch project.

4

There are 4 answers

2
Micah Elliott On

You now need to explicitly enable it and set a prefix. The steps to enable Projectile with a C-c C-p prefix:

(projectile-mode +1)
(define-key projectile-mode-map (kbd "C-c C-p") 'projectile-command-map)

This has changed a couple times in 2018. Boris used to set C-c p as the default leader, then changed it to C-c C-p to be in accordance with the emacs keybinding conventions (bullet #2 mentions it.). But now it's removed altogether, so you should set it yourself.

0
louiet On

I encountered a similar problem recently that projectile-global-mode doesn't work as how it worked before after I had pinned the projectile package to the melpa stable archive, which was of the version v0.14.0.

The way that projectile-global-mode behaved before is that when turned on the keybindings are available from any buffer, but now I can't get it to work when in the splash screen (which is in Fundamental mode) after emacs starts, like Menno Smits points out in the comment.

For the sake of curiosity, I git bisect the source code history of projectile to find out which commit introduces this behavior change and finally get this, which no longer uses define-globalized-minor-mode to define the global minor mode but defines the projectile-mode as global by default with (define-minor-mode xxxxxx :global t), the difference could be told from the doc of define-globalized-minor-mode I think:

Globally enabling the mode also affects buffers subsequently created by visiting files, and buffers that use a major mode other than Fundamental mode; but it does not detect the creation of a new buffer in Fundamental mode. Source

Not sure if this relates, but this's how I figured it out and hope it helps anyone having the same confusion as mine.

4
bitristan On

Projectile's default keymap prefix is defined by the variable projectile-keymap-prefix. You can use C-h v to see value of that variable. If not set or is not ^Cp, you can use the code below to set it to C-c p

(setq projectile-keymap-prefix (kbd "C-c p"))

or any else key binds as you like.

0
Regis A. Ely On

You need to manually activate projectile mode in your ~/.emacs file:

(projectile-mode 1)