-
Notifications
You must be signed in to change notification settings - Fork 722
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
[BUG] pipe bc make the content dissapear #4559
Comments
Hello Charles, It is due to #3669. Kakoune no longer adds newline to the input when piping. The printf 1+1 | bc
# (standard_in) 1: parse error ⇐ however exit status is 0 In Kakoune, you now have to add the newline yourself with the following pattern: { cat; echo; } For your convenience, you can add the following shortcuts to your kakrc: map -docstring 'increment selection' global normal <c-a> ': increment-selection %val{count}<ret>'
map -docstring 'decrement selection' global normal <c-x> ': decrement-selection %val{count}<ret>'
define-command -override increment-selection -params 1 -docstring 'increment-selection <count>: increment selection by count' %{
execute-keys "a+%sh{expr $1 '|' 1}<esc>|{ cat; echo; } | bc<ret>"
}
define-command -override decrement-selection -params 1 -docstring 'decrement-selection <count>: decrement selection by count' %{
execute-keys "a-%sh{expr $1 '|' 1}<esc>|{ cat; echo; } | bc<ret>"
} |
Hoo thank you, you are right. For posterity, if we press L after selecting each expression to include the new line, things are working again. Thank @alexherbo2 , this issue is solved then ! |
|
Thanks for this explanation, and I see for the mentioned issue the case where this newline lead to wrong result, so it make sense for kakoune to omit it. Cheers. |
Hi, I am trying to make this work in the example from the Wiki: define-command -hidden -params 2 inc %{
evaluate-commands %sh{
if [ "$1" = 0 ]
then
count=1
else
count="$1"
fi
# old
# printf '%s%s\n' 'exec h"_/\d<ret><a-i>na' "$2($count)<esc>|bc<ret>h"
# new: doesn't work yet
printf '%s%s' 'exec h"_/\d<ret><a-i>na' "$2($count)<esc>|{ cat\; echo\; }|bc<ret>h"
}
}
map global normal <c-a> ':inc %val{count} +<ret>'
map global normal <c-x> ':inc %val{count} -<ret>' Is there a way to make it work here? I've been trying several ways, but it always ends up in removing the number. EDIT: printf 1+1 | qalc -n -t -f - I might be doing something wrong. |
I think one of the problems might be that I need to escape the braces, so I tried this... Now it behaves differently: it does nothing instead of erasing the number. printf '%s%s' %[ 'exec h"_/\d<ret><a-i>na' "$2($count)<esc>|{ cat\; echo\; }|bc<ret>h" ] Any help is apprecied. |
If I try your
braces for grouping are only valid in specific positions.
Another workaround is to add a newline to the commandline
for whatever reason this doesn't work but you can use set-register:
|
@krobelus thank you! I somehow forgot to check the debug buffer 😅... # simulate <c-a> and <c-x> to increment/decrement the number under the cursor
define-command -hidden -params 2 inc %{ try %{
evaluate-commands %sh{
if [ "$1" = 0 ]
then
count=1
else
count="$1"
fi
printf '%s%s' 'exec h"_/\d<ret><a-i>na' "$2($count)<esc>|( cat\; echo )|bc<ret>"
}
} catch %{
# Prevent the cursor from moving left if no number is found
execute-keys l
}}
map global normal <c-a> ':inc %val{count} +<ret>'
map global normal <c-x> ':inc %val{count} -<ret>' Maybe, after the new release, we need to update the related bc wiki page. |
Hi, sorry for bumping this again, I figured out why it was not working: we can't use spaces and semicolons when we're not using a subshell. The final command, without a subshell looks like this: define-command -hidden -params 2 inc %{ try %{
evaluate-commands %sh{
[ "$1" = 0 ] && count=1 || count="$1"
printf '%s%s' 'exec h"_/\d<ret><a-i>na' "$2($count)<esc>|{<space>cat<semicolon>echo<semicolon>}|bc<ret>"
}
} catch %{
execute-keys l
}}
map global normal <c-a> ': inc %val{count} +<ret>'
map global normal <c-x> ': inc %val{count} -<ret>' I will be able to sleep at night better now. I've also updated it in the bc wiki. |
Version of Kakoune
commit e04a14c Date: Wed Feb 16 07:55:56 2022 +1100
Reproducer
Pipe any valid selection to
bc
:This should call bc on three selections: 1-1, 2-1 and 3-1
Outcome
Expected:
Expectations
Result in removed selection instead.
Additional information
The bug also occurs when a single selection is made.
OS: Arch linux
The text was updated successfully, but these errors were encountered: