Skip to content

Commit

Permalink
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidesc…
Browse files Browse the repository at this point in the history
…rolloff'

Problem:    Cannot have a local value for 'scrolloff' and 'sidescrolloff'.
            (Gary Holloway)
Solution:   Make 'scrolloff' and 'sidescrolloff' global-local. (mostly by
            Aron Widforss, closes #3539)
  • Loading branch information
brammool committed Jan 31, 2019
1 parent b3051ce commit 375e339
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 67 deletions.
16 changes: 12 additions & 4 deletions runtime/doc/options.txt
Expand Up @@ -6590,14 +6590,18 @@ A jump table for the options with a short description can be found at |Q_op|.

*'scrolloff'* *'so'*
'scrolloff' 'so' number (default 0, set to 5 in |defaults.vim|)
global
global or local to window |global-local|
{not in Vi}
Minimal number of screen lines to keep above and below the cursor.
This will make some context visible around where you are working. If
you set it to a very large value (999) the cursor line will always be
in the middle of the window (except at the start or end of the file or
when long lines wrap).
For scrolling horizontally see 'sidescrolloff'.
After using the local value, go back the global value with one of
these two: >
setlocal scrolloff<
setlocal scrolloff=-1
< For scrolling horizontally see 'sidescrolloff'.
NOTE: This option is set to 0 when 'compatible' is set.

*'scrollopt'* *'sbo'*
Expand Down Expand Up @@ -7152,7 +7156,7 @@ A jump table for the options with a short description can be found at |Q_op|.

*'sidescrolloff'* *'siso'*
'sidescrolloff' 'siso' number (default 0)
global
global or local to window |global-local|
{not in Vi}
The minimal number of screen columns to keep to the left and to the
right of the cursor if 'nowrap' is set. Setting this option to a
Expand All @@ -7162,7 +7166,11 @@ A jump table for the options with a short description can be found at |Q_op|.
to a large value (like 999) has the effect of keeping the cursor
horizontally centered in the window, as long as one does not come too
close to the beginning of the line.
NOTE: This option is set to 0 when 'compatible' is set.
After using the local value, go back the global value with one of
these two: >
setlocal sidescrolloff<
setlocal sidescrolloff=-1
< NOTE: This option is set to 0 when 'compatible' is set.

Example: Try this together with 'sidescroll' and 'listchars' as
in the following example to never allow the cursor to move
Expand Down
2 changes: 1 addition & 1 deletion src/edit.c
Expand Up @@ -728,7 +728,7 @@ edit(
(int)curwin->w_wcol < mincol - curbuf->b_p_ts
#endif
&& curwin->w_wrow == W_WINROW(curwin)
+ curwin->w_height - 1 - p_so
+ curwin->w_height - 1 - get_scrolloff_value()
&& (curwin->w_cursor.lnum != curwin->w_topline
#ifdef FEAT_DIFF
|| curwin->w_topfill > 0
Expand Down
7 changes: 4 additions & 3 deletions src/ex_cmds.c
Expand Up @@ -3784,6 +3784,7 @@ do_ecmd(
#endif
int readfile_flags = 0;
int did_inc_redrawing_disabled = FALSE;
long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so;

if (eap != NULL)
command = eap->do_ecmd_cmd;
Expand Down Expand Up @@ -4389,12 +4390,12 @@ do_ecmd(
did_inc_redrawing_disabled = FALSE;
if (!skip_redraw)
{
n = p_so;
n = *so_ptr;
if (topline == 0 && command == NULL)
p_so = 999; /* force cursor halfway the window */
*so_ptr = 9999; // force cursor halfway the window
update_topline();
curwin->w_scbind_pos = curwin->w_topline;
p_so = n;
*so_ptr = n;
redraw_curbuf_later(NOT_VALID); /* redraw this buffer later */
}

Expand Down
2 changes: 1 addition & 1 deletion src/ex_docmd.c
Expand Up @@ -8923,7 +8923,7 @@ ex_syncbind(exarg_T *eap UNUSED)
{
if (wp->w_p_scb && wp->w_buffer)
{
y = wp->w_buffer->b_ml.ml_line_count - p_so;
y = wp->w_buffer->b_ml.ml_line_count - get_scrolloff_value();
if (topline > y)
topline = y;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui.c
Expand Up @@ -4405,7 +4405,7 @@ gui_do_scroll(void)
#endif
)
{
if (p_so != 0)
if (get_scrolloff_value() != 0)
{
cursor_correct(); /* fix window for 'so' */
update_topline(); /* avoid up/down jump */
Expand Down
9 changes: 5 additions & 4 deletions src/misc2.c
Expand Up @@ -643,6 +643,7 @@ leftcol_changed(void)
long lastcol;
colnr_T s, e;
int retval = FALSE;
long siso = get_sidescrolloff_value();

changed_cline_bef_curs();
lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1;
Expand All @@ -652,15 +653,15 @@ leftcol_changed(void)
* If the cursor is right or left of the screen, move it to last or first
* character.
*/
if (curwin->w_virtcol > (colnr_T)(lastcol - p_siso))
if (curwin->w_virtcol > (colnr_T)(lastcol - siso))
{
retval = TRUE;
coladvance((colnr_T)(lastcol - p_siso));
coladvance((colnr_T)(lastcol - siso));
}
else if (curwin->w_virtcol < curwin->w_leftcol + p_siso)
else if (curwin->w_virtcol < curwin->w_leftcol + siso)
{
retval = TRUE;
(void)coladvance((colnr_T)(curwin->w_leftcol + p_siso));
(void)coladvance((colnr_T)(curwin->w_leftcol + siso));
}

/*
Expand Down

0 comments on commit 375e339

Please sign in to comment.