bhauman / rebel-readline

Terminal readline library for Clojure dialects
Eclipse Public License 1.0
684 stars 37 forks source link

Completion not really useful #148

Closed mbuczko closed 6 years ago

mbuczko commented 6 years ago

At the beginning, thanks for a great work to make REPL bit more civilized.

Now, a word about the completion system. To be honest I find it a bit awkward rather than helpful. Hitting a tab opens menu which is no way interactively narrowed by subsequent key presses. That simply means, if I type "m " and I'll get over 10 possible completion candidates I have to read each of them to decide which one I wanted to type originally and navigate with arrows in that location. It takes way more time than typing the same phrase without completion.

Well, yes, I know I can switch completion off, but this mechanism is too valuable to simply give up :)

I tried to analyze what jline offers underneath and surprisingly its default completion system is exactly what I wanted to see, ie. hitting a tab opens menu with completion candidates but still allows to type and narrows menu respectively. Hitting tab again "activates" menu (if there is more than 1 candidate) which usually means selecting an option from up to 2-3 candidates.

So the next question was, why rebel-readline does not use this kind of completion and forces me to select option from menu right after hitting a tab. Looks like it's a widget which is called in line-reader:

(call-widget LineReader/MENU_COMPLETE))

if we could use a COMPLETE_WORD instead, we will get a completion behavior similar to what jline offers out of the box:

(call-widget LineReader/COMPLETE_WORD))

This makes completion much more convenient. The only problem here is that subsequent typing erases menu instead of narrowing. Looking again at the code, seems like it's caused by clojure-self-insert widget bound here:

(key-binding (KeyMap/range " -~") "clojure-self-insert")

commenting this line out makes completion mechanism working ideally, but yeah, we're losing hints and probably more which I'm not aware of.

The question is, do you think that completion thing is something worth to be improved? If so, I'm happy to help, but would like to start this discussion first to be sure we are not trying to improve something that most of people feel already quite comfortable with :)

bhauman commented 6 years ago

I agree with you here, this is the behavior I want as well. If you are interested in sending a PR or simply doing more research to discover what is needed to modify "clojure-self-insert" to make this work that would be very helpful.

mbuczko commented 6 years ago

Ok, I created a PR which instead of calling LineReader/SELF_INSERT from a widget (which erases menu with options to complete) simply extends LineReaderImpl's selfInsert method and calls directly a clojure-self-insert from inside. By all means I'm not a jline expert so I'm not really sure how it looks like from "architectural" point of view, but at least works for me :)