mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
parent
8bdcd832ae
commit
b2cb05b53e
@ -870,7 +870,7 @@ ShellCmdPost After executing a shell command with |:!cmd|,
|
|||||||
*Signal*
|
*Signal*
|
||||||
Signal After Nvim receives a signal. The pattern is
|
Signal After Nvim receives a signal. The pattern is
|
||||||
matched against the signal name. Only
|
matched against the signal name. Only
|
||||||
"SIGUSR1" is supported. Example: >
|
"SIGUSR1" and "SIGWINCH" are supported. Example: >
|
||||||
autocmd Signal SIGUSR1 call some#func()
|
autocmd Signal SIGUSR1 call some#func()
|
||||||
< *ShellFilterPost*
|
< *ShellFilterPost*
|
||||||
ShellFilterPost After executing a shell command with
|
ShellFilterPost After executing a shell command with
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "nvim/os/signal.h"
|
#include "nvim/os/signal.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
static SignalWatcher spipe, shup, squit, sterm, susr1;
|
static SignalWatcher spipe, shup, squit, sterm, susr1, swinch;
|
||||||
#ifdef SIGPWR
|
#ifdef SIGPWR
|
||||||
static SignalWatcher spwr;
|
static SignalWatcher spwr;
|
||||||
#endif
|
#endif
|
||||||
@ -53,6 +53,9 @@ void signal_init(void)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef SIGUSR1
|
#ifdef SIGUSR1
|
||||||
signal_watcher_init(&main_loop, &susr1, NULL);
|
signal_watcher_init(&main_loop, &susr1, NULL);
|
||||||
|
#endif
|
||||||
|
#ifdef SIGWINCH
|
||||||
|
signal_watcher_init(&main_loop, &swinch, NULL);
|
||||||
#endif
|
#endif
|
||||||
signal_start();
|
signal_start();
|
||||||
}
|
}
|
||||||
@ -70,6 +73,9 @@ void signal_teardown(void)
|
|||||||
#ifdef SIGUSR1
|
#ifdef SIGUSR1
|
||||||
signal_watcher_close(&susr1, NULL);
|
signal_watcher_close(&susr1, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGWINCH
|
||||||
|
signal_watcher_close(&swinch, NULL);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal_start(void)
|
void signal_start(void)
|
||||||
@ -88,6 +94,9 @@ void signal_start(void)
|
|||||||
#ifdef SIGUSR1
|
#ifdef SIGUSR1
|
||||||
signal_watcher_start(&susr1, on_signal, SIGUSR1);
|
signal_watcher_start(&susr1, on_signal, SIGUSR1);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGWINCH
|
||||||
|
signal_watcher_start(&swinch, on_signal, SIGWINCH);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal_stop(void)
|
void signal_stop(void)
|
||||||
@ -106,6 +115,9 @@ void signal_stop(void)
|
|||||||
#ifdef SIGUSR1
|
#ifdef SIGUSR1
|
||||||
signal_watcher_stop(&susr1);
|
signal_watcher_stop(&susr1);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGWINCH
|
||||||
|
signal_watcher_stop(&swinch);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal_reject_deadly(void)
|
void signal_reject_deadly(void)
|
||||||
@ -140,6 +152,10 @@ static char *signal_name(int signum)
|
|||||||
#ifdef SIGUSR1
|
#ifdef SIGUSR1
|
||||||
case SIGUSR1:
|
case SIGUSR1:
|
||||||
return "SIGUSR1";
|
return "SIGUSR1";
|
||||||
|
#endif
|
||||||
|
#ifdef SIGWINCH
|
||||||
|
case SIGWINCH:
|
||||||
|
return "SIGWINCH";
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
@ -197,6 +213,12 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
|
|||||||
apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGUSR1", curbuf->b_fname, true,
|
apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGUSR1", curbuf->b_fname, true,
|
||||||
curbuf);
|
curbuf);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef SIGWINCH
|
||||||
|
case SIGWINCH:
|
||||||
|
apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGWINCH", curbuf->b_fname, true,
|
||||||
|
curbuf);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ELOG("invalid signal: %d", signum);
|
ELOG("invalid signal: %d", signum);
|
||||||
|
@ -30,6 +30,12 @@ describe('autocmd Signal', function()
|
|||||||
eq({'notification', 'foo', {}}, next_msg())
|
eq({'notification', 'foo', {}}, next_msg())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('matches SIGWINCH', function()
|
||||||
|
command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")')
|
||||||
|
posix_kill('WINCH', funcs.getpid())
|
||||||
|
eq({'notification', 'foo', {}}, next_msg())
|
||||||
|
end)
|
||||||
|
|
||||||
it('does not match unknown patterns', function()
|
it('does not match unknown patterns', function()
|
||||||
command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")')
|
command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")')
|
||||||
posix_kill('USR1', funcs.getpid())
|
posix_kill('USR1', funcs.getpid())
|
||||||
|
Loading…
Reference in New Issue
Block a user