Doom-emacs: Open all matching files from "search project" (SPM s p) results

Created on 2 Mar 2020  Â·  5Comments  Â·  Source: hlissner/doom-emacs

Please visit our Discord server to ask how-to and workflow questions:
https://discord.gg/qvGgnVx -- post on Doom's issue tracker as a last resort.

What are you trying to achieve?
Open all the files (in different buffers) which match a pattern.

What have you tried?
SPC s p, which launches ripgrep and shows the results in a list. Currently I need to open SPC s p repeatedly, type in the search pattern again and open the next file in list.

System information


((emacs
(version . "26.3")
(features . "NOTIFY ACL GNUTLS LIBXML2 ZLIB MODULES THREADS")
(build . "Oct 01, 2019")
(buildopts "--disable-dependency-tracking --disable-silent-rules --enable-locallisppath=/usr/local/share/emacs/site-lisp --infodir=/usr/local/Cellar/emacs/26.3/share/info/emacs --prefix=/usr/local/Cellar/emacs/26.3 --with-gnutls --without-x --with-xml2 --without-dbus --with-modules --without-ns --without-imagemagick")
(windowsys . batch)
(daemonp . server-running))
(doom
(version . "2.0.9")
(build . "HEAD -> develop 12249753e 2020-02-22 20:40:03 -0500")
(dir . "~/.rc/doom.d/"))
(system
(type . darwin)
(config . "x86_64-apple-darwin19.0.0")
(shell . "/bin/zsh")
(uname . "Darwin 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64")
(path "~/.nimble/bin" "~/opt/python-language-server/output/bin/Release/osx-x64/publish" "/usr/local/opt/python/libexec/bin" "~/.miniconda3/bin" "/usr/local/bin" "/usr/bin" "/bin" "/usr/sbin" "/sbin" "/opt/X11/bin" "~/.cabal/bin" "/usr/local/MacGPG2/bin" "/usr/local/sbin" "/Applications/DevDesktop/drush" "/usr/local/texlive/2016/bin/x86_64-darwin" "/Library/TeX/texbin" "~/.emacs.d/bin" "/usr/local/Cellar/emacs/26.3/libexec/emacs/26.3/x86_64-apple-darwin19.0.0"))
(config
(envfile . envvar-file)
(elc-files . 0)
(modules :completion company (ivy +fuzzy) :ui doom doom-dashboard fill-column hl-todo modeline nav-flash ophints (popup +all +defaults) tabs treemacs workspaces :editor (evil +everywhere) file-templates multiple-cursors snippets :emacs dired electric ibuffer vc :term eshell shell term vterm :checkers syntax spell grammar :tools direnv (eval +overlay) (lookup +docsets) lsp magit :lang data emacs-lisp julia (latex +latexmk) markdown (org +jupyter +pandoc +present) (python +lsp) rst sh :email mu4e :app calendar :config (default +bindings +smartparens))
(packages . "<(void-function sp-point-in-string)>")
(elpa "n/a")
(unpin "n/a")))

:completion helm :completion ivy question resolved

Most helpful comment

You can open a permanent, occur buffer from your search results with C-c C-o, or you can repeat the last ivy search with SPC '. You could also define a custom ivy action for counsel-rg to open all candidates:

(after! counsel
  (ivy-add-actions
   #'counsel-rg
   '(("a" (lambda (_path) (mapc #'counsel-git-grep-action ivy--all-candidates))
      "Open all matches"))))

Then C-o a from the search results will open all matches.

Hope that helps!

All 5 comments

You can open a permanent, occur buffer from your search results with C-c C-o, or you can repeat the last ivy search with SPC '. You could also define a custom ivy action for counsel-rg to open all candidates:

(after! counsel
  (ivy-add-actions
   #'counsel-rg
   '(("a" (lambda (_path) (mapc #'counsel-git-grep-action ivy--all-candidates))
      "Open all matches"))))

Then C-o a from the search results will open all matches.

Hope that helps!

Perfect, thanks!

@hlissner Can you also provide the equivalent "open all matches" for projectile-find-file, reachable via SPC SPC (or SPC p f)?

@krei-del That's tricky, because SPC SPC uses one of four commands depending on the performance requirements, but:

(after! counsel
  (dolist (cmd '(counsel-find-file counsel-projectile-find-file projectile-find-file counsel-file-jump))
    (ivy-add-actions
     cmd
     '(("a" (lambda (_path) (mapc #'counsel-git-grep-action ivy--all-candidates))
        "Open all matches")))))

@hlissner _Thanks a lot for your quick support!!_ ... Unfortunately the last step is not working ... no files will be opened..
As I can see the new menu item "a: Open all matches" I expect the issue is in line

'(("a" (lambda (_path) (mapc #'counsel-git-grep-action ivy--all-candidates))

But I do not know any (e)lisp (unfortunately again) .. just a wild guess: maybe the _path 'variable' is named differently in counsil-find-file, counsel-projectile-find-file, ...

Was this page helpful?
0 / 5 - 0 ratings