Remove prefix actions

These actions are no longer needed since ivy now supports
multi-character action keys.
This commit is contained in:
Eric Danan 2018-01-05 09:46:11 +01:00
parent 0a63f2210d
commit d482793252
2 changed files with 23 additions and 76 deletions

View file

@ -88,7 +88,7 @@ Default key binding: <kbd>C-c p p</kbd>.
This command is a replacement for `projectile-switch-project`. It adds the possibility to select from a list of switch-project actions to apply to the selected project: This command is a replacement for `projectile-switch-project`. It adds the possibility to select from a list of switch-project actions to apply to the selected project:
| Key | Action | | Key | Action |
| :------------ | :-------------------------------------------------------------------------------------- | | :------------- | :-------------------------------------------------------------------------------------- |
| <kbd>o</kbd> | Jump to a project buffer or file: call `counsel-projectile` (default action; see above) | | <kbd>o</kbd> | Jump to a project buffer or file: call `counsel-projectile` (default action; see above) |
| <kbd>f</kbd> | Jump to a project file: call `counsel-projectile-find-file` (see below) | | <kbd>f</kbd> | Jump to a project file: call `counsel-projectile-find-file` (see below) |
| <kbd>d</kbd> | Jump to a project directory: call `counsel-projectile-find-dir` (see below) | | <kbd>d</kbd> | Jump to a project directory: call `counsel-projectile-find-dir` (see below) |
@ -197,19 +197,6 @@ Extra actions can be added to these lists or, alternatively, can be set through
- change an action key, function, or name, - change an action key, function, or name,
- change the index of the default action. - change the index of the default action.
See its docstring for details. See its docstring for details.
Although ivy does not support this natively, it is in fact possible to include actions with a two-character key in the list. To do so, however, it is necessary to also include an action whose key is the first of these two characters and whose action function is `counsel-projectile-prefix-action`. For instance, the default value of `counsel-projectile-switch-project-action` includes the following actions:
```emacs-lisp
("s" counsel-projectile-prefix-action
"search project with grep / ag / rg...")
("sg" counsel-projectile-switch-project-action-grep
"search project with grep")
("ss" counsel-projectile-switch-project-action-ag
"search project with ag")
("sr" counsel-projectile-switch-project-action-rg
"search project with rg")
```
## Setting `counsel-projectile-org-capture` templates ## Setting `counsel-projectile-org-capture` templates
The available capture templates for `counsel-projectile-org-capture` are read from the variable `counsel-projectile-org-capture-templates`. This variable has the same format as the variable `org-capture-templates`, except that in all strings of in an entrys target slot, all instances of `${root}` and `${name}` are replaced with the current project root and name, respectively. The available capture templates for `counsel-projectile-org-capture` are read from the variable `counsel-projectile-org-capture-templates`. This variable has the same format as the variable `org-capture-templates`, except that in all strings of in an entrys target slot, all instances of `${root}` and `${name}` are replaced with the current project root and name, respectively.

View file

@ -73,7 +73,7 @@ consisting of:
- the index of the default action in the list (1 for the first - the index of the default action in the list (1 for the first
action, etc), action, etc),
- the available actions, each of which consists of: - the available actions, each of which consists of:
- a key (one-character string) to call the action, - a key (string) to call the action,
- an action function of one variable, - an action function of one variable,
- a name (string) for the action. - a name (string) for the action.
@ -83,12 +83,7 @@ An action is triggered for the selected candidate with `M-o
triggered with `M-RET' or `C-M-RET'. If this variable holds a triggered with `M-RET' or `C-M-RET'. If this variable holds a
single action function, this action becomes the default action single action function, this action becomes the default action
and is assigned the key \"o\". For an action list, it is also and is assigned the key \"o\". For an action list, it is also
usual to assign the key \"o\" to the default action. usual to assign the key \"o\" to the default action." command)
It is in fact possible to include actions with a two-character
key in the list. To do so, however, it is necessary to also
include an action whose key is the first of these two characters
and whose action function is `counsel-projectile-prefix-action'." command)
:type '(choice :type '(choice
(function :tag "Single action function") (function :tag "Single action function")
(cons :tag "Action list" (cons :tag "Action list"
@ -248,37 +243,6 @@ If anything goes wrong, throw an error and do not modify ACTION-VAR."
(cdr action-list)))))) (cdr action-list))))))
(set action-var action-list))) (set action-var action-list)))
(defun counsel-projectile-prefix-action (cand)
"Generic action for a prefix key in any counsel-projectile command.
If used as action function in an action list, the corresponding
key will serve as a prefix key. That is, a secondary key will be
read from the minibuffer and the action from the list whose key
is the concatenation of these two keys will be called."
(let* ((action (ivy-state-action ivy-last))
(prefix (car (nth (car action) action)))
(sub-action (cl-loop
for a in (cdr action)
if (and (string-prefix-p prefix (car a))
(not (string= prefix (car a))))
collect (cons (substring (car a) (length prefix))
(cdr a))))
;; adapted from `ivy-read-action' from here on
(hint (funcall ivy-read-action-format-function sub-action))
(resize-mini-windows t)
(key (string (read-key hint)))
(action-fun (nth 1 (assoc key sub-action))))
(cond ((member key '("" ""))
(when (eq ivy-exit 'done)
(ivy-resume)))
((null action-fun)
(message "%s is not bound" key)
(when (eq ivy-exit 'done)
(ivy-resume)))
(t
(message "")
(funcall action-fun cand)))))
;;;; counsel-projectile-find-file ;;;; counsel-projectile-find-file
(counsel-projectile--defcustom-action (counsel-projectile--defcustom-action
@ -879,16 +843,12 @@ candidates list of `counsel-projectile-switch-project'."
"edit project dir-locals") "edit project dir-locals")
("v" counsel-projectile-switch-project-action-vc ("v" counsel-projectile-switch-project-action-vc
"open project in vc-dir / magit / monky") "open project in vc-dir / magit / monky")
("s" counsel-projectile-prefix-action
"search project with grep / ag / rg...")
("sg" counsel-projectile-switch-project-action-grep ("sg" counsel-projectile-switch-project-action-grep
"search project with grep") "search project with grep")
("ss" counsel-projectile-switch-project-action-ag ("ss" counsel-projectile-switch-project-action-ag
"search project with ag") "search project with ag")
("sr" counsel-projectile-switch-project-action-rg ("sr" counsel-projectile-switch-project-action-rg
"search project with rg") "search project with rg")
("x" counsel-projectile-prefix-action
"invoke shell / eshell / term from project root...")
("xs" counsel-projectile-switch-project-action-run-shell ("xs" counsel-projectile-switch-project-action-run-shell
"invoke shell from project root") "invoke shell from project root")
("xe" counsel-projectile-switch-project-action-run-eshell ("xe" counsel-projectile-switch-project-action-run-eshell