diff options
-rw-r--r-- | Makefile | 27 | ||||
-rw-r--r-- | src/nvim/terminal.c | 8 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 41 |
3 files changed, 51 insertions, 25 deletions
@@ -13,21 +13,9 @@ CMAKE_EXTRA_FLAGS ?= # CMAKE_INSTALL_PREFIX # - May be passed directly or as part of CMAKE_EXTRA_FLAGS. -# - Fail if the given value does not match the CMake cached value. #9615 -CACHED_PREFIX := $(shell $(CMAKE_PRG) -L -N build | 2>/dev/null \ - grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2) +# - `checkprefix` target checks that it matches the CMake-cached value. #9615 CMAKE_INSTALL_PREFIX ?= $(shell echo $(CMAKE_EXTRA_FLAGS) | 2>/dev/null \ grep -o 'CMAKE_INSTALL_PREFIX=[^ ]\+' | cut -d '=' -f2) -ifneq (,$(CMAKE_INSTALL_PREFIX)) - ifneq (,$(CACHED_PREFIX)) - ifneq ($(CMAKE_INSTALL_PREFIX),$(CACHED_PREFIX)) - $(info error: CMAKE_INSTALL_PREFIX "$(CMAKE_INSTALL_PREFIX)" does not match cached value "$(CACHED_PREFIX)") - $(info . Run this command, then try again:) - $(info . cmake build -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)) - $(error error) - endif - endif -endif BUILD_TYPE ?= $(shell (type ninja > /dev/null 2>&1 && echo "Ninja") || \ echo "Unix Makefiles") @@ -78,7 +66,7 @@ SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE) all: nvim -nvim: build/.ran-cmake deps +nvim: checkprefix build/.ran-cmake deps +$(BUILD_CMD) -C build libnvim: build/.ran-cmake deps @@ -177,4 +165,13 @@ appimage-%: lint: check-single-includes clint testlint lualint -.PHONY: test testlint lualint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage +checkprefix: + @cached_prefix=$$($(CMAKE_PRG) -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \ + if [ -n "$(CMAKE_INSTALL_PREFIX)" ] && ! [ "$(CMAKE_INSTALL_PREFIX)" = "$$cached_prefix" ]; then \ + printf "\nerror: CMAKE_INSTALL_PREFIX '$(CMAKE_INSTALL_PREFIX)' does not match cached value '%s'\n" "$$cached_prefix"; \ + printf " Run this command, then try again:\n"; \ + printf " cmake build -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)\n"; \ + exit 1; \ + fi; + +.PHONY: test testlint lualint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 5d8c29a5ad..8b4ad4d3af 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -236,7 +236,8 @@ 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 == -1) ? 10000 : MAX(1, p_scbk); // 'scrollback' + curbuf->b_p_scbk = // 'scrollback' (initialize local from global) + (p_scbk < 0) ? 10000 : MAX(1, p_scbk); curbuf->b_p_tw = 0; // 'textwidth' set_option_value("wrap", false, NULL, OPT_LOCAL); set_option_value("list", false, NULL, OPT_LOCAL); @@ -244,9 +245,10 @@ Terminal *terminal_open(TerminalOptions opts) RESET_BINDING(curwin); // Reset cursor in current window. curwin->w_cursor = (pos_T){ .lnum = 1, .col = 0, .coladd = 0 }; - // Apply TermOpen autocmds _before_ configuring the scrollback buffer. apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf); + // Local 'scrollback' _after_ autocmds. + curbuf->b_p_scbk = (curbuf->b_p_scbk < 1) ? SB_MAX : curbuf->b_p_scbk; // Configure the scrollback buffer. rv->sb_size = (size_t)curbuf->b_p_scbk; @@ -1161,7 +1163,7 @@ 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) { - if (buf->b_p_scbk < 1) { + if (buf->b_p_scbk < 1) { // Local 'scrollback' was set to -1. buf->b_p_scbk = SB_MAX; } const size_t scbk = (size_t)buf->b_p_scbk; diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 7c74e82d17..75bb89a1ab 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -10,6 +10,7 @@ local wait = helpers.wait local retry = helpers.retry local curbufmeths = helpers.curbufmeths local nvim = helpers.nvim +local expect_err = helpers.expect_err local feed_data = thelpers.feed_data describe(':terminal scrollback', function() @@ -467,13 +468,8 @@ describe("'scrollback' option", function() end) 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*:")) - - status, rv = pcall(command, 'set scrollback=100001') - eq(false, status) -- assert failure - eq('E474:', string.match(rv, "E%d*:")) + expect_err('E474:', command, 'set scrollback=-2') + expect_err('E474:', command, 'set scrollback=100001') end) it('defaults to -1 on normal buffers', function() @@ -481,6 +477,37 @@ describe("'scrollback' option", function() eq(-1, curbufmeths.get_option('scrollback')) end) + it(':setlocal in a :terminal buffer', function() + set_fake_shell() + + -- _Global_ scrollback=-1 defaults :terminal to 10_000. + command('setglobal scrollback=-1') + command('terminal') + eq(10000, curbufmeths.get_option('scrollback')) + + -- _Local_ scrollback=-1 in :terminal forces the _maximum_. + command('setlocal scrollback=-1') + retry(nil, nil, function() -- Fixup happens on refresh, not immediately. + eq(100000, curbufmeths.get_option('scrollback')) + end) + + -- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605 + command('setglobal scrollback=-1') + command('autocmd TermOpen * setlocal scrollback=-1') + command('terminal') + eq(100000, curbufmeths.get_option('scrollback')) + end) + + it(':setlocal in a normal buffer', function() + command('new') + -- :setlocal to -1. + command('setlocal scrollback=-1') + eq(-1, curbufmeths.get_option('scrollback')) + -- :setlocal to anything except -1. Currently, this just has no effect. + command('setlocal scrollback=42') + eq(42, curbufmeths.get_option('scrollback')) + end) + it(':set updates local value and global default', function() set_fake_shell() command('set scrollback=42') -- set global value |