Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect both backquotes and tildes' special features unknown to the kernel from expansion #5251

Open
nonumeros opened this issue Oct 26, 2024 · 8 comments

Comments

@nonumeros
Copy link
Contributor

nonumeros commented Oct 26, 2024

Protect both backquotes and tildes' special features unknown to the kernel from expansion

There had been some noticeable changes that somehow protect $ and thus piping out each selection to a command given.

And it all seems too good and dandy but it may not account for the fact that, (and this is from my understanding of the issue), that although say a tilde ~ is unknown to the kernel with its special feature, a given buffer is still modified, (hence unwanted behavior) even by enclosing it within bacvior) even by enclosing it within backquotes to prevent expansion

Bottom line here is that whenever I see a message on the kakoune session saying modified buffer exist it really really raises every sort of alarm imaginable to human kind. Why would a modified buffer exist in the + sfirst place without an apparent modification? This is of course, going b saby the POSIX standards.

Allow me to turther explain it. On most terminals, if I were to map any given combination to run a command

` $ <command> $kak_buffile

or

~$ <command> $kak_buffile

it goes through without an issue. But it should return modified buffers exist and yet doesn't.

In the teletype the same commands

` $ <command> $kak_buffile
~ $ <command> $kak_buffile

return modified buffers exist even though it is not supposed to, for nothng was really modified

In the latter, no amount of ` will protect either the ~ from interpreting it and thus returning a modified buffer exist for that particular buffer.

There may be other characters such as an _ that may prevent this from happening. Which in the case of the teletype, it does seem to do the trick. But I have to admit I don't quite understand the difference there, as opposed to the other two.

@nonumeros
Copy link
Contributor Author

If for example,

~~ $ <command> $kak_buffile

is called out, upon exiting the session, it would return a modified buffer remaining which, regardless of the tildes used, ought to not be modified.

Of course! The message cannot be more accurate. The buffer was indeed modified. Hence raising up the issue as to what exactly, was modified

@Screwtapello
Copy link
Contributor

I don't understand what you're doing.

The backtick is the Kakoune command for "convert selections to lower-case", ~ is the command for "convert selections to upper-case", and $ is the Kakoune command for "pipe each selection to a shell command to test if it should remain selected".

Are you selecting some text, pressing backtick to make it lower-case, then running a $ command? Presumably the "modified buffer remaining" command means that you have used backtick to make things lower-case (or upper-case, with ~).

I do not understand your reference to escaping; backtick and ~ do not escape anything in Kakoune.

~ can be an escape character for ssh connections, but only immediately after pressing Enter, and it wouldn't have any effect on Kakoune's $ command at the other end of the connection.

@nonumeros
Copy link
Contributor Author

nonumeros commented Oct 27, 2024

I don't understand what you're doing.

The backtick is the Kakoune command for "convert selections to lower-case", ~ is the command for "convert selections to upper-case", and $ is the Kakoune command for "pipe each selection to a shell command to test if it should remain selected".

Are you selecting some text, pressing backtick to make it lower-case, then running a $ command? Presumably the "modified buffer remaining" command means that you have used backtick to make things lower-case (or upper-case, with ~).

I do not understand your reference to escaping; backtick and ~ do not escape anything in Kakoune.

~ can be an escape character for ssh connections, but only immediately after pressing Enter, and it wouldn't have any effect on Kakoune's $ command at the other end of the connection.

Think of it this way. And keep in mind that just as I said earlier, some changes ocurred along the way, that I can't pinpoint what version of kakoune may have been running at the time. But for references, this is with the latest head

But think of it this way. What I've done with kakoune is mapping some keys to a given command which in turn runs the $kak_buffile for me. Think of the same behavior that within vim, you'd have with an :! command operation, followed by the filename. Which is bound to active register %

There have been a few commands mapped to some keys that basically behave as such. Returning the modified buffer remaining message.

If I were to have in the configuration file something such as

map global normal <c-l> ':w<ret> $ tex $kak_buffile' 

you can probably shell out with the write operation altogether, but at that point you might as well tag it along the way. I don't see a difference.

Now. The buffer filename does not necessarily have to have the extension assigned to the filename. Heck. I'm pretty sure you can run the above command on a markdown file for that matter. Alhtough it would interpret some characters differently and beyond that point will probably stall out mainly because it wouldn't match the programme of unescaped character strings and the like. But this is besides the point.

So let's say you take for example the above. Sorry for redundancy and here and this is the most important part out of the whole diatribe. Fiddle out with both backquotes and tildes here

map global normal <c-l> ':w<ret> ~~$ tex $kak_buffile' 

and teletype it to markdown the file md for me. What do you see? Remember you can always dispense of the write operation too.

@Screwtapello
Copy link
Contributor

OK, here's a test case of what I think you're talking about:

$ echo "hello world" > test.txt
$ kak -n test.txt -e 'execute-keys "~~$true<ret>"; quit'

(I don't happen to have TeX installed, and the specific command doesn't seem to be relevant to the problem you're describing)

When I do the above steps, Kakoune fails to exit, with an error:

'quit': 1 modified buffers remaining

...which makes total sense, because the buffer has been modified by the ~ operation: "hello" became "Hello" (with a capital H).

That's what I expected would happen, but apparently it's not what you expected would happen? What result were you expecting?

@nonumeros
Copy link
Contributor Author

nonumeros commented Oct 28, 2024

...which makes total sense, because the buffer has been modified by the ~ operation: "hello" became "Hello" (with a capital H)

and $ is the Kakoune command for "pipe each selection to a shell command to test if it should remain selected"

Then I'm at a loss there.

I don't know. So, If you were to have

kak -n test.txt -e 'execute-keys "~~`$true<ret>"; quit'

