Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9649059

Browse files
committed
events: add new "SignalUSR1" event
..which gets triggered when SIGUSR1 is sent to the nvim process. Closes #9562
1 parent 894f6be commit 9649059

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

runtime/doc/autocmd.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ Name triggered by ~
290290
|DiffUpdated| after diffs have been updated
291291
|DirChanged| after the |current-directory| was changed
292292

293+
|SignalUSR1| after the nvim process received an USR1 signal
294+
293295
|FileChangedShell| Vim notices that a file changed since editing started
294296
|FileChangedShellPost| after handling a file changed since editing started
295297
|FileChangedRO| before making the first change to a read-only file
@@ -918,6 +920,9 @@ ShellCmdPost After executing a shell command with |:!cmd|,
918920
ShellFilterPost After executing a shell command with
919921
":{range}!cmd", ":w !cmd" or ":r !cmd".
920922
Can be used to check for any changed files.
923+
*SignalUSR1*
924+
SignalUSR1 After the nvim process received an USR1
925+
signal.
921926
*SourcePre*
922927
SourcePre Before sourcing a Vim script. |:source|
923928
<afile> is the name of the file being sourced.

src/nvim/auevents.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ return {
7474
'SessionLoadPost', -- after loading a session file
7575
'ShellCmdPost', -- after ":!cmd"
7676
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
77+
'SignalUSR1', -- signal USR1
7778
'SourceCmd', -- sourcing a Vim script using command
7879
'SourcePre', -- before sourcing a Vim script
7980
'SpellFileMissing', -- spell file missing
@@ -115,6 +116,7 @@ return {
115116
-- syntax file
116117
nvim_specific = {
117118
DirChanged=true,
119+
SignalUSR1=true,
118120
TabClosed=true,
119121
TabNew=true,
120122
TabNewEntered=true,

src/nvim/fileio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6917,6 +6917,7 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,
69176917
|| event == EVENT_REMOTEREPLY
69186918
|| event == EVENT_SPELLFILEMISSING
69196919
|| event == EVENT_SYNTAX
6920+
|| event == EVENT_SIGNALUSR1
69206921
|| event == EVENT_TABCLOSED) {
69216922
fname = vim_strsave(fname);
69226923
} else {

src/nvim/os/signal.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
#include "nvim/globals.h"
1616
#include "nvim/memline.h"
1717
#include "nvim/eval.h"
18+
#include "nvim/fileio.h"
1819
#include "nvim/main.h"
1920
#include "nvim/memory.h"
2021
#include "nvim/misc1.h"
2122
#include "nvim/event/signal.h"
2223
#include "nvim/os/signal.h"
2324
#include "nvim/event/loop.h"
2425

25-
static SignalWatcher spipe, shup, squit, sterm;
26+
static SignalWatcher spipe, shup, squit, sterm, susr1;
2627
#ifdef SIGPWR
2728
static SignalWatcher spwr;
2829
#endif
@@ -61,6 +62,10 @@ void signal_init(void)
6162
signal_watcher_init(&main_loop, &spwr, NULL);
6263
signal_watcher_start(&spwr, on_signal, SIGPWR);
6364
#endif
65+
#ifdef SIGUSR1
66+
signal_watcher_init(&main_loop, &susr1, NULL);
67+
signal_watcher_start(&susr1, on_signal, SIGUSR1);
68+
#endif
6469
}
6570

6671
void signal_teardown(void)
@@ -73,6 +78,9 @@ void signal_teardown(void)
7378
#ifdef SIGPWR
7479
signal_watcher_close(&spwr, NULL);
7580
#endif
81+
#ifdef SIGUSR1
82+
signal_watcher_close(&susr1, NULL);
83+
#endif
7684
}
7785

7886
void signal_stop(void)
@@ -84,6 +92,9 @@ void signal_stop(void)
8492
#ifdef SIGPWR
8593
signal_watcher_stop(&spwr);
8694
#endif
95+
#ifdef SIGUSR1
96+
signal_watcher_stop(&susr1);
97+
#endif
8798
}
8899

89100
void signal_reject_deadly(void)
@@ -115,6 +126,10 @@ static char * signal_name(int signum)
115126
#endif
116127
case SIGHUP:
117128
return "SIGHUP";
129+
#ifdef SIGUSR1
130+
case SIGUSR1:
131+
return "SIGUSR1";
132+
#endif
118133
default:
119134
return "Unknown";
120135
}
@@ -162,6 +177,10 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
162177
deadly_signal(signum);
163178
}
164179
break;
180+
#ifdef SIGUSR1
181+
case SIGUSR1:
182+
apply_autocmds(EVENT_SIGNALUSR1, NULL, NULL, true, curbuf);
183+
#endif
165184
default:
166185
ELOG("invalid signal: %d", signum);
167186
break;

0 commit comments

Comments
 (0)