mirror of
https://github.com/neovim/neovim.git
synced 2025-09-25 04:28:33 +00:00
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:

committed by
Justin M. Keyes

parent
2b1398c31e
commit
7bc37ffb22
@@ -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
|
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.
|
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*
|
2. Automatically setting options *auto-setting*
|
||||||
|
|
||||||
|
@@ -1255,7 +1255,7 @@ typedef enum {
|
|||||||
kCdScopeInvalid = -1,
|
kCdScopeInvalid = -1,
|
||||||
kCdScopeWindow, ///< Affects one window.
|
kCdScopeWindow, ///< Affects one window.
|
||||||
kCdScopeTab, ///< Affects one tab page.
|
kCdScopeTab, ///< Affects one tab page.
|
||||||
kCdScopeGlobal, ///< Affects the entire instance of Neovim.
|
kCdScopeGlobal, ///< Affects the entire Nvim instance.
|
||||||
} CdScope;
|
} CdScope;
|
||||||
|
|
||||||
#define MIN_CD_SCOPE kCdScopeWindow
|
#define MIN_CD_SCOPE kCdScopeWindow
|
||||||
|
@@ -156,7 +156,6 @@ static long p_ts;
|
|||||||
static long p_tw;
|
static long p_tw;
|
||||||
static int p_udf;
|
static int p_udf;
|
||||||
static long p_wm;
|
static long p_wm;
|
||||||
static long p_scbk;
|
|
||||||
static char_u *p_keymap;
|
static char_u *p_keymap;
|
||||||
|
|
||||||
/* Saved values for when 'bin' is set. */
|
/* Saved values for when 'bin' is set. */
|
||||||
@@ -4199,16 +4198,13 @@ set_num_option (
|
|||||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||||
check_colorcolumn(wp);
|
check_colorcolumn(wp);
|
||||||
}
|
}
|
||||||
} else if (pp == &curbuf->b_p_scbk) {
|
} else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) {
|
||||||
// 'scrollback'
|
// 'scrollback'
|
||||||
if (!curbuf->terminal) {
|
if (*pp < -1 || *pp > SB_MAX
|
||||||
|
|| (opt_flags == OPT_LOCAL && !curbuf->terminal)) {
|
||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
curbuf->b_p_scbk = -1;
|
*pp = old_value;
|
||||||
} else {
|
} else if (curbuf->terminal) {
|
||||||
if (curbuf->b_p_scbk < -1 || curbuf->b_p_scbk > 100000) {
|
|
||||||
errmsg = e_invarg;
|
|
||||||
curbuf->b_p_scbk = 1000;
|
|
||||||
}
|
|
||||||
// Force the scrollback to take effect.
|
// Force the scrollback to take effect.
|
||||||
terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX);
|
terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX);
|
||||||
}
|
}
|
||||||
@@ -4331,6 +4327,11 @@ set_num_option (
|
|||||||
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
|
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
|
||||||
*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
|
*(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;
|
options[opt_idx].flags |= P_WAS_SET;
|
||||||
|
|
||||||
if (!starting && errmsg == NULL) {
|
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
|
// 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
|
// (i.e. has no global, window-local or buffer-local value depending on
|
||||||
// opt_type). Uses
|
// opt_type).
|
||||||
//
|
//
|
||||||
// Returned flags:
|
// Returned flags:
|
||||||
// 0 hidden or unknown option, also option that does not have requested
|
// 0 hidden or unknown option, also option that does not have requested
|
||||||
|
@@ -524,6 +524,7 @@ EXTERN int p_ru; // 'ruler'
|
|||||||
EXTERN char_u *p_ruf; // 'rulerformat'
|
EXTERN char_u *p_ruf; // 'rulerformat'
|
||||||
EXTERN char_u *p_pp; // 'packpath'
|
EXTERN char_u *p_pp; // 'packpath'
|
||||||
EXTERN char_u *p_rtp; // 'runtimepath'
|
EXTERN char_u *p_rtp; // 'runtimepath'
|
||||||
|
EXTERN long p_scbk; // 'scrollback'
|
||||||
EXTERN long p_sj; // 'scrolljump'
|
EXTERN long p_sj; // 'scrolljump'
|
||||||
EXTERN long p_so; // 'scrolloff'
|
EXTERN long p_so; // 'scrolloff'
|
||||||
EXTERN char_u *p_sbo; // 'scrollopt'
|
EXTERN char_u *p_sbo; // 'scrollopt'
|
||||||
@@ -811,4 +812,6 @@ enum {
|
|||||||
/* Value for b_p_ul indicating the global value must be used. */
|
/* Value for b_p_ul indicating the global value must be used. */
|
||||||
#define NO_LOCAL_UNDOLEVEL -123456
|
#define NO_LOCAL_UNDOLEVEL -123456
|
||||||
|
|
||||||
|
#define SB_MAX 100000 // Maximum 'scrollback' value.
|
||||||
|
|
||||||
#endif // NVIM_OPTION_DEFS_H
|
#endif // NVIM_OPTION_DEFS_H
|
||||||
|
@@ -1918,7 +1918,7 @@ return {
|
|||||||
vi_def=true,
|
vi_def=true,
|
||||||
varname='p_scbk',
|
varname='p_scbk',
|
||||||
redraw={'current_buffer'},
|
redraw={'current_buffer'},
|
||||||
defaults={if_true={vi=-1}}
|
defaults={if_true={vi=1000}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
full_name='scrollbind', abbreviation='scb',
|
full_name='scrollbind', abbreviation='scb',
|
||||||
|
@@ -85,8 +85,6 @@ typedef struct terminal_state {
|
|||||||
# include "terminal.c.generated.h"
|
# include "terminal.c.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SB_MAX 100000 // Maximum 'scrollback' value.
|
|
||||||
|
|
||||||
// Delay for refreshing the terminal buffer after receiving updates from
|
// Delay for refreshing the terminal buffer after receiving updates from
|
||||||
// libvterm. Improves performance when receiving large bursts of data.
|
// libvterm. Improves performance when receiving large bursts of data.
|
||||||
#define REFRESH_DELAY 10
|
#define REFRESH_DELAY 10
|
||||||
@@ -233,7 +231,7 @@ Terminal *terminal_open(TerminalOptions opts)
|
|||||||
// Default settings for terminal buffers
|
// Default settings for terminal buffers
|
||||||
curbuf->b_p_ma = false; // 'nomodifiable'
|
curbuf->b_p_ma = false; // 'nomodifiable'
|
||||||
curbuf->b_p_ul = -1; // 'undolevels'
|
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'
|
curbuf->b_p_tw = 0; // 'textwidth'
|
||||||
set_option_value((uint8_t *)"wrap", false, NULL, OPT_LOCAL);
|
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 *)"number", false, NULL, OPT_LOCAL);
|
||||||
@@ -248,7 +246,8 @@ Terminal *terminal_open(TerminalOptions opts)
|
|||||||
apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf);
|
||||||
|
|
||||||
// Configure the scrollback buffer.
|
// 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);
|
rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size);
|
||||||
|
|
||||||
if (!true_color) {
|
if (!true_color) {
|
||||||
|
@@ -8,6 +8,7 @@ local command = helpers.command
|
|||||||
local wait = helpers.wait
|
local wait = helpers.wait
|
||||||
local retry = helpers.retry
|
local retry = helpers.retry
|
||||||
local curbufmeths = helpers.curbufmeths
|
local curbufmeths = helpers.curbufmeths
|
||||||
|
local nvim = helpers.nvim
|
||||||
local feed_data = thelpers.feed_data
|
local feed_data = thelpers.feed_data
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
if helpers.pending_win32(pending) then return end
|
||||||
@@ -368,6 +369,12 @@ describe("'scrollback' option", function()
|
|||||||
clear()
|
clear()
|
||||||
end)
|
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 function expect_lines(expected, epsilon)
|
||||||
local ep = epsilon and epsilon or 0
|
local ep = epsilon and epsilon or 0
|
||||||
local actual = eval("line('$')")
|
local actual = eval("line('$')")
|
||||||
@@ -421,12 +428,13 @@ describe("'scrollback' option", function()
|
|||||||
screen:detach()
|
screen:detach()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('defaults to 1000', function()
|
it('defaults to 1000 in terminal buffers', function()
|
||||||
execute('terminal')
|
set_fake_shell()
|
||||||
|
command('terminal')
|
||||||
eq(1000, curbufmeths.get_option('scrollback'))
|
eq(1000, curbufmeths.get_option('scrollback'))
|
||||||
end)
|
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')
|
local status, rv = pcall(command, 'set scrollback=-2')
|
||||||
eq(false, status) -- assert failure
|
eq(false, status) -- assert failure
|
||||||
eq('E474:', string.match(rv, "E%d*:"))
|
eq('E474:', string.match(rv, "E%d*:"))
|
||||||
@@ -437,15 +445,32 @@ describe("'scrollback' option", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('defaults to -1 on normal buffers', function()
|
it('defaults to -1 on normal buffers', function()
|
||||||
execute('new')
|
command('new')
|
||||||
eq(-1, curbufmeths.get_option('scrollback'))
|
eq(-1, curbufmeths.get_option('scrollback'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('error if set on a normal buffer', function()
|
it(':setlocal in a normal buffer is an error', function()
|
||||||
command('new')
|
command('new')
|
||||||
execute('set scrollback=42')
|
execute('setlocal scrollback=42')
|
||||||
feed('<CR>')
|
feed('<CR>')
|
||||||
eq('E474:', string.match(eval("v:errmsg"), "E%d*:"))
|
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)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user