what changed?

or for that matter,

kak -n test.txt -e 'execute-keys "~~`$true<ret>\`"; quit'

Now. You've got an excellent point there.

$ echo "Hello world" > test.txt
$ kak -n test.txt -e 'execute-keys "$true<ret>\`"; quit'

@Screwtapello
Copy link
Contributor

kak -n test.txt -e 'execute-keys "~~`$true<ret>"; quit'

You've added a backtick after ~~, so that's "convert selection to uppercase, convert selection to uppercase, convert selection to lowercase". That's two modifications, Kakoune still refuses to quit because of the modified buffer.

kak -n test.txt -e 'execute-keys "~~`$true<ret>\`"; quit'

Now there's a backslash ("execute the next key with hooks disabled") and another backtick ("convert selection to lowercase") at the end. Buffer's still modified, Kakoune still refuses to quit.

In fact, the $ command doesn't do anything at all in this instance. You can get exactly the same results with:

kak -n test.txt -e 'execute-keys "~~"; quit'
kak -n test.txt -e 'execute-keys "~~`"; quit'
kak -n test.txt -e 'execute-keys "~~`\`"; quit'

Your original message talks about "enclosing in backquotes to prevent expansion", but as far as I can tell nothing is being expanded, and even if it were, backquotes do not prevent any kind of expansion in Kakoune.

@nonumeros
Copy link
Contributor Author

nonumeros commented Nov 3, 2024

at the current stage of development, unlike in prior commits, some changes have occurred along the way that I simply dismissed or failed to follow along but there have definitely been some modifications

Take for example this before-and-after scenario

before

'execute-keys "\$"'

after

'execute-keys "` $"'

the latter clearly indicating that some whitespaces and/or special characters are taken into consideration now, resulting for example in applying it over to the selection. But this wasn't always the case. It wasn't. In other words:

'execute-keys "x"'

where x there, is indeed the selcetion was not the norm. Not always the norm. Not always the norm

Now. The documentation states the following and I'll quote it

While in shell-programming it’s good practice to always wrap expansions in double-quotes, in Kakoune it’s perfectly safe to leave expansions unquoted.

Okie dokie then. Then. It would make more sense to say

'execute-keys $tex'

than say

'execute-keys "` $tex"'

Correct? Unless the reason to say that running it on double quotes, as in with the prior examples you listed, is indeed the correct operation since the execute-keys is being run from the terminal, rather than from an the editor session. But I'm not quite sure about it either.

e.g.,

kak -n test.txt -e 'execute-keys ""'

needs to be in single, followed by double quotes, but double quotes exert the changes on the editor, as opposed to single quotes there, or so it seems.

If I say

kak -n test.txt -e 'execute-keys $tex'

matches the behavior I would expect the documentation is describing, rather than a superfluous/spurious double quote or another character/space that may have gone unescaped. Or so I think.

backquotes do not prevent any kind of expansion in Kakoune.

Right.

'execute-keys $tex'

behaves almost the same as

'execute-keys "$tex"'

but that's only as long as a space or any other character is not included between the double quotes

As always. I appreciate the responses and feedback from you.

@Screwtapello
Copy link
Contributor

When Kakoune executes a command, it splits the line on whitespace characters to produce a list of words. The first word is the command, the rest of the words are passed to the command for it to interpret.

When evaluate-commands is given multiple words, it joins them with a space, since it expects them to be another series of commands which will be split on spaces. So:

evaluate-commands echo hello
evaluate-commands echo                   hello
evaluate-commands "echo hello"

...all do the same thing.

When execute-keys is given multiple words, it joins them without a space. That's because the space key is a normal-mode command (it enters the user mode) and it would be confusing for it to be unexpectedly inserted into people's key sequences. If you really do want to execute the space key, you need to use the long name, or quote it so that Kakoune doesn't use it for word-splitting:

execute-keys <space>
execute-keys " "

...both do the same thing.

So yes, these two commands do exactly the same thing:

execute-keys $tex
execute-keys "$tex"

...since none of the characters within the quotes have any special meaning outside the quotes.

These two commands also do exactly the same thing:

execute-keys \$tex
execute-keys "\$tex"

...for the same reason: none of the characters within the quotes have any special meaning outside the quotes.

However, these two commands do not do the same thing:

execute-keys ` $tex
execute-keys "` $tex"

...because the space character is significant outside the quotes. The first is equivalent to:

execute-keys `$tex

(without the space) because Kakoune splits on spaces, and execute-keys (as described above) joins its arguments together. The other is equivalent to:

execute-keys `<space>$tex

...replacing the quoted space character with the long key name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants