saikyun / freja

Self-modifiable editor for coding graphical things
66 stars 2 forks source link

Some aid in entering file paths #6

Open sogaiu opened 3 years ago

sogaiu commented 3 years ago

It would be nice to not have to type every character of a file path when trying to open a file as the probability of errors might grow as the length of the file path grows.

I'm hoping there is a simple way to achieve this that doesn't take much effort.

I guess some obvious (not necessarily simple) vague ideas are:

saikyun commented 3 years ago

One way to do completion:

  1. bind hotkey like tab: (set-key file-open-data [:tab] autocomplete-file)
  2. autocomplete-file can look like this:
    (defn autocomplete-file
    [props]
    (def partial-path (content props)) # `content` just turns the contents of a text area into a string
    (def folder (peg/match peg-for-getting-everything-but-the-stuff-after-last-slash partial-path))
    (def partial-file-name (peg/match peg-for-getting-everything-after-last-slash partial-path))
    (def files (get-files-in-folder folder))
    (def matches (filter |(string/starts-with $ partial-file-name) files))
    (case (length matches)
    0 (print "No match")
    1 (replace-content props (string folder "/" (first matches)))
    (do (print "Multiple matches:")
     (pp matches))))
saikyun commented 3 years ago

I'd like to figure out some way to make this a general thing, e.g. like helm. This way one could use the same filtering ui for both opening files, jumping to definitions and autocomplete. I guess the most basic way to start would be to imitate helm. I like helm.

sogaiu commented 3 years ago

From the user's perspective it might be less to have to learn as well.

I don't have a very clear idea of how the various helm-like things differ. May be it makes sense to start sketching out what you like?

My first encounter with a similar UI in Emacs was helm's predecessor "anywhere" (I think that's what it was called). But before that I had used QuickSilver (QS) on various macs. By now I think some of the core ideas have spread to various other places too (or discovered independently or imitated from elsewhere).

I'll mention a few things that I found particularly nice about this general sort of thing. May be you can share what you like too.

1) The ability to bring up a "prompt" or some UI for entry in a fairly ubiquitous fashion. For QS, this was pretty much no matter what application was in the foreground. For "anywhere", IIRC, it leveraged the minibuffer and you could bind it to M-x (may be?) to get it to come up pretty much "whenever" within Emacs.

2) Subsequent to the "entry UI" appearing, the ability to not have to type too much to begin expressing your intent. In QS this was accomplished partly via a search / fuzzy algorithm. You didn't have to type the full text for something to start showing up, e.g. "ff" might have been enough to get "Firefox" to appear pretty high in the results. Also, typing more would tend to filter the current results. IIUC, the various things in Emacs that are spiritual descendants of anywhere have various ways of doing this sort of thing with tweaking.

I may have missed some important things, but at least this is a start.

sogaiu commented 2 years ago

For reference, the author of closh and liz wrote a post on Quicksilver.

He has other posts about things that share some characteristics with QuickSilver. Many of the ones from 2015 seem relevant.

sogaiu commented 2 years ago

While it might still be nice to have some completion, the recently added list-files feature has been helpful in selecting a file to open.