terminal: global 'scrollback' #6352

Make the 'scrollback' option work like most other buffer-local options:
- `:set scrollback=x` sets the global and local value
- `:setglobal scrollback=x` sets only the global default
- new terminal buffers inherit the global

Normal buffers are still always -1, and :setlocal there is an error.

Closes #6337
This commit is contained in:
Jakob Schnitzer
2017-03-24 20:21:05 +01:00
committed by Justin M. Keyes
parent 2b1398c31e
commit 7bc37ffb22
7 changed files with 53 additions and 39 deletions

View File

@@ -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*

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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',

View File

@@ -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
@@ -233,7 +231,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 = 1000; // 'scrollback'
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);
@@ -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) {

View File

@@ -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)