diff --git a/README.md b/README.md index a364d5d..52c6d58 100644 --- a/README.md +++ b/README.md @@ -87,27 +87,27 @@ Default key binding: C-c p p. 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 | -| :------------ | :-------------------------------------------------------------------------------------- | -| o | Jump to a project buffer or file: call `counsel-projectile` (default action; see above) | -| f | Jump to a project file: call `counsel-projectile-find-file` (see below) | -| d | Jump to a project directory: call `counsel-projectile-find-dir` (see below) | -| b | Jump to a project buffer: call `counsel-projectile-switch-to-buffer` (see below) | -| m | Find file manually: call `counsel-find-file` from the project root | -| S | Save all project buffers | -| k | Kill all project buffers | -| K | Remove project from the list of known projects | -| c | Run project compilation command | -| C | Run project configure command | -| E | Edit project directory-local variables | -| v | Open project in vc-dir / magit / monky | -| sg | Search project with grep: call `counsel-projectile-grep` (see below) | -| ss | Search project with ag: call `counsel-projectile-ag` (see below) | -| sr | Search project with rg: call `counsel-projectile-rg` (see below) | -| xs | Invoke shell from the project root | -| xe | Invoke eshell from the project root | -| xt | Invoke term from the project root | -| O | Org-capture into project: call `counsel-projectile-org-capture` (see below) | +| Key | Action | +| :------------- | :-------------------------------------------------------------------------------------- | +| o | Jump to a project buffer or file: call `counsel-projectile` (default action; see above) | +| f | Jump to a project file: call `counsel-projectile-find-file` (see below) | +| d | Jump to a project directory: call `counsel-projectile-find-dir` (see below) | +| b | Jump to a project buffer: call `counsel-projectile-switch-to-buffer` (see below) | +| m | Find file manually: call `counsel-find-file` from the project root | +| S | Save all project buffers | +| k | Kill all project buffers | +| K | Remove project from the list of known projects | +| c | Run project compilation command | +| C | Run project configure command | +| E | Edit project directory-local variables | +| v | Open project in vc-dir / magit / monky | +| s g | Search project with grep: call `counsel-projectile-grep` (see below) | +| s s | Search project with ag: call `counsel-projectile-ag` (see below) | +| s r | Search project with rg: call `counsel-projectile-rg` (see below) | +| x s | Invoke shell from the project root | +| x e | Invoke eshell from the project root | +| x t | Invoke term from the project root | +| O | Org-capture into project: call `counsel-projectile-org-capture` (see below) | ## The `counsel-projectile-find-file` command Default key binding: C-c p f. @@ -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 the index of the default action. 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 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 entry’s target slot, all instances of `${root}` and `${name}` are replaced with the current project root and name, respectively. diff --git a/counsel-projectile.el b/counsel-projectile.el index 95633dc..f64ccbb 100644 --- a/counsel-projectile.el +++ b/counsel-projectile.el @@ -73,7 +73,7 @@ consisting of: - the index of the default action in the list (1 for the first action, etc), - 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, - 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 single action function, this action becomes the default action and is assigned the key \"o\". For an action list, it is also -usual to assign the key \"o\" to the default action. - -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) +usual to assign the key \"o\" to the default action." command) :type '(choice (function :tag "Single action function") (cons :tag "Action list" @@ -248,37 +243,6 @@ If anything goes wrong, throw an error and do not modify ACTION-VAR." (cdr 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--defcustom-action @@ -879,16 +843,12 @@ candidates list of `counsel-projectile-switch-project'." "edit project dir-locals") ("v" counsel-projectile-switch-project-action-vc "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 "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") - ("x" counsel-projectile-prefix-action - "invoke shell / eshell / term from project root...") ("xs" counsel-projectile-switch-project-action-run-shell "invoke shell from project root") ("xe" counsel-projectile-switch-project-action-run-eshell