[ivy] counsel search commands use spacemacs--ivy-file-actions
spacemacs/counsel-search counsel-rg counsel-ag and counsel-find-file now share a comon set of actions defined in `spacemacs--ivy-file-actions`
This commit is contained in:
parent
497c767036
commit
03ab15ed36
|
@ -13,6 +13,7 @@
|
||||||
- [[#key-bindings][Key bindings]]
|
- [[#key-bindings][Key bindings]]
|
||||||
- [[#transient-state][Transient state]]
|
- [[#transient-state][Transient state]]
|
||||||
- [[#colorsfaces][Colors/Faces]]
|
- [[#colorsfaces][Colors/Faces]]
|
||||||
|
- [[#search-files-with-ivy][Search files with ivy]]
|
||||||
|
|
||||||
* Description
|
* Description
|
||||||
This layer enables Ivy for completion. It will replace the default completion by
|
This layer enables Ivy for completion. It will replace the default completion by
|
||||||
|
@ -140,3 +141,37 @@ are found in [[https://oremacs.com/swiper/#minibuffer-key-bindings][the Hydra se
|
||||||
| ~SPC C f~ | =counsel-colors-faces= |
|
| ~SPC C f~ | =counsel-colors-faces= |
|
||||||
| ~SPC C w~ | =counsel-colors-web= |
|
| ~SPC C w~ | =counsel-colors-web= |
|
||||||
| ~SPC h d F~ | =counsel-describe-face= |
|
| ~SPC h d F~ | =counsel-describe-face= |
|
||||||
|
|
||||||
|
** Search files with ivy
|
||||||
|
=ripgrep= is recommended and =Spacemacs= will pick it up as the default seach
|
||||||
|
app if found. To pass parameters to =ripgrep= use double dash then everything
|
||||||
|
after it is treated as parameters for search app.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
#+begin_src
|
||||||
|
phrase I want to search -- -tlisp
|
||||||
|
#+end_src
|
||||||
|
will search only on lisp files.
|
||||||
|
|
||||||
|
Commands available while browsing the search result:
|
||||||
|
|
||||||
|
| Key binding | Description |
|
||||||
|
|------------------+----------------------------------|
|
||||||
|
| ~C-SPC~ or ~C-l~ | Preview result |
|
||||||
|
| ~C-x C-d~ | Change search folder |
|
||||||
|
| ~M-q~ | =counsel-git-grep-query-replace= |
|
||||||
|
| ~C-c C-o~ | =ivy-occur= |
|
||||||
|
| ~C-c C-e~ | Spacemacs's =counsel-edit= |
|
||||||
|
|
||||||
|
When you =M-o= on the result list of =counsel-find-file= and file search result
|
||||||
|
you have these following extra actions:
|
||||||
|
|
||||||
|
| Key binding | Description |
|
||||||
|
|-------------+---------------------------------|
|
||||||
|
| ~f~ | =find-file-other-frame= |
|
||||||
|
| ~j~ | =find-file-other-window= |
|
||||||
|
| ~v~ | =spacemacs/find-file-vsplit= |
|
||||||
|
| ~s~ | =spacemacs/find-file-split= |
|
||||||
|
| ~l~ | =find-file-literally= |
|
||||||
|
| ~d~ | =spacemacs/delete-file-confirm= |
|
||||||
|
| ~r~ | =spacemacs/rename-file= |
|
||||||
|
|
|
@ -361,18 +361,27 @@ To prevent this error we just wrap `describe-mode' to defeat the
|
||||||
(call-interactively 'describe-mode))))
|
(call-interactively 'describe-mode))))
|
||||||
|
|
||||||
(defun spacemacs//counsel-with-git-grep (func x)
|
(defun spacemacs//counsel-with-git-grep (func x)
|
||||||
|
"This function should be kept in sync with `counsel-git-grep-action'.
|
||||||
|
|
||||||
|
We copy exactly that function and modify it a bit which allows us
|
||||||
|
to programatically add extra actions to counsel git-grep based
|
||||||
|
commands."
|
||||||
(when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" x)
|
(when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" x)
|
||||||
(with-ivy-window
|
(let ((file-name (match-string-no-properties 1 x))
|
||||||
(let ((file-name (match-string-no-properties 1 x))
|
(line-number (match-string-no-properties 2 x)))
|
||||||
(line-number (match-string-no-properties 2 x)))
|
;; this line is the difference to `counsel-git-grep-action'
|
||||||
(funcall func
|
(funcall func
|
||||||
(expand-file-name file-name (ivy-state-directory ivy-last)))
|
(expand-file-name file-name (ivy-state-directory ivy-last)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(forward-line (1- (string-to-number line-number)))
|
(forward-line (1- (string-to-number line-number)))
|
||||||
(re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
|
(when (re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
|
||||||
(unless (eq ivy-exit 'done)
|
(when swiper-goto-start-of-match
|
||||||
(swiper--cleanup)
|
(goto-char (match-beginning 0))))
|
||||||
(swiper--add-overlays (ivy--regex ivy-text)))))))
|
(swiper--ensure-visible)
|
||||||
|
(run-hooks 'counsel-grep-post-action-hook)
|
||||||
|
(unless (eq ivy-exit 'done)
|
||||||
|
(swiper--cleanup)
|
||||||
|
(swiper--add-overlays (ivy--regex ivy-text))))))
|
||||||
|
|
||||||
;;; org
|
;;; org
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,11 @@
|
||||||
'counsel-find-file
|
'counsel-find-file
|
||||||
spacemacs--ivy-file-actions)
|
spacemacs--ivy-file-actions)
|
||||||
|
|
||||||
|
(dolist (action '(spacemacs/counsel-search counsel-rg counsel-ag))
|
||||||
|
(ivy-set-actions
|
||||||
|
action
|
||||||
|
spacemacs--ivy-grep-actions))
|
||||||
|
|
||||||
(when (or (eq 'vim dotspacemacs-editing-style)
|
(when (or (eq 'vim dotspacemacs-editing-style)
|
||||||
(and (eq 'hybrid dotspacemacs-editing-style)
|
(and (eq 'hybrid dotspacemacs-editing-style)
|
||||||
hybrid-style-enable-hjkl-bindings))
|
hybrid-style-enable-hjkl-bindings))
|
||||||
|
|
Loading…
Reference in New Issue