Why Emacs project C-c p is undefined?
Asked Answered
H

4

16

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.

Hilde answered 15/7, 2015 at 3:41 Comment(4)
Do you have a .projectile file somewhere? If you aren't within a project, my understanding is that this may not work.Radiotelegraphy
I should also point out that your .init code worked for me in terms of installing projectile and getting the commands to function. Try restarting emacs, perhaps.Radiotelegraphy
Hi, I do have .projectile file in directoryHilde
I see the same behaviour for scratch buffers in Fundamental mode. If I attempt to use C-c p in the initial scratch buffer it doesn't work but it does when I'm editing other files. Could it be that you're trying C-c p in the initial scratch buffer when Emacs starts? Obviously, it would be nice if C-c p also worked in scratch buffers but it's not such a big issue.Buttons
C
12

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.

Cystitis answered 27/8, 2018 at 20:23 Comment(2)
the link to the keybinding conventions you quoted, don't seem to say C-c C-p is any different from C-c p, so I am just wondering, using C-c p feels just as fine. It doesn't seem to break any conventions.Grampus
@DanielDinnyes, C-c <letter> for any upper- or lower-case letter is reserved for the end user (as stated on the linked page of the manual -- it's bullet point #2). It is effectively a bug for any library to bind such a sequence.Tallia
H
1

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

(projectile-mode 1)
Hygeia answered 25/8, 2017 at 10:5 Comment(0)
P
0

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.

Prescript answered 15/7, 2015 at 4:48 Comment(4)
Hi Tinker, It seems that there is ^Cp variable already set for projectile-keymap-prefix. I have added edit2 in my question above.Hilde
Oh, that's strange. Let me see. Could you first execute the command projectile-find-file to see if it works. Then use C-h f to see the binding keys. As my computer, it is C-c p f. So I can use that to execute projectile command. It everything work fine, but you have the problem yet, then I have no idea about this.Prescript
projectile-find-file works as expected. C-h f also works. But C-c p f does not work.Hilde
That's very strange. Perhaps you can toggle-debug-on-error and see what happened internal. I am not famillar about that. So sorry for can't provider any more help.Prescript
V
0

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.

Virge answered 15/7, 2018 at 4:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.