mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.86k stars 712 forks source link

Ability to explore directories within kakoune #4014

Open cole-h opened 3 years ago

cole-h commented 3 years ago

Feature and Usecase

I would like to be able to explore directories from within kakoune, so that when I run kak on a directory and not a file (usually accidentally), I can somehow navigate to one of the contained files, akin to vim's netrw feature.

I'd also settle for being able to hook into the error that happens when running kak on a directory, so that I can lift from https://github.com/TeddyDD/kakoune-edit-or-dir to satisfy this. I found https://github.com/mawww/kakoune/issues/1056, but it was closed without a(n obvious) solution. I don't consider connect.kak a solution to this unless kak grows libvterm integration (because connect.kak doesn't work over SSH unless I use tmux, which I don't (want to) use all the time).

Screwtapello commented 3 years ago

Inside Kakoune, if you type :e path/to/some/dir/ you should get a completion menu of the contents of that path, which is not quite as nice as a fully-interactive filesystem browser, but is nicer than a plain error message. LIkewise from the shell, after typing kak path/to/some/dir/ you get the opportunity to play with tab-completion — it's not quite as nice as Kakoune's completion, but it's better than nothing.

Perhaps a better solution would be something like a BufCreatePre hook, with the special rule that if :edit is invoked inside the hook, the original :edit command is cancelled and Kakoune does not attempt to open the original path for reading. Then you could do things like:

hook global BufCreatePre (.*\.zip)!(.*) %{
    eval %sh{
        workdir=$(mktemp -d)
        cd "$workdir"
        unzip "$kak_hook_param_capture_1" "$kak_hook_param_capture_2"
        echo edit "$workdir"/"$kak_hook_param_capture_2"
        echo hook buffer BufWritePost %{ nop %sh{ cd "$workdir"; zip "$kak_hook_param_capture_1" "$kak_hook_param_capture_2" } }
    }
}

...to teach Kakoune to edit files stored inside .zip archives with a syntax like path/to/archive.zip!inner/path/to/file.txt

tototest99 commented 3 years ago

Hello, There was a lot of recent posts on the discourse forum, with featureful terminal file managers. Respecting Kakoune design you can plug one in different ways (plugin, connect, sh launcher incorporating the choice depending on the file you pass as argument, etc.). imho a netrw is out of scope and another burden on the maintainers.

cauebs commented 3 years ago

I think it's even more useful with zips and tars than plain directories. It's one of the few things I miss from vim.

benjaminwil commented 2 years ago

I just came across another real-world use case where it would be convenient for Kakoune to handle being given a directory.

Bundler, the defacto package manager for RubyGems, provides a command bundle open to open up the source code of external dependencies in one's Gemfile. (i.e. bundle open nokogiri.)

It opens the editor assigned to EDITOR and puts you in the root directory of that gem dependency. Vim handled this with netrw, and GUI editors seem to also handle this okay.

Now that my EDITOR is set to Kakoune, I can't use this command. Kakoune opens to a text error, and there doesn't seem to be an easy way to get the working directory—which would be the root of the dependency's source code, I would think.

krobelus commented 2 years ago

On Thu, Feb 03, 2022 at 07:05:55PM -0800, benjamin wil wrote:

and there doesn't seem to be an easy way to get the working directory

There is, try :echo %sh{pwd}

sidkshatriya commented 2 years ago

There is, try :echo %sh{pwd}

It is easy but only for someone with some experience with kakoune. There has been a lot of discussion around pwd. See my (failed) attempt to get this into core https://github.com/mawww/kakoune/pull/4431

The fact that this is brought up reasonably regularly means that it continues to be a paper cut, whether or not @mawww agrees with it. Anyways, I've made my peace with it and accepted that it is likely never to be incorporated.

benjaminwil commented 2 years ago

There is, try :echo %sh{pwd}

Of course, thank you. So if I can gracefully handle the error state and either a) do something with $PWD or b) pre-fill :edit <tab> in Kakoune, I could be very happy. But I am not yet clear on whether there's a hook I could use, or how I might rescue from this specific error.

krobelus commented 2 years ago

On Fri, Feb 04, 2022 at 09:00:06AM -0800, benjamin wil wrote:

So if I can gracefully handle the error state and either a) do something with $PWD or b) pre-fill :edit <tab> in Kakoune, I could be very happy. But I am not yet clear on whether there's a hook I could use, or how I might rescue from this specific error.

That hook doesn't exist yet. For now you could check for a directory argument in a wrapper script.