Skip to content

Commit af2d20c

Browse files
committed
patch 8.0.1237: ":set scroll&" often gives an error
Problem: ":set scroll&" often gives an error. Solution: Don't use a fixed default value, use half the window height. Add a test. (Ozaki Kiichi, closes #2104)
1 parent d057301 commit af2d20c

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,7 @@ test_arglist \
22422242
test_reltime \
22432243
test_retab \
22442244
test_ruby \
2245+
test_scroll_opt \
22452246
test_scrollbind \
22462247
test_search \
22472248
test_searchpos \

src/option.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@ static struct vimoption options[] =
23592359
SCRIPTID_INIT},
23602360
{"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
23612361
(char_u *)VAR_WIN, PV_SCROLL,
2362-
{(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
2362+
{(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
23632363
{"scrollbind", "scb", P_BOOL|P_VI_DEF,
23642364
#ifdef FEAT_SCROLLBIND
23652365
(char_u *)VAR_WIN, PV_SCBIND,
@@ -3904,10 +3904,9 @@ set_init_2(void)
39043904
int idx;
39053905

39063906
/*
3907-
* 'scroll' defaults to half the window height. Note that this default is
3908-
* wrong when the window height changes.
3907+
* 'scroll' defaults to half the window height. The stored default is zero,
3908+
* which results in the actual value computed from the window height.
39093909
*/
3910-
set_number_default("scroll", (long)((long_u)Rows >> 1));
39113910
idx = findoption((char_u *)"scroll");
39123911
if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
39133912
set_option_default(idx, OPT_LOCAL, p_cp);

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ source test_popup.vim
4141
source test_put.vim
4242
source test_recover.vim
4343
source test_reltime.vim
44+
source test_scroll_opt.vim
4445
source test_searchpos.vim
4546
source test_set.vim
4647
source test_sort.vim

src/testdir/test_scroll_opt.vim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
" Test for reset 'scroll'
2+
"
3+
4+
func Test_reset_scroll()
5+
let scr = &l:scroll
6+
7+
setlocal scroll=1
8+
setlocal scroll&
9+
call assert_equal(scr, &l:scroll)
10+
11+
setlocal scroll=1
12+
setlocal scroll=0
13+
call assert_equal(scr, &l:scroll)
14+
15+
try
16+
execute 'setlocal scroll=' . (winheight(0) + 1)
17+
" not reached
18+
call assert_false(1)
19+
catch
20+
call assert_exception('E49:')
21+
endtry
22+
23+
split
24+
25+
let scr = &l:scroll
26+
27+
setlocal scroll=1
28+
setlocal scroll&
29+
call assert_equal(scr, &l:scroll)
30+
31+
setlocal scroll=1
32+
setlocal scroll=0
33+
call assert_equal(scr, &l:scroll)
34+
35+
quit!
36+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1237,
764766
/**/
765767
1236,
766768
/**/

0 commit comments

Comments
 (0)