joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.23k stars 139 forks source link

Allowing Spaces to Work Like Hyphens When Completing (Corfu - Orderless Standardization) #646

Closed yuki-tsubaki closed 2 weeks ago

yuki-tsubaki commented 2 weeks ago

Context and Reasoning

I (and presumably some other people) like to use orderless with corfu for completions. I have been using space as the component separator. With the current completion functions in Slynk when I use a space (like I do in most other modes) it results in no results.

I can think of various ways to solve this (including many which can be done just within my init file so this isn't particularly bad as is--I'll cover them in a workaround section in case other people are looking for ideas).

That being said I just wanted to raise the idea here as changing this here might make it work a bit better out of the box for some people. (Thanks for your work on sly, by the way. It is definitely one of my favorite Emacs packages of all time.)

Idea

The simplest way I can think of to do this would just be to just add a pre-processing step that replaces all non-escaped spaces in the prefix with hyphens before doing the rest of the processing.

While spaces are allowed in symbol names according to the CL spec (so some support for this should be maintained in the completion framework), they seem to be rare enough that spaces being handled like - by default seems like a sane default (as I imagine space as a chunk separator is a more common thing than needing them to help select symbols that contain literal spaces).

Additionally if implemented in the Elisp portion of the code, it seems like an option to disable this could be added trivially.

Sidenote

I don't care because your completion is very well made, but if you or other people ever do want to make a mode that allows the completion sorting and stuff to be offloaded to orderless or some other system for some reason (as tangentially mentioned in #476), it seems like it would be pretty easy to get something working. The implementation on Geiser seems to do it (not as feature rich as the current one here but that could be added reasonably).

Workarounds

The cleanest in my opinion is just to set the orderless-component-seperator to accept spaces, hyphens, or slashes and then rebind the space (or whatever you use now) in corfu-mode to insert a hyphen rather than a space (it is one of the custom options so you can just set it with that or copy the value from there).

This allows you to continue to use spaces in things like minibuffer completion, use the keys you are used to in corfu-mode, and have it work in sly-mode stuff as well.