cp-mode: use native projectile keymaps
This commit is contained in:
parent
a091875789
commit
b1484297c3
2 changed files with 54 additions and 30 deletions
14
README.md
14
README.md
|
|
@ -49,6 +49,12 @@ Install the package from [MELPA](https://melpa.org), [MELPA Stable](https://stab
|
||||||
## Getting started
|
## Getting started
|
||||||
To turn on counsel-projectile mode, either call the command `counsel-projectile-mode` or use the Customize interface to toggle on the variable `counsel-projectile-mode`. This will turn on projectile mode, thus enabling all projectile key bindings, and add the counsel-projectile key bindings on top of them.
|
To turn on counsel-projectile mode, either call the command `counsel-projectile-mode` or use the Customize interface to toggle on the variable `counsel-projectile-mode`. This will turn on projectile mode, thus enabling all projectile key bindings, and add the counsel-projectile key bindings on top of them.
|
||||||
|
|
||||||
|
Note that starting with projectile version 1.1, the projectile (and counsel-projectile) key bindings are only available after you select a keymap prefix for them. For instance, to select <kbd>C-c p</kbd> as prefix (the default prior to version 1.1), you need to execute the following form:
|
||||||
|
|
||||||
|
```emacs-lisp
|
||||||
|
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
|
||||||
|
```
|
||||||
|
|
||||||
The counsel-projectile key bindings either remap existing projectile commands to their counsel-projectile replacements (e.g. <kbd>C-c p f</kbd> now calls `counsel-projectile-find-file` instead of `projectile-find-file`) or bind keys to counsel-projectile commands that have no projectile counterparts (e.g. <kbd>C-c p SPC</kbd> calls the command `counsel-projectile`).
|
The counsel-projectile key bindings either remap existing projectile commands to their counsel-projectile replacements (e.g. <kbd>C-c p f</kbd> now calls `counsel-projectile-find-file` instead of `projectile-find-file`) or bind keys to counsel-projectile commands that have no projectile counterparts (e.g. <kbd>C-c p SPC</kbd> calls the command `counsel-projectile`).
|
||||||
|
|
||||||
Calling the command `counsel-projectile-mode` once again or toggling off the variable `counsel-projectile-mode` disables the counsel-projectile key bindings and turns off projectile mode.
|
Calling the command `counsel-projectile-mode` once again or toggling off the variable `counsel-projectile-mode` disables the counsel-projectile key bindings and turns off projectile mode.
|
||||||
|
|
@ -184,6 +190,14 @@ This command opens the current project's agenda. It simply calls `org-agenda` af
|
||||||
# Configuration
|
# Configuration
|
||||||
## Enabling counsel-projectile mode when emacs starts
|
## Enabling counsel-projectile mode when emacs starts
|
||||||
To automatically enable counsel-projectile mode when emacs starts, you can either use the Customize interface to toggle on the variable `counsel-projectile-mode` and save your customization, or add `(counsel-projectile-mode)` to your init file.
|
To automatically enable counsel-projectile mode when emacs starts, you can either use the Customize interface to toggle on the variable `counsel-projectile-mode` and save your customization, or add `(counsel-projectile-mode)` to your init file.
|
||||||
|
|
||||||
|
Note that starting with projectile version 1.1, the projectile (and counsel-projectile) key bindings are only available after you select a keymap prefix for them. For instance, to select <kbd>C-c p</kbd> as prefix (the default prior to version 1.1), you need to add the following form to your init file:
|
||||||
|
|
||||||
|
```emacs-lisp
|
||||||
|
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
|
||||||
|
```
|
||||||
|
## Customizing counsel-projectile key bindings
|
||||||
|
The key bindings that are added when counsel-projectile-mode is turned on are determined by the variable `counsel-projectile-key-bindings`. You can set this variable, either directly or through the customize interface, to customize these key bindings. It holds an alist of `(KEY . DEF)` pairs, where KEY is either a key sequence to bind in `projectile-command-map` or a projectile command to remap in `projectile-mode-map`, and DEF is the counsel-projectile command to which KEY is remapped or bound.
|
||||||
## Customizing action lists
|
## Customizing action lists
|
||||||
The lists of available actions (including the default action) for most of the commands above are stored in custom variables. If you set one of these variables, either directly or through the through the Customize interface, the new value will be picked up the next time you invoke the corresponding commmand.
|
The lists of available actions (including the default action) for most of the commands above are stored in custom variables. If you set one of these variables, either directly or through the through the Customize interface, the new value will be picked up the next time you invoke the corresponding commmand.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1361,28 +1361,27 @@ If not inside a project, call `counsel-projectile-switch-project'."
|
||||||
|
|
||||||
;;;; counsel-projectile-mode
|
;;;; counsel-projectile-mode
|
||||||
|
|
||||||
(defvar counsel-projectile-command-map
|
(defcustom counsel-projectile-key-bindings
|
||||||
(let ((map (make-sparse-keymap)))
|
'((projectile-find-file . counsel-projectile-find-file)
|
||||||
(set-keymap-parent map projectile-command-map)
|
(projectile-find-dir . counsel-projectile-find-dir)
|
||||||
(define-key map (kbd "s r") 'counsel-projectile-rg)
|
(projectile-switch-to-buffer . counsel-projectile-switch-to-buffer)
|
||||||
(define-key map (kbd "O c") 'counsel-projectile-org-capture)
|
(projectile-grep . counsel-projectile-grep)
|
||||||
(define-key map (kbd "O a") 'counsel-projectile-org-agenda)
|
(projectile-ag . counsel-projectile-ag)
|
||||||
(define-key map (kbd "SPC") 'counsel-projectile)
|
(projectile-switch-project . counsel-projectile-switch-project)
|
||||||
map)
|
(" " . counsel-projectile)
|
||||||
"Keymap for Counesl-Projectile commands after `projectile-keymap-prefix'.")
|
("sr" . counsel-projectile-rg)
|
||||||
(fset 'counsel-projectile-command-map counsel-projectile-command-map)
|
("Oc" . counsel-projectile-org-capture)
|
||||||
|
("Oa" . counsel-projectile-org-agenda))
|
||||||
|
"Alist of counsel-projectile key bindings.
|
||||||
|
|
||||||
(defvar counsel-projectile-mode-map
|
Each element is of the form \(KEY . DEF\) where KEY is either a
|
||||||
(let ((map (make-sparse-keymap)))
|
key sequence to bind in `projectile-command-map' or a projectile
|
||||||
(define-key map projectile-keymap-prefix 'counsel-projectile-command-map)
|
command to remap in `projectile-mode-map', and DEF is the
|
||||||
(define-key map [remap projectile-find-file] 'counsel-projectile-find-file)
|
counsel-projectile command to which KEY is remapped or bound."
|
||||||
(define-key map [remap projectile-find-dir] 'counsel-projectile-find-dir)
|
:type '(alist :key-type (choice (function :tag "Projectile command")
|
||||||
(define-key map [remap projectile-switch-to-buffer] 'counsel-projectile-switch-to-buffer)
|
key-sequence)
|
||||||
(define-key map [remap projectile-grep] 'counsel-projectile-grep)
|
:value-type (function :tag "Counsel-projectile command"))
|
||||||
(define-key map [remap projectile-ag] 'counsel-projectile-ag)
|
:group 'counsel-projectile)
|
||||||
(define-key map [remap projectile-switch-project] 'counsel-projectile-switch-project)
|
|
||||||
map)
|
|
||||||
"Keymap for Counsel-Projectile mode.")
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode counsel-projectile-mode
|
(define-minor-mode counsel-projectile-mode
|
||||||
|
|
@ -1392,19 +1391,30 @@ With a prefix argument ARG, enable the mode if ARG is positive,
|
||||||
and disable it otherwise. If called from Lisp, enable the mode
|
and disable it otherwise. If called from Lisp, enable the mode
|
||||||
if ARG is omitted or nil, and toggle it if ARG is `toggle'.
|
if ARG is omitted or nil, and toggle it if ARG is `toggle'.
|
||||||
|
|
||||||
Counsel-Projectile mode triggers Projectile mode, remaps
|
Counsel-Projectile mode turns on Projectile mode, thus enabling
|
||||||
Projectile commands that have counsel replacements, and adds key
|
all projectile key bindings, and adds the counsel-projectile key
|
||||||
bindings for Counsel-Projectile commands that have no Projectile
|
bindings on top of them.
|
||||||
counterpart.
|
|
||||||
|
|
||||||
\\{counsel-projectile-mode-map}"
|
The counsel-projectile key bindings either remap existing
|
||||||
|
projectile commands to their counsel-projectile replacements or
|
||||||
|
bind keys to counsel-projectile commands that have no projectile
|
||||||
|
counterparts."
|
||||||
:group 'counsel-projectile
|
:group 'counsel-projectile
|
||||||
:require 'counsel-projectile
|
:require 'counsel-projectile
|
||||||
:keymap counsel-projectile-mode-map
|
|
||||||
:global t
|
:global t
|
||||||
(if counsel-projectile-mode
|
(cond
|
||||||
|
(counsel-projectile-mode
|
||||||
(projectile-mode)
|
(projectile-mode)
|
||||||
(projectile-mode -1)))
|
(dolist (binding counsel-projectile-key-bindings)
|
||||||
|
(if (functionp (car binding))
|
||||||
|
(define-key projectile-mode-map `[remap ,(car binding)] (cdr binding))
|
||||||
|
(define-key projectile-command-map (car binding) (cdr binding)))))
|
||||||
|
(t
|
||||||
|
(dolist (binding counsel-projectile-key-bindings)
|
||||||
|
(if (functionp (car binding))
|
||||||
|
(define-key projectile-mode-map `[remap ,(car binding)] nil)
|
||||||
|
(define-key projectile-command-map (car binding) nil)))
|
||||||
|
(projectile-mode -1))))
|
||||||
|
|
||||||
;;;; provide
|
;;;; provide
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue