aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/options.txt14
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/option.c21
-rw-r--r--src/nvim/option_defs.h3
-rw-r--r--src/nvim/options.lua2
-rw-r--r--src/nvim/terminal.c13
-rw-r--r--test/functional/terminal/scrollback_spec.lua37
7 files changed, 53 insertions, 39 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 1cb14f7771..c31ebf4ebc 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -398,20 +398,6 @@ command, not when assigning a value to an option with ":let".
Note the maximum length of an expanded option is limited. How much depends on
the system, mostly it is something like 256 or 1024 characters.
- *Linux-backspace*
- Note about Linux: By default the backspace key
- produces CTRL-?, which is wrong. You can fix it by
- putting this line in your rc.local: >
- echo "keycode 14 = BackSpace" | loadkeys
-<
- *NetBSD-backspace*
- Note about NetBSD: If your backspace doesn't produce
- the right code, try this: >
- xmodmap -e "keycode 22 = BackSpace"
-< If this works, add this in your .Xmodmap file: >
- keysym 22 = BackSpace
-< You need to restart for this to take effect.
-
==============================================================================
2. Automatically setting options *auto-setting*
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index ad14ec4f8c..de79ee2469 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -1255,7 +1255,7 @@ typedef enum {
kCdScopeInvalid = -1,
kCdScopeWindow, ///< Affects one window.
kCdScopeTab, ///< Affects one tab page.
- kCdScopeGlobal, ///< Affects the entire instance of Neovim.
+ kCdScopeGlobal, ///< Affects the entire Nvim instance.
} CdScope;
#define MIN_CD_SCOPE kCdScopeWindow
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 2a17ca69d1..b037b0ae35 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -156,7 +156,6 @@ static long p_ts;
static long p_tw;
static int p_udf;
static long p_wm;
-static long p_scbk;
static char_u *p_keymap;
/* Saved values for when 'bin' is set. */
@@ -4199,16 +4198,13 @@ set_num_option (
FOR_ALL_TAB_WINDOWS(tp, wp) {
check_colorcolumn(wp);
}
- } else if (pp == &curbuf->b_p_scbk) {
+ } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) {
// 'scrollback'
- if (!curbuf->terminal) {
+ if (*pp < -1 || *pp > SB_MAX
+ || (opt_flags == OPT_LOCAL && !curbuf->terminal)) {
errmsg = e_invarg;
- curbuf->b_p_scbk = -1;
- } else {
- if (curbuf->b_p_scbk < -1 || curbuf->b_p_scbk > 100000) {
- errmsg = e_invarg;
- curbuf->b_p_scbk = 1000;
- }
+ *pp = old_value;
+ } else if (curbuf->terminal) {
// Force the scrollback to take effect.
terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX);
}
@@ -4331,6 +4327,11 @@ set_num_option (
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
*(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;
if (!starting && errmsg == NULL) {
@@ -4586,7 +4587,7 @@ get_option_value (
//
// Pretends that option is absent if it is not present in the requested scope
// (i.e. has no global, window-local or buffer-local value depending on
-// opt_type). Uses
+// opt_type).
//
// Returned flags:
// 0 hidden or unknown option, also option that does not have requested
diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h
index b171b23edb..94c6361236 100644
--- a/src/nvim/option_defs.h
+++ b/src/nvim/option_defs.h
@@ -524,6 +524,7 @@ EXTERN int p_ru; // 'ruler'
EXTERN char_u *p_ruf; // 'rulerformat'
EXTERN char_u *p_pp; // 'packpath'
EXTERN char_u *p_rtp; // 'runtimepath'
+EXTERN long p_scbk; // 'scrollback'
EXTERN long p_sj; // 'scrolljump'
EXTERN long p_so; // 'scrolloff'
EXTERN char_u *p_sbo; // 'scrollopt'
@@ -811,4 +812,6 @@ enum {
/* Value for b_p_ul indicating the global value must be used. */
#define NO_LOCAL_UNDOLEVEL -123456
+#define SB_MAX 100000 // Maximum 'scrollback' value.
+
#endif // NVIM_OPTION_DEFS_H
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 853c2b52d7..ee2b8a563d 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -1918,7 +1918,7 @@ return {
vi_def=true,
varname='p_scbk',
redraw={'current_buffer'},
- defaults={if_true={vi=-1}}
+ defaults={if_true={vi=1000}}
},
{
full_name='scrollbind', abbreviation='scb',
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 87ee8f410f..dc418e25fa 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -85,8 +85,6 @@ typedef struct terminal_state {
# include "terminal.c.generated.h"
#endif
-#define SB_MAX 100000 // Maximum 'scrollback' value.
-
// Delay for refreshing the terminal buffer after receiving updates from
// libvterm. Improves performance when receiving large bursts of data.
#define REFRESH_DELAY 10
@@ -231,10 +229,10 @@ Terminal *terminal_open(TerminalOptions opts)
set_option_value((uint8_t *)"buftype", 0, (uint8_t *)"terminal", OPT_LOCAL);
// Default settings for terminal buffers
- curbuf->b_p_ma = false; // 'nomodifiable'
- curbuf->b_p_ul = -1; // 'undolevels'
- curbuf->b_p_scbk = 1000; // 'scrollback'
- curbuf->b_p_tw = 0; // 'textwidth'
+ curbuf->b_p_ma = false; // 'nomodifiable'
+ curbuf->b_p_ul = -1; // 'undolevels'
+ curbuf->b_p_scbk = p_scbk; // 'scrollback'
+ curbuf->b_p_tw = 0; // 'textwidth'
set_option_value((uint8_t *)"wrap", false, NULL, OPT_LOCAL);
set_option_value((uint8_t *)"number", false, NULL, OPT_LOCAL);
set_option_value((uint8_t *)"relativenumber", false, NULL, OPT_LOCAL);
@@ -248,7 +246,8 @@ 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)curbuf->b_p_scbk;;
+ rv->sb_size = curbuf->b_p_scbk < 0
+ ? SB_MAX : (size_t)MAX(1, curbuf->b_p_scbk);
rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size);
if (!true_color) {
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index 81649f2bde..4ead288a19 100644
--- a/test/functional/terminal/scrollback_spec.lua
+++ b/test/functional/terminal/scrollback_spec.lua
@@ -8,6 +8,7 @@ local command = helpers.command
local wait = helpers.wait
local retry = helpers.retry
local curbufmeths = helpers.curbufmeths
+local nvim = helpers.nvim
local feed_data = thelpers.feed_data
if helpers.pending_win32(pending) then return end
@@ -368,6 +369,12 @@ describe("'scrollback' option", function()
clear()
end)
+ local function set_fake_shell()
+ -- shell-test.c is a fake shell that prints its arguments and exits.
+ nvim('set_option', 'shell', nvim_dir..'/shell-test')
+ nvim('set_option', 'shellcmdflag', 'EXE')
+ end
+
local function expect_lines(expected, epsilon)
local ep = epsilon and epsilon or 0
local actual = eval("line('$')")
@@ -421,12 +428,13 @@ describe("'scrollback' option", function()
screen:detach()
end)
- it('defaults to 1000', function()
- execute('terminal')
+ it('defaults to 1000 in terminal buffers', function()
+ set_fake_shell()
+ command('terminal')
eq(1000, curbufmeths.get_option('scrollback'))
end)
- it('error if set to invalid values', function()
+ it('error if set to invalid value', function()
local status, rv = pcall(command, 'set scrollback=-2')
eq(false, status) -- assert failure
eq('E474:', string.match(rv, "E%d*:"))
@@ -437,15 +445,32 @@ describe("'scrollback' option", function()
end)
it('defaults to -1 on normal buffers', function()
- execute('new')
+ command('new')
eq(-1, curbufmeths.get_option('scrollback'))
end)
- it('error if set on a normal buffer', function()
+ it(':setlocal in a normal buffer is an error', function()
command('new')
- execute('set scrollback=42')
+ execute('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('terminal')
+ eq(42, curbufmeths.get_option('scrollback')) -- inherits global default
+ command('setlocal scrollback=99')
+ eq(99, curbufmeths.get_option('scrollback'))
+ command('set scrollback<') -- reset to global default
+ eq(42, curbufmeths.get_option('scrollback'))
+ command('setglobal scrollback=734') -- new global default
+ eq(42, curbufmeths.get_option('scrollback')) -- local value did not change
+ command('terminal')
+ eq(734, curbufmeths.get_option('scrollback'))
end)
end)