3

I am currently using emacs out of prelude and with helm-projectile enabled in my setup.

Recently I added helm-ls-git to my stack too and noticed that the function helm-browse-project is more interesting for me than the one I've been using previously helm-projectile-find-file (from helm-projectile) bound to C-c p f.

Under my config/personal.el I've added the following line and thought it should do the trick:

(global-set-key (kbd "C-c p f") 'helm-browse-project)

This is not working, but if I switch to another unused key binding such as C-c p 0 for instance, it works perfectly fine.

So, why can't I override it and what should I do in order to make that happen?

3 Answers 3

3

If you(or prelude maker) set it up as explained on the projectile(wrapped by helm-projectile) home(github.com), you'll bind the internal projectile-command-map to this minor-mode's projectile-mode-map with the prefix key C-c p in your Emacs config like this:

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

In this case the target map to change for your own binding is neither global-map you first tried nor projectile-mode-map just for defining the prefix key to call the command map, but the command map itself is what should be changed and the following code will do the trick:

;; overwrite the command map for the key "f" (after the prefix key "C-c p")
(define-key projectile-command-map (kbd "f") 'helm-browse-project)
0

Load order matters. The latest global-set-key overrides the former ones. Make sure yours is evaluated after the one you want to override.

0

There are several different keymaps active for any Emacs buffer: the major-mode, any minor-modes, a buffer-local keymap, and the global keymap. The global keymap has the lowest priority - if a keybinding is defined in any of the other active keymaps, that's the binding that will be applied when you hit those keys.

In your case, C-c p f is bound in the keymap for a minor or major mode, so binding that key in the global keymap doesn't do anything useful. You can see a list of all the active keybindings for a buffer with the C-h b. Scroll through that to find the keymap where that sequence is bound. That's the one you need to modify, not the global keymap.

1
  • Usually the buffer local keymap is defined by the major-mode via use-local-map.
    – clemera
    Commented Apr 22, 2019 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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