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

Trim in :pipe in 24.07 version #11177

Closed
b52es opened this issue Jul 15, 2024 · 7 comments · Fixed by #11183
Closed

Trim in :pipe in 24.07 version #11177

b52es opened this issue Jul 15, 2024 · 7 comments · Fixed by #11183

Comments

@b52es
Copy link

b52es commented Jul 15, 2024

24.07 release added trim in :pipe that kills newline symbol at the end of selection. Please return to 24.03 release behavior.

@RoloEdits
Copy link
Contributor

Original issue: #10912

@pascalkuthe
Copy link
Member

I didn't get a chance to review that PR. We should not be stripping arbitrary whitespace at the end. Only a single newline character should be trimmed (that is what kakoune does too for example) so trim_end is not the right function.

@b52es
Copy link
Author

b52es commented Jul 15, 2024

I agree with #10912 only with realize this feature in new command like :pipe_trim and :pipe with previous raw behavior.

@b52es
Copy link
Author

b52es commented Jul 15, 2024

I believe the new trim in pipe was supposed to check the selected text for a trailing newline character; if present, the return text of the external command must leave at least one trailing newline character.

@RoloEdits
Copy link
Contributor

I can get a pr for this pretty quick, but just need to know the exact behavior. Should at least one newline always exist? Or no mater what remove a trailing newline if it exists?

The original issue brought up how having the output with trailing whitespace was cumbersome:

That’s a possible solution, but it means that the vast majority of the time you pipe to another command you’ll have to :trim too. IMO this is a behaviour that should be implemented by the pipe command for ease of use.

I’d also be open to it only trimming a single trailing newline too. But as it is, stuff like piping to uniq or sort or case conversion utils or a formatter will all insert a new line into your document because these tools do the “correct” thing for interactive shell usage. Both Vim and Kakoune do remove the final newline, for good reason :)

What does your use case look like? @b52es

@pascalkuthe
Copy link
Member

https://github.com/mawww/kakoune/blame/840f4ec3ed14281cea6dd17c4c38d302963ae16d/src/normal.cc#L612

this is what kakoune does. Thre is no 100% perfect solution since shell commands don't behave consistently but I think what kakoune setteled on is reasonable and ist useful in the majority of situations.

@GavinSmith0123
Copy link

I am not sure if it is the same issue as :pipe but I have a similar problem with :insert-output in helix 24.7. I have a program to generate contents of a file which should end in a newline. However, however many newlines I output at the end of the program, none appear from :insert-output. Has this been fixed as well?

The only workaround I can find is to change my program to output an extra character (a letter "x"), and then delete it. So the lines in my config.toml file look like this:

  "F1" = [":insert-output ~/.config/helix/print-changelog.pl",                  
          "goto_line_start", "delete_selection_noyank"]         

(I tried doing it with "insert_newline" instead but this unhelpfully inserted an autoindent after the newline.)

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

Successfully merging a pull request may close this issue.

4 participants