diff --git a/README.org b/README.org index c3956d4..901489e 100644 --- a/README.org +++ b/README.org @@ -6,22 +6,29 @@ :PROPERTIES: :CUSTOM_ID: description :END: + [[https://github.com/bbatsov/projectile][Projectile]] has native support for using [[https://github.com/abo-abo/swiper][ivy]] as its completion system. Counsel-projectile provides further ivy integration into projectile by taking advantage of ivy's support for selecting from a list of actions and applying an action without leaving the completion session. Concretely, counsel-projectile defines replacements for existing projectile commands as well as new commands that have no projectile counterparts. A minor mode is also provided that adds key bindings for all these commands on top of the projectile key bindings. + * News :PROPERTIES: :CUSTOM_ID: news :END: + - [2017-12-18] New version ~0.2~. If you are upgrading from ~0.1~, please read [[#upgrading][here]] about important changes. - [2016-04-12] First version ~0.1~. + * Installation :PROPERTIES: :CUSTOM_ID: installation :END: + Install the package from [[https://melpa.org][MELPA]] or [[https://github.com/dimitri/el-get][el-get]], or clone this repository somewhere in your load path. + * Usage :PROPERTIES: :CUSTOM_ID: usage :END: + ** Getting started :PROPERTIES: :CUSTOM_ID: start @@ -34,11 +41,14 @@ The counsel-projectile key bindings either remap existing projectile commands to 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. Note that if you turn on projectile mode but not counsel-projectile mode, the counsel-projectile commands can still be called with ~M-x~, only the key bindings for these commands are not enabled. + ** Summary of interactive commands :PROPERTIES: :CUSTOM_ID: commands :END: + Replacements for existing commands: + | Key binding | Command | Description | |-------------+---------------------------------------+-----------------------------| | ~C-c p p~ | ~counsel-projectile-switch-project~ | Switch project | @@ -49,15 +59,19 @@ Replacements for existing commands: | ~C-c p s s~ | ~counsel-projectile-ag~ | Search project with ag | New commands: + | Key binding | Command | Description | |-------------+----------------------------------+-----------------------------------------------------| | ~C-c p SPC~ | ~counsel-projectile~ | Jump to a project buffer or file, or switch project | | ~C-c p s r~ | ~counsel-projectile-rg~ | Search project with rg | | ~C-c p O~ | ~counsel-projectile-org-capture~ | Org-capture into project | + ** The ~counsel-projectile~ command + Default key binding: ~C-c p SPC~. This command lets you quickly jump to a project buffer or file. It uses ivy to display in the minibuffer a list of all project buffers as well as all project files that are not currently visited by a buffer. Buffers are fontified according to their major mode and files are fontified as "virtual buffers", as in the command ~ivy-switch-buffer~. As in all ivy commands, you can use ~M-o~ / ~C-M-o~ + ~~ to select from a list of actions to apply (or ~M-RET~ / ~C-M-REG~ to apply the default action) to the selected candidate: + | Key | Action | |-----+------------------------------------------------------------------------------| | ~o~ | Open buffer or file in current window (default action) | @@ -68,10 +82,13 @@ This command lets you quickly jump to a project buffer or file. It uses ivy to d | ~p~ | Switch project: call ~counsel-projectile-switch-project~ (see below) | If not called inside a project, ~counsel-projectile~ first offers to select a project to switch to by calling ~counsel-projectile-switch-project~ (see below). Once you select a project and hit ~RET~, it lets you jump to a buffer or file in this project as described above. + ** ~counsel-projectile-switch-project~ + 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) | @@ -93,7 +110,9 @@ This command is a replacement for ~projectile-switch-project~. It adds the possi | ~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) | + ** ~counsel-projectile-find-file~ + Default key binding: ~C-c p f~. This command is a replacement for ~projectile-find-file~. It displays a list of all project files and offers several actions: @@ -105,55 +124,75 @@ This command is a replacement for ~projectile-find-file~. It displays a list of | ~r~ | Open file as root (does nothing for buffers) | | ~m~ | Find file manually: call ~counsel-find-file~ from file's directory | | ~p~ | Switch project: call ~counsel-projectile-switch-project~ (see above) | + ** ~counsel-projectile-find-dir~ + Default key binding: ~C-c p d~. This command is a replacement for ~projectile-find-dir~. It displays a list of all project directories and offers several actions: + | Key | Action | |-----+----------------------------------------------------------------------| | ~o~ | Open directory with ~dired~ in current window (default action) | | ~j~ | Open director with ~dired~ in other window | | ~m~ | Find file manually: call ~counsel-find-file~ from directory | | ~p~ | Switch project: call ~counsel-projectile-switch-project~ (see above) | + ** ~counsel-projectile-switch-to-buffer~ + Default key binding: ~C-c p b~. This command is a replacement for ~projectile-switch-to-buffer~. It displays a list of all project buffers and offers several actions: + | Key | Action | |-----+----------------------------------------------------------------------| | ~o~ | Open buffer in current window (default action) | | ~j~ | Open buffer in other window | | ~m~ | Find file manually: call ~counsel-find-file~ from buffer's directory | | ~p~ | Switch project: call ~counsel-projectile-switch-project~ (see above) | + ** ~counsel-projectile-grep~ + Default key binding: ~C-c p s g~. This command is a replacement for ~projectile-grep~. It searches all project files with ~grep~, taking advantage of ivy's support for updating the list of candidates after each input (dynamic collections). Each canidate corresponds to a matching line in some project file, and there is only one action that opens that file at that line. + ** ~counsel-projectile-ag~ + Default key binding: ~C-c p s s~. This command is a replacement for ~projectile-ag~. It is similar to ~counsel-projectile-grep~ (see above) but uses ~ag~ (the silver searcher) instead of ~grep~. + ** ~counsel-projectile-rg~ + Default key binding: ~C-c p s r~. This command is similar to ~counsel-projectile-grep~ (see above) but uses ~rg~ (ripgrep) instead of ~grep~. + ** ~counsel-projectile-org-capture~ + Default key binding: ~C-c p O~. This command lets you capture something (a note, todo item...) into the current project using org-mode's ~org-capture~. Like ~org-capture~, it first lets you select a capture template then file the newly captured information. By default, there is a single template storing the captured information into file \"notes.org\" in the project root directory, under headline ~Tasks~. + * Configuration :PROPERTIES: :CUSTOM_ID: config :END: + ** 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. + ** Customizing action lists :PROPERTIES: -:CUSTOM_ID: config/action +:CUSTOM_ID: config-action :END: + 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 through the Customize interface or directly with ~setq~, the new value will be picked up the next time you invoke the correspodiding commmand. The variable holding the action list for ~command~ is named ~command-action~. The following action list variables are defined: + - ~counsel-projectile-action~ - ~counsel-projectile-switch-project-action~ - ~counsel-projectile-find-file-action~ @@ -161,6 +200,7 @@ The variable holding the action list for ~command~ is named ~command-action~. Th - ~counsel-projectile-switch-to-buffer-action~ For instance, the default value of ~counsel-projectile-action~ is: + #+BEGIN_SRC emacs-lisp '(1 ("o" counsel-projectile-action @@ -176,11 +216,13 @@ For instance, the default value of ~counsel-projectile-action~ is: ("p" (lambda (_) (counsel-projectile-switch-project)) "switch project")) #+END_SRC + The first element is the index of the default action, and the remainig ones are the available actions (a key, an action function, and a name for each action). Thus the default action in this list is the first one ("current window"). Extra actions can be added to these lists or, alternatively, can be set through ivy's ~ivy-set-actions~ mechanism. If you prefer setting all actions (except the default one) through this mechanism, you can set the action list variable to a single action (e.g. ~counsel-projectile-action~) instead of a list. Note that ivy only supports one-character keys for actions. Hence, for instance, it is not possible to directly set the keys ~s g~, ~s s~, and ~s r~ for the three project search commands in ~projectile-switch-project-action~. Instead, the key ~s~ is set for a "prefix" action ~counsel-projectile-switch-project-action-prefix-search~ that reads a secondary one-character key and calls the corresponding search command as a "sub-action". The list of available sub-actions is read from the variable ~counsel-projectile-switch-project-action-prefix-search-sub-action~, which can be customized separately. This variable has the same format as an action list, except that the index is not present. Its default value is: + #+BEGIN_SRC emacs-lisp '(("g" counsel-projectile-switch-project-action-grep "Search project with grep") @@ -191,51 +233,70 @@ Note that ivy only supports one-character keys for actions. Hence, for instance, #+END_SRC The following sub-action variables are defined: + - ~counsel-projectile-switch-project-action-prefix-search-sub-action~ - ~counsel-projectile-switch-project-action-prefix-shell-sub-action~ + ** 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. + +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. The default value contains a single template, whose target is: + #+BEGIN_SRC emacs-lisp (file+headline "${root}/notes.org}" "Tasks") #+END_SRC + This points to headline "Tasks" in file "notes.org" in the project root directory (one file per project). Another example of a valid target is: + #+BEGIN_SRC emacs-lisp (file+olp "~/notes.org" "${root}" "Tasks") #+END_SRC - (file+olp "~/notes.org" "${root}" "Tasks") + This points to outline path "/Tasks" in file "~/notes.org" (same file for all projects). Templates contexts are read from the variable ~counsel-projectile-org-capture-templates-contexts~, which has the same format as ~capture-templates-contexts~ + ** Removing the current project or buffer from the list of candidates + By default, when calling ~counsel-projectile-switch-project~, the current project (if any) is included in the candidates list and preselected. Similarly, when calling ~counsel-projectile-switch-to-buffer~, the current buffer is included in the candidates list and preselected. If you prefer removing these elements from the candidate lists of these commands, you can set the variables ~counsel-projectile-remove-current-project~ and ~counsel-projectile-remove-current-buffer~ accordingly. + ** Initial input for the project search commands If you want some initial input to be inserted in the minibuffer every time you call ~counsel-projectile-grep~, ~counsel-projectile-ag~, or ~counsel-projectile-rg~, you can customize the variables ~counsel-projectile-grep-initial-input~, ~counsel-projectile-ag-initial-input~, or ~counsel-projectile-rg-initial-input~ accordingly. Each of these variable, if non ~nil~, should hold a Lisp expression whose evaluation yields the initial input string. If you use the Customize interface, some choices are proposed based on various versions of the ~thing-at-point~ function. Note that you can always insert the value of ~(ivy-thing-at-point)~ by hitting ~M-n~ in the minibuffer. + * Upgrading from previous version (~0.1~) :PROPERTIES: :CUSTOM_ID: upgrading :END: + If you are upgrading from version ~0.1~ to version ~0.2~, please read below about important changes, some of which may require you to update your configuration. ** Key bindings The commands ~counsel-projectile-on~, ~counsel-projectile-off~ and ~counsel-projectile-toggle~ no longer exist. They are replaced by the counsel-projectile minor mode. You can toggle this mode either by calling the ~counsel-projectile-mode~ command. or by setting the ~counsel-projectile-mode~ variable throught the Customize interface. See [[#start][Getting started]] above for details. + ** Action lists + The available actions for the various counsel-projectile commands are now customized differently: - - The custom variable corresponding to ~command~ is now named ~command-action~, not ~command-actions~. - - This variable now stores all the available actions, including the default action, not only the extra actions. - - It also stores the index of the default action (it is a list whose first element is this index and whose remaining elements are the availabe actions). - - This variable is now used as the value of the ~:action~ parameter for the command's ~ivy-read~ call. Hence if you set it outside the Customize interface, you no longer need to call ~ivy-set-actions~ afterwards. If you set extra actions through ~ivy-set-actions~, they will not replace the variable's actions but will rather be added to them. -See [[#config/action][Customizing action lists]] above for details. + +- The custom variable corresponding to ~command~ is now named ~command-action~, not ~command-actions~. +- This variable now stores all the available actions, including the default action, not only the extra actions. +- It also stores the index of the default action (it is a list whose first element is this index and whose remaining elements are the availabe actions). +- This variable is now used as the value of the ~:action~ parameter for the command's ~ivy-read~ call. Hence if you set it outside the Customize interface, you no longer need to call ~ivy-set-actions~ afterwards. If you set extra actions through ~ivy-set-actions~, they will not replace the variable's actions but will rather be added to them. + +See [[#config-action][Customizing action lists]] above for details. Also, in the default action lists, the keys set for some actions have changed, mainly for the ~counsel-projectile-switch-project~ command. Indeed, as new actions were added to this command, the corresponding list of keys was becoming somewhat inconsistent. The new keys replicate the default projectile key bindings (for instance, the aciton to save all project buffers is now called with the key ~S~, mimicking the default key binding ~C-c p S~ for the command ~projectile-save-project-buffers~). When an action calls a command that has no default projectile key binding, its key is chosen among those that are not bound by projectile by default. + ** Minibuffer keymap + The minibuffer keymap ~counsel-projectile-map~ no longer exists. It was only used to bind a key (~M-SPC~ by default) to the command ~counsel-projectile-drop-to-switch-project~ exiting the current command and calling ~counsel-projectile-switch-project~. The same functionality is now implemented in a simpler way through an aciton that calls ~counsel-projectile-switch-project~, whose key is ~p~ by default. Concretely, you should now hit ~M-o p~ instead of ~M-SPC~. + * Contributors :PROPERTIES: :CUSTOM_ID: contributors :END: + Counsel-projectile is inspired by [[https://github.com/bbatsov/helm-projectile][helm-projectile]]. Many thanks to [[https://github.com/abo-abo][abo-abo]] and [[https://github.com/DamienCassou][DamienCassou]] who encouraged and helped me to start this repository, as well as all contributors and users who have submitted issues and pull requests.