crzjp · 2022-05-21 16:23
example:
I'm going to open init.el and early-init.el
what I DON'T want:
type C-x C-f archive-name RET and then one more time to the other archive
what I want:
type C-x C-f, select the targets, RET and then open all
what I have:
emacs 28 + vertico + consult
(sorry for english misspelling)
oantolin · 2022-05-21 17:19
First a built-in solution: `find-file` will open all matching file if you give it a file name with wildcards, so `C-x C-f ~/.emacs.d/*init.el RET` will open both `init.el` and `early-init.el`. (And you can use TAB completion to complete the directory name.)
This means that if you turned Vertico *off* you could type a file name with wildcards and press `RET` to open all matching files. With Vertico *on* you can almost do the same thing except that `RET` always chooses a candidate if possible, so if the wilcard input matches any files, then you'd need to use `M-RET` to submit the wildcardy input literally.
Note that this works even if with your current `completion-styles` no file names are considered to match the wildcards! (Crazy, huh?)
(If you use `partial-completion` for file completion —either by having it in `completion-styles` so it is always on, or by having it in `(alist-get 'file completion-category-overrides)` so that you use it specifically for files—, then the wildcards *will* match the corresponding files, making the above procedure less disconcerting.)
OK, but what if you can't easily write an expression with wildcards that matches exactly the files you want? What if you want to open several files chosen higgledy–piggledy? In that case I'd recommend using Embark. While `find-file` is running Embark's default action will be `find-file` itsef, so you can use `embark-dwim` on a candidate to open it. If you use the default value of `embark-quit-after-action`, which is `t`, this will quit the minibuffer, so use `C-u` with `embark-dwim` to avoid that. I set `embark-quit-after-action` to `nil` in my personal configuration and I bind `embark-dwim` to `C-,`, so to open several files I just scroll through Vertico's list, hit `C-,` on the files I want and then `C-g` to quit `find-file` (or instead of `C-g`, I use `RET` on the last file I wish to open).
Another option also using Embark, is that if you can manage to match exactly the files you want to open, then you can open them all with `embark-act-all`: just run `embark-act-all` and hit `RET` to select the default action. You don't need a key binding for `embark-act-all`, because it is available as `A` from `embark-act`; so if you bind `embark-act` to `C-.`, say, then `C-. A RET` will open all the files currently matching your input. If you use a fancy completion style like `orderless`, it's usually not hard to get the input to match exactly the set of files you want. In your example of `init.el` and `early-init.el`, even using a completion style like `substring` and typing `init` is likely to match exactly the ones you want.
crzjp · 2022-05-21 17:50
I learned a lot, excellent explanation! I'll try the built in options first, but embark has been catching my attention for some time now. thank you!
Phil-Hudson · 2022-05-21 19:09
`C-x d`
00-11 · 2022-05-21 19:45
[This quick demo/description](https://www.emacswiki.org/emacs/Icicles_-_Nutshell_View#FlashyDemo) covers the following. All but the first one, which vanilla Emacs provides, are [Icicles](https://www.emacswiki.org/emacs/Icicles) features.
* Use of *glob patterns*, such as `*init.el`, with `RET` (mentioned by /u/oantolin). No completion involved (so no preview of which files match) -- just enter the pattern.
* Use of `RET` with [*multiple* such patterns](https://www.emacswiki.org/emacs/Icicles_-_Multi-Inputs) (multi-inputs), e.g., `C-x C-f ici*.el book*.el foo.* M-R RET`. Again, no completion involved; usable whenever anything is read from the minibuffer.
* Use of [multi-commands](https://www.emacswiki.org/emacs/multi-command), to *act on multiple* matching candidates (and repeatable), including acting on *all* of them at once (`C-!`). You can act on some candidates, change the pattern to match other candidates, act on some of those, etc.
* Use of [progressive completion](https://www.emacswiki.org/emacs/progressive_completion): match multiple patterns *sequentially*, each pattern filtering the results of filtering with the last (like Unix pipes). Each filtering is in a recursive minibuffer, so you can act on some matches (see previous), pop back out of the current filtering, type another pattern and act on some matches to it, etc.
* Use of [various kinds](https://www.emacswiki.org/emacs/Icicles_-_Completion_Methods_and_Styles) of pattern matching, including *regexp* ("apropos") matching. Not limited to `completion-styles`.
* Use of [multi-completion](https://www.emacswiki.org/emacs/multi-completion): match *different aspects or parts* of a thing at the same time, e.g. file name and file content, or name and date of last access. More flexible than vanilla `completing-read-multiple`.
shryzr · 2022-05-22 01:01
thank you for the awesome explanation. I was aiming to understand this at some point.
crzjp · 2022-06-17 22:27
> I set embark-quit-after-action to nil in my personal configuration and I bind embark-dwim to C-,, so to open several files I just scroll through Vertico's list, hit C-, on the files I want and then C-g to quit find-file (or instead of C-g, I use RET on the last file I wish to open).
sorry to reply old message but I'm not getting to the described behavior, I'm using your same setup but when I press C-, to embark-dwin it's immediately opening the selected target with also losing the minibuffer focus. Can you elaborate more?
oantolin · 2022-06-17 23:33
If you have the variable `embark-quit-after-action` set to the default value of `t`, embark should behave as you describe: quitting the minibuffer immediately.
You can either give `embark-dwim` a prefix argument using `C-u` for a one-off non-quitting action, or set the user option `embark-quit-after-action` to `nil` if you prefer embark to not quit the minibuffer by default.
oantolin · 2022-06-17 23:43
> embark-dwin it's immediately opening the selected target with also losing the minibuffer focus.
Oh, sorry I read too quickly! You mean the minibuffer stays open but loses focus? Yes, that is the expected behavior. I think I have switching back to the minibuffer so ingrained that I forgot to mention it.
crzjp · 2022-06-18 01:33
thank you for the response, Ill check my setup and try to set some other behavior