diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 6 | ||||
-rw-r--r-- | runtime/doc/options.txt | 6 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 1 | ||||
-rw-r--r-- | src/nvim/auevents.lua | 2 | ||||
-rw-r--r-- | src/nvim/fileio.c | 1 | ||||
-rw-r--r-- | src/nvim/option.c | 10 | ||||
-rw-r--r-- | src/nvim/options.lua | 2 | ||||
-rw-r--r-- | src/nvim/os/signal.c | 23 | ||||
-rw-r--r-- | src/nvim/terminal.c | 11 | ||||
-rw-r--r-- | test/functional/autocmd/signal_spec.lua | 38 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 19 |
11 files changed, 83 insertions, 36 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index d7b74f99c2..6423939b83 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -353,6 +353,8 @@ Name triggered by ~ |CompleteDone| after Insert mode completion is done |User| to be used in combination with ":doautocmd" +|Signal| after the nvim process received a signal + The alphabetical list of autocommand events: *autocmd-events-abc* @@ -914,6 +916,10 @@ ShellCmdPost After executing a shell command with |:!cmd|, any changed files. For non-blocking shell commands, see |job-control|. + *Signal* +Signal After the nvim process received a signal. + The pattern is matched against the name of the + received signal. Only "SIGUSR1" is supported. *ShellFilterPost* ShellFilterPost After executing a shell command with ":{range}!cmd", ":w !cmd" or ":r !cmd". diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index b6ea63449d..d0643bf5ed 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4761,14 +4761,12 @@ A jump table for the options with a short description can be found at |Q_op|. height with ":set scroll=0". *'scrollback'* *'scbk'* -'scrollback' 'scbk' number (default: 10000 - in normal buffers: -1) +'scrollback' 'scbk' number (default: 10000) local to buffer Maximum number of lines kept beyond the visible screen. Lines at the top are deleted if new lines exceed this limit. + Minimum is 1, maximum is 100000. Only in |terminal| buffers. - -1 means "unlimited" for normal buffers, 100000 otherwise. - Minimum is 1. *'scrollbind'* *'scb'* *'noscrollbind'* *'noscb'* 'scrollbind' 'scb' boolean (default off) diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 36630d14ac..33260ab53b 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -142,6 +142,7 @@ Commands: Events: |DirChanged| + |Signal| |TabNewEntered| |TermClose| |TermOpen| diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 3cffd66dee..cc0ed0f587 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -74,6 +74,7 @@ return { 'SessionLoadPost', -- after loading a session file 'ShellCmdPost', -- after ":!cmd" 'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd". + 'Signal', -- after nvim process received a signal 'SourceCmd', -- sourcing a Vim script using command 'SourcePre', -- before sourcing a Vim script 'SpellFileMissing', -- spell file missing @@ -115,6 +116,7 @@ return { -- syntax file nvim_specific = { DirChanged=true, + Signal=true, TabClosed=true, TabNew=true, TabNewEntered=true, diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index ba154ea36a..6356290b9c 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6917,6 +6917,7 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, || event == EVENT_REMOTEREPLY || event == EVENT_SPELLFILEMISSING || event == EVENT_SYNTAX + || event == EVENT_SIGNAL || event == EVENT_TABCLOSED) { fname = vim_strsave(fname); } else { diff --git a/src/nvim/option.c b/src/nvim/option.c index c57e6649bb..3914e020b1 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4240,8 +4240,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } else if (pp == &curbuf->b_p_channel || pp == &p_channel) { errmsg = e_invarg; } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { - if (value < -1 || value > SB_MAX - || (value != -1 && opt_flags == OPT_LOCAL && !curbuf->terminal)) { + if (value < -1 || value > SB_MAX) { errmsg = e_invarg; } } else if (pp == &curbuf->b_p_sw || pp == &p_sw) { @@ -4435,11 +4434,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; } - if (pp == &curbuf->b_p_scbk && !curbuf->terminal) { - // Normal buffer: reset local 'scrollback' after updating the global value. - curbuf->b_p_scbk = -1; - } - options[opt_idx].flags |= P_WAS_SET; // Don't do this while starting up, failure or recursively. @@ -5862,7 +5856,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_ai = p_ai; buf->b_p_ai_nopaste = p_ai_nopaste; buf->b_p_sw = p_sw; - buf->b_p_scbk = -1; + buf->b_p_scbk = p_scbk; buf->b_p_tw = p_tw; buf->b_p_tw_nopaste = p_tw_nopaste; buf->b_p_tw_nobin = p_tw_nobin; diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 222ec5457b..127c15dd5a 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1930,7 +1930,7 @@ return { vi_def=true, varname='p_scbk', redraw={'current_buffer'}, - defaults={if_true={vi=10000}} + defaults={if_true={vi=-1}} }, { full_name='scrollbind', abbreviation='scb', diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index fc7f9cefd1..20f68233e7 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -15,6 +15,7 @@ #include "nvim/globals.h" #include "nvim/memline.h" #include "nvim/eval.h" +#include "nvim/fileio.h" #include "nvim/main.h" #include "nvim/memory.h" #include "nvim/misc1.h" @@ -22,7 +23,7 @@ #include "nvim/os/signal.h" #include "nvim/event/loop.h" -static SignalWatcher spipe, shup, squit, sterm; +static SignalWatcher spipe, shup, squit, sterm, susr1; #ifdef SIGPWR static SignalWatcher spwr; #endif @@ -61,6 +62,10 @@ void signal_init(void) signal_watcher_init(&main_loop, &spwr, NULL); signal_watcher_start(&spwr, on_signal, SIGPWR); #endif +#ifdef SIGUSR1 + signal_watcher_init(&main_loop, &susr1, NULL); + signal_watcher_start(&susr1, on_signal, SIGUSR1); +#endif } void signal_teardown(void) @@ -73,6 +78,9 @@ void signal_teardown(void) #ifdef SIGPWR signal_watcher_close(&spwr, NULL); #endif +#ifdef SIGUSR1 + signal_watcher_close(&susr1, NULL); +#endif } void signal_stop(void) @@ -84,6 +92,9 @@ void signal_stop(void) #ifdef SIGPWR signal_watcher_stop(&spwr); #endif +#ifdef SIGUSR1 + signal_watcher_stop(&susr1); +#endif } void signal_reject_deadly(void) @@ -115,6 +126,10 @@ static char * signal_name(int signum) #endif case SIGHUP: return "SIGHUP"; +#ifdef SIGUSR1 + case SIGUSR1: + return "SIGUSR1"; +#endif default: return "Unknown"; } @@ -162,6 +177,12 @@ static void on_signal(SignalWatcher *handle, int signum, void *data) deadly_signal(signum); } break; +#ifdef SIGUSR1 + case SIGUSR1: + apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGUSR1", curbuf->b_fname, true, + curbuf); + break; +#endif default: ELOG("invalid signal: %d", signum); break; diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 33050ac642..5d8c29a5ad 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -236,7 +236,7 @@ Terminal *terminal_open(TerminalOptions opts) // Default settings for terminal buffers curbuf->b_p_ma = false; // 'nomodifiable' curbuf->b_p_ul = -1; // 'undolevels' - curbuf->b_p_scbk = p_scbk; // 'scrollback' + curbuf->b_p_scbk = (p_scbk == -1) ? 10000 : MAX(1, p_scbk); // 'scrollback' curbuf->b_p_tw = 0; // 'textwidth' set_option_value("wrap", false, NULL, OPT_LOCAL); set_option_value("list", false, NULL, OPT_LOCAL); @@ -249,8 +249,7 @@ Terminal *terminal_open(TerminalOptions opts) apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf); // Configure the scrollback buffer. - rv->sb_size = curbuf->b_p_scbk < 0 - ? SB_MAX : (size_t)MAX(1, curbuf->b_p_scbk); + rv->sb_size = (size_t)curbuf->b_p_scbk; rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size); if (!true_color) { @@ -1162,8 +1161,10 @@ static void refresh_size(Terminal *term, buf_T *buf) /// Adjusts scrollback storage after 'scrollback' option changed. static void on_scrollback_option_changed(Terminal *term, buf_T *buf) { - const size_t scbk = curbuf->b_p_scbk < 0 - ? SB_MAX : (size_t)MAX(1, curbuf->b_p_scbk); + if (buf->b_p_scbk < 1) { + buf->b_p_scbk = SB_MAX; + } + const size_t scbk = (size_t)buf->b_p_scbk; assert(term->sb_current < SIZE_MAX); if (term->sb_pending > 0) { // Pending rows must be processed first. abort(); diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua new file mode 100644 index 0000000000..719adeaf1b --- /dev/null +++ b/test/functional/autocmd/signal_spec.lua @@ -0,0 +1,38 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local funcs = helpers.funcs +local next_msg = helpers.next_msg + +if helpers.pending_win32(pending) then + -- Only applies to POSIX systems. + return +end + +local function posix_kill(signame, pid) + os.execute('kill -s '..signame..' -- '..pid..' >/dev/null') +end + +describe('autocmd Signal', function() + before_each(clear) + + it('matches *', function() + command('autocmd Signal * call rpcnotify(1, "foo")') + posix_kill('USR1', funcs.getpid()) + eq({'notification', 'foo', {}}, next_msg()) + end) + + it('matches SIGUSR1', function() + command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")') + posix_kill('USR1', funcs.getpid()) + eq({'notification', 'foo', {}}, next_msg()) + end) + + it('does not match unknown patterns', function() + command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")') + posix_kill('USR1', funcs.getpid()) + eq(nil, next_msg(500)) + end) +end) diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 38c7e385cc..7c74e82d17 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -481,25 +481,10 @@ describe("'scrollback' option", function() eq(-1, curbufmeths.get_option('scrollback')) end) - it(':setlocal in a normal buffer is an error', function() - command('new') - - -- :setlocal to -1 is NOT an error. - feed_command('setlocal scrollback=-1') - eq(nil, string.match(eval("v:errmsg"), "E%d*:")) - feed('<CR>') - - -- :setlocal to anything except -1 is an error. - feed_command('setlocal scrollback=42') - feed('<CR>') - eq('E474:', string.match(eval("v:errmsg"), "E%d*:")) - eq(-1, curbufmeths.get_option('scrollback')) - end) - it(':set updates local value and global default', function() set_fake_shell() - command('set scrollback=42') -- set global and (attempt) local - eq(-1, curbufmeths.get_option('scrollback')) -- normal buffer: -1 + command('set scrollback=42') -- set global value + eq(42, curbufmeths.get_option('scrollback')) command('terminal') eq(42, curbufmeths.get_option('scrollback')) -- inherits global default command('setlocal scrollback=99') |