Moelf / JLFzf.jl

Julia bind to fzf fuzzy finder
MIT License
15 stars 5 forks source link

Fuzzy Tab Completion? #9

Open carlocab opened 3 years ago

carlocab commented 3 years ago

Thanks for putting this package together!

I was wondering if it were also possible to use JLFzf for fuzzy tab completion. I am thinking something along the lines of [1] or [2]. JLFzf would capture the results returned by Julia's built-in tab completion system, allowing the user to use fzf to search among the results.

The key seems to be the complete_line and show_completions functions in LineEdit.jl, but I haven't yet figured out how these functions work.

I'll open a PR if I manage to do so, but I thought to open this issue in case someone here already knows how to do this.

One complication is that fzf probably shouldn't be called when tab completion returns the available methods, as shown in the docs, since the output isn't something you actually want to paste into the REPL directly.

Moelf commented 3 years ago

i personally think fzf tab completion is not all that useful because usually functions / fields are just 1 word. you either remember or not

carlocab commented 3 years ago

Well, that's the point of fzf: it's really useful in cases you don't remember. Also, I just don't think that's true at all. Fzf completion could be really useful for exploring the objects of packages that are new to you.

Bear in mind that tab completion isn't just for completing functions or fields, but also for the completion of paths/filenames (which seems to be the primary use-case of fzf, and would integrate nicely with the the --preview option), dictionary keys, or even unicode input.

Fuzzy search might actually be the key to a lot of users being able to take full advantage of the rather large number of Unicode symbols available to them in Julia. For example, try typing \bi in your REPL and invoking tab completion.

Moelf commented 3 years ago

again, for Unicode, you need to know what symbol is called (in LaTeX) anyways. For example, you see ⟉, there's no way to "fzf" search it without knowing it's called something like \sushsol. Path completion I can imagine being useful.

Also, because JLFzf originally was aimed to be a thin wrapper around fzf_jll, I think stuff like "replace tab completion behavior with fzf" should likely go into another package, or even just be part of LSPrelated stuff in your editor: https://github.com/nvim-lua/telescope.nvim

carlocab commented 3 years ago

Maybe for a naive implementation of Unicode completion fuzzy-find, what you say about \suphsol is true occasionally. Perhaps the better implementation would be to be able to search keywords, character descriptions, and include a preview window that renders the character in question. Of course, this would be way more complicated, but I think would prove helpful even in the case you describe. (And I'll mention that \suphsol isn't even available as an input in Julia, so perhaps it's not a great example.)

Second, I think you underestimate how often people have a vague idea of the keyword for a Unicode character, but just can't remember the exact keyword. I think the naive implementation would be useful even in this case.

Third, I will mention that the feature I describe is practically part of vanilla CLI fzf, just like fuzzy history search. The standard completions for fzf include the ** completion (which is basically a step away from tab completion) and kill <Tab> PID completion. The completion I'm talking about doesn't even need to be bound to tab. It could just work similarly to fzf's CTRL-T, just like your wrapper replicates the CTRL-R behaviour. So I think a big part of some of the features I describe do fit in a thin wrapper for fzf (and maybe rebinding some of the completion behaviour to tab and the more complicated features like the one I describe above can go elsewhere if you prefer).

I really don't understand your last comment -- we're discussing using fzf in the Julia REPL, so I'm not sure how this is related to editor integration. You don't even need to be using an editor at all to take advantage of the completion I'm talking about.

Anyway, it seems like you're quite against this, so I don't mind closing this issue and trying to pursue the idea elsewhere. However, I do think these features could be implemented in a way that could be really useful -- if not for you (though hopefully for you too), then for a lot of other people.

Moelf commented 3 years ago

First let me just say, I'm not against a PR that facilitates tab completion for module or unicode etc. But I want to stress that:

just like your wrapper replicates the CTRL-R behaviour.

is false. using JLFzf does not change any behavior of the REPL, unlike OhMyREPL.jl, which is where the "magic" happen. You can think of JLFzf's existence as to help other pacakges just like OhMyREPL to have fzf functionality.

In its core, fzf just means "given a list of strings, drop into fuzzy search, return the selected one", notice in the Unicode example, what you search is not what you get back, this is not canonical fzf anymore. (or I guess you can get back and tab again)

I do like the fzf completion after blah. though, potentially we can make a helper function for that kind of tools in here.

carlocab commented 3 years ago

I'm not against a PR that facilitates tab completion for module or unicode etc.

Great! That's really all I was asking:

I was wondering if it were also possible to use JLFzf for fuzzy tab completion.

pdeffebach commented 2 years ago

Bumping this issue. Thanks for the wonderful package!

I think this is a good feature. I've been using Stata a lot recently for a data set with many many columns (a long survey). Stata has a great feature where you can start typing in a search box and it narrows down the columns that match your search as you type.

Something like that would be super useful in Julia (especially with the incoming column metadata functionality).

I don't necessarily want to override current tab behavior, but if there were some sort of interactive hotkey that wasn't tab, it would be very welcome.

Moelf commented 2 years ago

I think such PR would be more welcomed in OhMyREPL.jl but we can experiment with that here.

I think basically

  1. find out what happens when user press tab in normal REPL
  2. mimic that except pass through the fzf before completing the result