kakounedotcom / connect.kak

Connect a program to Kakoune clients
https://kakoune.org
The Unlicense
88 stars 18 forks source link

Fixed quoting for :ls and rofi/wofi module #33

Closed useredsa closed 4 years ago

useredsa commented 4 years ago

rofi-buffers wouldn't work with buffers with spaces or similar. Pretty often: *man whatever*.

I have not checked the whole codebase for similar issues that require -quoting shell or quotes in front of a :command.

alexherbo2 commented 4 years ago

I prefer a different implementation, similar to swaymsg output. When the output is the terminal, pretty-print, and use the shell quoting when redirected. Ideally, I would prefer JSON over shell, but we have not.

Your implementation quotes everything as a single argument, breaking multi-edits. I’m afraid handling properly the quoting will uglify all the script implementations. I will take a look how we can keep the scripts well readable.

See https://github.com/mawww/kakoune/issues/3783 for the JSON quoting feature.

alexherbo2 commented 4 years ago

Ok, I took a look. How about adding support for :edit and :buffer to take their input from stdin?

In the scripts, it will look like:

find -type f | dmenu | :edit
:ls | dmenu | :buffer

It is not perfect as we take one argument per line, not allowing :edit +<line>:<column> <file> with a filter program.

useredsa commented 4 years ago

But the modification for :ls would be appropiate, right?

useredsa commented 4 years ago

Your implementation quotes everything as a single argument, breaking multi-edits.

Is it possible to select multiple entries with rofi?

alexherbo2 commented 4 years ago

Not sure, if we use a filter program, we don’t need the quoting. The output should be the same as find, that is one entry per line.

useredsa commented 4 years ago

I prefer a different implementation, similar to swaymsg output. When the output is the terminal, pretty-print, and use the shell quoting when redirected. Ideally, I would prefer JSON over shell, but we have not.

Your implementation quotes everything as a single argument, breaking multi-edits. I’m afraid handling properly the quoting will uglify all the script implementations. I will take a look how we can keep the scripts well readable.

See mawww/kakoune#3783 for the JSON quoting feature.

We could quote only the $(:ls ....) and move the kak_escape to :buffer and :edit I belive. Then it's a matter of passing multiple commands to :buffer or :edit.

useredsa commented 4 years ago

Not sure, if we use a filter program, we don’t need the quoting. The output should be the same as find, that is one file per line.

It doesn't change the expected output, it precisely guarantees that it does that instead of printing multiple lines for the same buffer.

#!/bin/sh

# List buffers
kak_quoted_buflist=$(:get -quoting shell %val{buflist})
eval "set -- $kak_quoted_buflist"
printf '%s\n' "$@"

prints

*debug*
*scratch*

So I think this one is necessary.

alexherbo2 commented 4 years ago

Ah, you are right. We still outputs one buffer per line, but we need the -quoting shell before passing to printf.

useredsa commented 4 years ago

Your implementation quotes everything as a single argument, breaking multi-edits.

Is it possible to select multiple entries with rofi?

Actually, we can consider the output of rofi to be a single element. Otherwise, how can we differentiate between <buffer> <line> <number> when we have a buffer with spaces? Only with quoting, but we shouldn't start to produce quotes with rofi.

That would mean that the inner quotes are necessary.

alexherbo2 commented 4 years ago

btw, how do you develop plugins now with plug.kak? I was used my plugins to always be sync, but now I need to plug-install to sync the pool with the local repositories. There is some defer I find elegant, because you can develop without affecting your kakrc, but it is less straightforward.

useredsa commented 4 years ago

btw, how do you develop plugins now with plug.kak? I was used my plugins to always be sync, but now I need to plug-install to sync the pool with the local repositories. There is some defer I find elegant, because you can develop without affecting your kakrc, but it is less straightforward.

I think this belongs somewhere else?

alexherbo2 commented 4 years ago

yep xd

alexherbo2 commented 4 years ago

Fixed o/

alexherbo2 commented 4 years ago

@useredsa To summarize, I replaced the :edit $(list | dmenu) pattern with list | dmenu | :edit.

useredsa commented 4 years ago

@useredsa To summarize, I replaced the :edit $(list | dmenu) pattern with list | dmenu | :edit.

I was still having the same problem.

The problem is with kak -p:

~ $ kak -p <session>
eval -try-client client0 echo '3    3'

makes kakoune echo 3 3 instead of 3 3.

EDIT: That is actually only expected because of eval. The problem is we are not quoting right.

alexherbo2 commented 4 years ago

Your evaluate-commands does not quote each argument to pass to kak -p <session>, but the :send command does.

alexherbo2 commented 4 years ago

I tried the fuzzy finders with a 'b' c.txt and a "b" c.txt and it works.

useredsa commented 4 years ago

I tried the fuzzy finders with a 'b' c.txt and a "b" c.txt and it works.

I'm trying rofi-buffers and it doesn't

alexherbo2 commented 4 years ago

Added :send -verbatim buffer.

useredsa commented 4 years ago

@useredsa To summarize, I replaced the :edit $(list | dmenu) pattern with list | dmenu | :edit.

I believe this is causing kak-desktop to not work, because :edit expects input from the standard input when it's called with kak-desktop.

Isn't it better to take both input and arguments or maybe take arguments if there is no input instead of checking whether we are in a terminal. Or maybe even writing :edit - when you want to process the input. We can aso create another command called :edit-stdin.

alexherbo2 commented 4 years ago

12577666359ec38c1adcb78ced570944f7da7f9a