Hello,
Please find attached a patch.
MOTIVATION
The local options for which invalid values have
been defined have actually their values checked
only for local variables but not for global ones.
It matters because global variables of local
options might be used for the initialization of
new local variables.
EXAMPLE
1) Open Vim as you want
2) :e one
3) :setglobal foldcolumn=20
4) :e two
5) :setlocal foldcolumn?
Result> foldcolumn=20
(foldcolumn is supposed to take values between 0
and 12).
PATCH
This patch guarantees that the global and local
variables of all the NUMERIC local options take
only valid values (or more precisely : values that
are currently considered/defined as valid, see
TODO(*)).
In addition, the special cases (for example when
'scroll' is set to 0), which were only handled for
local variables, are now handled for global
variables too when relevant.
For reference, the numeric local options for which
some invalid values are currently defined (which
are the only options for which I added some
changes) are:
'iminsert'
'imsearch'
'shiftwidth'
'tabstop'
'textwidth'
--
'conceallevel'
'foldcolumn'
'foldlevel'
'numberwidth'
'scroll'
(the first five are local to buffers, the five
following are local to windows).
TODO
The same should be done for STRING local options
and maybe also for some string global-local
options ('undolevel' which is the only numeric
global-local option doesn't have any invalid value
defined).
(*)We could also define some invalid values for the
other numeric local options:
'softtabstop'
'synmaxcol'
'wrapmargin'
--
'foldminlines'
'foldnestmax'.
Indeed, negative values don't make much sense for
these options (except for 'softtabstop' but we
could still forbid values strictly inferior to -1).
Best regards,
Arnaud
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -8489,11 +8489,15 @@
#ifdef FEAT_FOLDING
/* 'foldlevel' */
- else if (pp == &curwin->w_p_fdl)
- {
- if (curwin->w_p_fdl < 0)
- curwin->w_p_fdl = 0;
- newFoldLevel();
+ else if (pp == &curwin->w_p_fdl || pp == &curwin->w_allbuf_opt.wo_fdl)
+ {
+ if (*pp < 0)
+ {
+ errmsg = e_positive;
+ *pp = 0;
+ }
+ if (pp == &curwin->w_p_fdl)
+ newFoldLevel();
}
/* 'foldminlines' */
@@ -8510,23 +8514,28 @@
}
/* 'foldcolumn' */
- else if (pp == &curwin->w_p_fdc)
- {
- if (curwin->w_p_fdc < 0)
+ else if (pp == &curwin->w_p_fdc || pp == &curwin->w_allbuf_opt.wo_fdc)
+ {
+ if (*pp < 0)
{
errmsg = e_positive;
- curwin->w_p_fdc = 0;
- }
- else if (curwin->w_p_fdc > 12)
+ *pp = 0;
+ }
+ else if (*pp > 12)
{
errmsg = e_invarg;
- curwin->w_p_fdc = 12;
+ *pp = 12;
}
}
#endif /* FEAT_FOLDING */
+ /* 'shiftwidth' and 'tabstop' */
+ else if (pp == &p_sw && p_sw < 0)
+ {
+ errmsg = e_positive;
+ p_sw = p_ts;
+ }
#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
- /* 'shiftwidth' or 'tabstop' */
else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
{
# ifdef FEAT_FOLDING
@@ -8554,15 +8563,17 @@
}
#endif
- else if (pp == &curbuf->b_p_iminsert)
- {
- if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
+ else if (pp == &curbuf->b_p_iminsert || pp == &p_iminsert)
+ {
+ if (*pp < 0 || *pp > B_IMODE_LAST)
{
errmsg = e_invarg;
- curbuf->b_p_iminsert = B_IMODE_NONE;
- }
- p_iminsert = curbuf->b_p_iminsert;
- if (termcap_active) /* don't do this in the alternate screen */
+ *pp = B_IMODE_NONE;
+ }
+ if (pp == &curbuf->b_p_imsearch)
+ p_iminsert = curbuf->b_p_iminsert;
+ /* don't do this in the alternate screen */
+ if (pp == &curbuf->b_p_iminsert || termcap_active)
showmode();
#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
/* Show/unshow value of 'keymap' in status lines. */
@@ -8577,15 +8588,15 @@
else if (p_window >= Rows)
p_window = Rows - 1;
}
-
- else if (pp == &curbuf->b_p_imsearch)
- {
- if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
+ else if (pp == &curbuf->b_p_imsearch || pp == &p_imsearch)
+ {
+ if (*pp < -1 || *pp > B_IMODE_LAST)
{
errmsg = e_invarg;
- curbuf->b_p_imsearch = B_IMODE_NONE;
- }
- p_imsearch = curbuf->b_p_imsearch;
+ *pp = B_IMODE_NONE;
+ }
+ if (pp == &curbuf->b_p_imsearch)
+ p_imsearch = curbuf->b_p_imsearch;
}
#ifdef FEAT_TITLE
@@ -8635,17 +8646,17 @@
ml_open_files();
}
#ifdef FEAT_CONCEAL
- else if (pp == &curwin->w_p_cole)
- {
- if (curwin->w_p_cole < 0)
+ else if (pp == &curwin->w_p_cole || pp == &curwin->w_allbuf_opt.wo_cole)
+ {
+ if (*pp < 0)
{
errmsg = e_positive;
- curwin->w_p_cole = 0;
- }
- else if (curwin->w_p_cole > 3)
+ *pp = 0;
+ }
+ else if (*pp > 3)
{
errmsg = e_invarg;
- curwin->w_p_cole = 3;
+ *pp = 3;
}
}
#endif
@@ -8672,43 +8683,62 @@
#ifdef FEAT_LINEBREAK
/* 'numberwidth' must be positive */
- else if (pp == &curwin->w_p_nuw)
- {
- if (curwin->w_p_nuw < 1)
+ else if (pp == &curwin->w_p_nuw || pp == &curwin->w_allbuf_opt.wo_nuw)
+ {
+ if (*pp < 1)
{
errmsg = e_positive;
- curwin->w_p_nuw = 1;
- }
- if (curwin->w_p_nuw > 10)
+ *pp = 1;
+ }
+ if (*pp > 10)
{
errmsg = e_invarg;
- curwin->w_p_nuw = 10;
- }
- curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
- }
-#endif
-
- else if (pp == &curbuf->b_p_tw)
- {
- if (curbuf->b_p_tw < 0)
+ *pp = 10;
+ }
+ if (pp == &curwin->w_p_nuw)
+ curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
+ }
+#endif
+
+ else if (pp == &curbuf->b_p_tw || pp == &p_tw)
+ {
+ if (*pp < 0)
{
errmsg = e_positive;
- curbuf->b_p_tw = 0;
+ *pp = 0;
}
#ifdef FEAT_SYN_HL
+ if (pp == &curbuf->b_p_tw)
+ {
# ifdef FEAT_WINDOWS
- {
- win_T *wp;
- tabpage_T *tp;
-
- FOR_ALL_TAB_WINDOWS(tp, wp)
- check_colorcolumn(wp);
- }
+ {
+ win_T *wp;
+ tabpage_T *tp;
+
+ FOR_ALL_TAB_WINDOWS(tp, wp)
+ check_colorcolumn(wp);
+ }
# else
check_colorcolumn(curwin);
# endif
-#endif
- }
+ }
+#endif
+ }
+ /* 'scroll' - global value in current window;
+ * the current local value is handled further below */
+ else if (pp == &curwin->w_allbuf_opt.wo_scr)
+ {
+ if ((*pp < 0 || (*pp > curwin->w_height
+ && curwin->w_height > 0))
+ && full_screen)
+ {
+ errmsg = e_scroll;
+ win_comp_scroll_global(curwin);
+ }
+ else if (*pp == 0 && full_screen)
+ win_comp_scroll_global(curwin);
+ }
+
/*
* Check the bounds for numeric options here
@@ -8773,6 +8803,11 @@
errmsg = e_positive;
curbuf->b_p_ts = 8;
}
+ if (p_ts <= 0)
+ {
+ errmsg = e_positive;
+ p_ts = 8;
+ }
if (p_tm < 0)
{
errmsg = e_positive;
@@ -8782,15 +8817,17 @@
|| (curwin->w_p_scr > curwin->w_height
&& curwin->w_height > 0))
&& full_screen)
- {
+ {
+ /* If 'scroll' was set voluntarily to 0 or an invalid value,
+ * set it to half the window height. */
if (pp == &(curwin->w_p_scr))
{
if (curwin->w_p_scr != 0)
errmsg = e_scroll;
- win_comp_scroll(curwin);
- }
- /* If 'scroll' became invalid because of a side effect silently adjust
- * it. */
+ win_comp_scroll_local(curwin);
+ }
+ /* If 'scroll' became equal to 0 or an invalid value because of
+ * a side effect, silently adjust it. */
else if (curwin->w_p_scr <= 0)
curwin->w_p_scr = 1;
else /* curwin->w_p_scr > curwin->w_height */
diff --git a/src/proto/window.pro b/src/proto/window.pro
--- a/src/proto/window.pro
+++ b/src/proto/window.pro
@@ -56,6 +56,8 @@
void win_new_height __ARGS((win_T *wp, int height));
void win_new_width __ARGS((win_T *wp, int width));
void win_comp_scroll __ARGS((win_T *wp));
+void win_comp_scroll_global __ARGS((win_T *wp));
+void win_comp_scroll_local __ARGS((win_T *wp));
void command_height __ARGS((void));
void last_status __ARGS((int morewin));
int tabline_height __ARGS((void));
diff --git a/src/window.c b/src/window.c
--- a/src/window.c
+++ b/src/window.c
@@ -6017,10 +6017,25 @@
win_comp_scroll(wp)
win_T *wp;
{
+ win_comp_scroll_local(wp);
+ win_comp_scroll_global(wp);
+}
+ void
+win_comp_scroll_local(wp)
+ win_T *wp;
+{
wp->w_p_scr = ((unsigned)wp->w_height >> 1);
if (wp->w_p_scr == 0)
wp->w_p_scr = 1;
}
+ void
+win_comp_scroll_global(wp)
+ win_T *wp;
+{
+ wp->w_allbuf_opt.wo_scr = ((unsigned)wp->w_height >> 1);
+ if (wp->w_allbuf_opt.wo_scr == 0)
+ wp->w_allbuf_opt.wo_scr = 1;
+}
/*
* command_height: called whenever p_ch has been changed