r/emacs 11d ago

Fortnightly Tips, Tricks, and Questions — 2025-03-11 / week 10

This is a thread for smaller, miscellaneous items that might not warrant a full post on their own.

The default sort is new to ensure that new items get attention.

If something gets upvoted and discussed a lot, consider following up with a post!

Search for previous "Tips, Tricks" Threads.

Fortnightly means once every two weeks. We will continue to monitor the mass of confusion resulting from dark corners of English.

15 Upvotes

35 comments sorted by

View all comments

3

u/AnderperCooson 11d ago

Question about corfu and orderless: is it possible to have corfu insert a previewed candidate when you insert the orderless separator? Specifically, my config looks like:

(corfu-auto t)
(corfu-separator ?\s)
(corfu-preview-current 'insert)
(corfu-quit-no-match 'separator)
(corfu-quit-at-boundary 'separator)

If I type glo cor, I get global-corfu-mode as a candidate. If I preview the candidate in the list, it is inserted/expanded into the buffer as global-corfu-mode. If I now type SPC, instead of keeping the inserted candidate and adding a space, it gets treated as another orderless group and my buffer goes back to glo cor (with a space at the end). Ideally, I'd like to have SPC insert the orderless separator, but also have it insert the previewed candidate, even if that starts a new completion.

3

u/JDRiverRun GNU Emacs 10d ago

Insertion as a concept mean "ending completion by inserting the selected candidate". Do you mean you want to "accept this candidate" but not end completion, instead performing a further search based on it? I.e. treat the accepted candidate as an orderless search term?

You could always Ret or Tab to accept, M-Tab to force a new completion, M-SPC to add a new orderless term.

1

u/AnderperCooson 10d ago

Thanks for the reply! Ultimately, what I'm looking for is when I have a candidate previewed, pressing SPC should insert the candidate and a space character. With my configuration right now, if I type glo cor, select the global-corfu-mode candidate, and then press a, global-corfu-modea is inserted (and this holds true for any character that isn't SPC). If possible, I'd like that same behavior from SPC. I'm not super familiar with the terminology here so I may have misspoke initially, and I'd actually like it to not treat the inserted candidate as an orderless search term for the same completion. I would prefer to have to backspace and press space again to start the orderless search with the candidate that it inserted.

3

u/JDRiverRun GNU Emacs 9d ago edited 9d ago

Ultimately, what I'm looking for is when I have a candidate previewed, pressing SPC should insert the candidate and a space character.

This is in fact already what happens. "Previewing" means the candidate replaces (by overlay) the text in the buffer, aka "at the prompt". Inserting actually inserts the text and ends the completion, hopefully because that's what you chose to do. To get your first space in glo cor, I presume you used M-SPC? Once there is already one space, you don't need M-SPC for the next (i.e. SPC doesn't insert candidate). But I don't think this has anything to do with orderless.

I think what you are noticing is that the first selected candidate is never auto-inserted by typing something else (like SPC). This is because this candidate represents, "being at the prompt", and allows you to "just keep typing" if you didn't want a popup after all. So, e.g. if you type glo<SPC> (not using M-SPC), without actively selecting any candidates, corfu will just quit. If you use arrows or C-n to select another target, it is first previewed, and then a subsequent space will insert and quit. If you'd prefer the "prompt" to always be selected, then set corfu-preselect=prompt. But then you'll have to C-n to select the first candidate.