Skip to content

Commit

Permalink
Reset SIGINT handler in background processes
Browse files Browse the repository at this point in the history
In a noninteractive shell, asynchronous commands ignore SIGINT and
SIGQUIT. We typically use such shells to feed fifo buffers which we
do want to cancel them on Control-C.  Make it so.

Same for SIGQUIT; that one is not typically used but I expect that
along the Kakoune server it kills any child processes that (haven't
been daemonized).

Note that for unknown reasons, Bash already doesn't ignore SIGINT in
async processes that use "eval".

Note that Dash has a bug that prevents this from working;
proposed fix is at
https://lore.kernel.org/dash/20240329153905.154792-2-aclopte@gmail.com/

(While at it balance out some parens, to help the m command)
  • Loading branch information
krobelus authored and mawww committed Mar 31, 2024
1 parent 5d00b80 commit 7b93567
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions rc/tools/clang.kak
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ define-command -params ..1 \
# position and a buffer timestamp, only valid completions should be
# displayed.
((
trap - INT QUIT
until [ -f ${dir}/buf ]; do :; done # wait for the buffer to be written
if [ -n "$kak_opt_clang_directory" ]; then
cd "$kak_opt_clang_directory"
fi
case ${kak_opt_filetype} in
c) ft=c ;;
cpp) ft=c++ ;;
obj-c) ft=objective-c ;;
*) ft=c++ ;;
(c) ft=c ;;
(cpp) ft=c++ ;;
(obj-c) ft=objective-c ;;
(*) ft=c++ ;;
esac
if [ "$1" = "-complete" ]; then
Expand Down
2 changes: 2 additions & 0 deletions rc/tools/ctags.kak
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ declare-option -docstring "path to the directory in which the tags file will be
define-command ctags-generate -docstring 'Generate tag file asynchronously' %{
echo -markup "{Information}launching tag generation in the background"
nop %sh{ (
trap - INT QUIT
while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done
trap 'rmdir .tags.kaklock' EXIT
Expand All @@ -128,6 +129,7 @@ define-command ctags-generate -docstring 'Generate tag file asynchronously' %{

define-command ctags-update-tags -docstring 'Update tags for the given file' %{
nop %sh{ (
trap - INT QUIT
while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done
trap 'rmdir .tags.kaklock' EXIT
Expand Down
3 changes: 2 additions & 1 deletion rc/tools/git.kak
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ define-command -params 1.. \
esac
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-git.XXXXXXXX)/fifo
mkfifo ${output}
( git "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
( trap - INT QUIT; git "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
printf %s "evaluate-commands -try-client '$kak_opt_docsclient' '
edit! -fifo ${output} *git*
Expand Down Expand Up @@ -283,6 +283,7 @@ define-command -params 1.. \
echo 'map window normal <ret> %{:git blame-jump<ret>}'
echo 'echo -markup {Information}Press <ret> to jump to blamed commit'
(
trap - INT QUIT
cd_bufdir
printf %s "evaluate-commands -client '$kak_client' %{
set-option buffer=$kak_bufname git_blame_flags '$kak_timestamp'
Expand Down
4 changes: 2 additions & 2 deletions rc/tools/go/gopls.kak
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ define-command -hidden -params 0 gopls-ref %{
evaluate-commands %sh{
dir=${kak_opt_gopls_tmp_dir}
mkfifo "${dir}/fifo"
( gopls references "${kak_buffile}:${kak_cursor_line}:${kak_cursor_column}" \
> "${dir}/fifo" 2> /dev/null & ) > /dev/null 2>&1 < /dev/null
( { trap - INT QUIT; gopls references "${kak_buffile}:${kak_cursor_line}:${kak_cursor_column}"
} > "${dir}/fifo" 2> /dev/null & ) > /dev/null 2>&1 < /dev/null
# using filetype=grep for nice hilight and <ret> mapping
printf %s\\n "evaluate-commands -try-client '${kak_opt_toolsclient}' %{
edit! -fifo '${dir}/fifo' *gopls-refs*
Expand Down
2 changes: 1 addition & 1 deletion rc/tools/grep.kak
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define-command -params .. -docstring %{
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo
mkfifo ${output}
( ${kak_opt_grepcmd} "$@" 2>&1 | tr -d '\r' > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
( { trap - INT QUIT; ${kak_opt_grepcmd} "$@" 2>&1 | tr -d '\r'; } > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} *grep*
Expand Down
1 change: 1 addition & 0 deletions rc/tools/lint.kak
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ define-command \
# but shellcheck isn't a fan.
# shellcheck disable=SC2094
({ # do the parsing in the background and when ready send to the session
trap - INT QUIT
for selpath in "$dir"/sel-*; do
# Read in the line and column offset of this selection.
Expand Down
2 changes: 1 addition & 1 deletion rc/tools/make.kak
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define-command -params .. \
} make %{ evaluate-commands %sh{
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-make.XXXXXXXX)/fifo
mkfifo ${output}
( eval "${kak_opt_makecmd}" "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
( { trap - INT QUIT; eval "${kak_opt_makecmd}" "$@"; } > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} -scroll *make*
Expand Down
1 change: 1 addition & 0 deletions rc/tools/python/jedi.kak
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define-command jedi-complete -docstring "Complete the current selection" %{
dir=${kak_opt_jedi_tmp_dir}
printf %s\\n "evaluate-commands -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }"
((
trap - INT QUIT
cd $(dirname ${kak_buffile})
export PYTHONPATH="$kak_opt_jedi_python_path:$PYTHONPATH"
Expand Down
1 change: 1 addition & 0 deletions rc/tools/rust/racer.kak
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define-command racer-complete -docstring "Complete the current selection with ra
evaluate-commands %sh{
dir=${kak_opt_racer_tmp_dir}
(
trap - INT QUIT
cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))"
racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} ${kak_buffile} ${dir}/buf)
compl=$(printf %s\\n "${racer_data}" | awk '
Expand Down
1 change: 1 addition & 0 deletions rc/tools/spell.kak
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define-command -params ..1 -docstring %{
printf 'eval -no-hooks write %s\n' "${kak_response_fifo}" > $kak_command_fifo
{
trap - INT QUIT
sed 's/^/^/' | eval "aspell --byte-offsets -a $options" 2>&1 | awk '
BEGIN {
line_num = 1
Expand Down

0 comments on commit 7b93567

Please sign in to comment.