projectile-keymap-prefix is not respected

Created on 31 Mar 2016  Â·  5Comments  Â·  Source: bbatsov/projectile

Expected behavior

after setting projectile-keymap-prefix, that prefix now launches projectile commands and the default prefix no longer does.

Actual behavior

setting projectile-keymap-prefix has no effect whatsoever.

Steps to reproduce the problem

set projectile-keymap-prefix, either with setq as described in the README, or via customize. Currently I have the following like in my init.el, produced by customize

'(projectile-keymap-prefix (kbd "M-p"))

I've also tried a couple other variants - (kbd "C-c C-p"), "M-p", "C-c C-p". None have any effect

This is what I see when I run C-h v projectile-keymap-prefix

projectile-keymap-prefix is a variable defined in `projectile.el'.
Its value is (kbd "M-p")
Original value was "p"

Documentation:
Projectile keymap prefix.

You can customize this variable.

[back]

Environment & Version information

Projectile version: 0.13.0
GNU Emacs 24.5.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.29)

Operating system

Linux, distro is NixOS

Most helpful comment

setting projectile-keymap-prefix has no effect whatsoever.

AFAIU, you need to set this variable _before_ projectile is required/loaded in order for the change to take effect.

When projectile.el is loaded, the definition of projectile-mode-map is evaluated. It defines a single entry which uses the value of projectile-keymap-prefix to point to projectile-command-map. If you set projectile-keymap-prefix later, it won't change the existing keybinding in projectile-mode-map.

So you basically have two options if you want projectile's commands to have a different prefix key:

  • set projectile-keymap-prefix _before_ requiring/loading projectile:

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

  • rebind projectile-command-map as @stunpix suggested (you may also want to unbind projectile-keymap-prefix if you're going to reuse C-c p for other keybindings):

elisp (require 'projectile) (define-key projectile-mode-map projectile-keymap-prefix nil) (define-key projectile-mode-map (kbd "C-c C-p") #'projectile-command-map)

There was a similar issue in projectile-rails: asok/projectile-rails#34.

cc @bbatsov if my reasoning is correct, can you add a note to the docs which clears this issue?

All 5 comments

Same problem here.

For me project's README example with projectile-keymap-prefix doesn't work as well, so after numerous attempts I'm using a workaround:

(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)

And this does what projectile-keymap-prefix is supposed to do: now I can use Projectile like s-p f and s-p s g

setting projectile-keymap-prefix has no effect whatsoever.

AFAIU, you need to set this variable _before_ projectile is required/loaded in order for the change to take effect.

When projectile.el is loaded, the definition of projectile-mode-map is evaluated. It defines a single entry which uses the value of projectile-keymap-prefix to point to projectile-command-map. If you set projectile-keymap-prefix later, it won't change the existing keybinding in projectile-mode-map.

So you basically have two options if you want projectile's commands to have a different prefix key:

  • set projectile-keymap-prefix _before_ requiring/loading projectile:

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

  • rebind projectile-command-map as @stunpix suggested (you may also want to unbind projectile-keymap-prefix if you're going to reuse C-c p for other keybindings):

elisp (require 'projectile) (define-key projectile-mode-map projectile-keymap-prefix nil) (define-key projectile-mode-map (kbd "C-c C-p") #'projectile-command-map)

There was a similar issue in projectile-rails: asok/projectile-rails#34.

cc @bbatsov if my reasoning is correct, can you add a note to the docs which clears this issue?

cc @bbatsov if my reasoning is correct, can you add a note to the docs which clears this issue?

Your reasoning is correct. Doc improvement PRs are always welcome. :-)

I managed to solve my issue! Make sure projectile-mode is enabled when trying the above

~~I'm still facing problems with this even after the fix suggested above.

This is what I see when I run C-h v projectile-keymap-prefix

projectile-keymap-prefix is a variable defined in ‘projectile.el’.
Its value is "C-c C-p"
Original value was "p"

Documentation:
Projectile keymap prefix.

You can customize this variable.

Everything in my init.el related to projectile

(require 'projectile)
(define-key projectile-mode-map projectile-keymap-prefix nil)
(define-key projectile-mode-map (kbd "C-c C-p") #'projectile-command-map)
(setq projectile-switch-project-action 'venv-projectile-auto-workon)

(require 'helm-projectile)
(helm-projectile-on)

~~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

levicole picture levicole  Â·  3Comments

barrkel picture barrkel  Â·  9Comments

JSmith-BitFlipper picture JSmith-BitFlipper  Â·  4Comments

ghost picture ghost  Â·  4Comments

novakboskov picture novakboskov  Â·  4Comments