refactor(options): use os_win/os_buf for local options (#31060)

Conversely, don't use them for global options.
This commit is contained in:
zeertzjq 2024-11-08 14:54:28 +08:00 committed by GitHub
parent 8af1702647
commit f83a31b49d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 22 deletions

View File

@ -1886,7 +1886,7 @@ static const char *did_set_arabic(optset_T *args)
// set rightleft mode // set rightleft mode
if (!win->w_p_rl) { if (!win->w_p_rl) {
win->w_p_rl = true; win->w_p_rl = true;
changed_window_setting(curwin); changed_window_setting(win);
} }
// Enable Arabic shaping (major part of what Arabic requires) // Enable Arabic shaping (major part of what Arabic requires)
@ -1917,7 +1917,7 @@ static const char *did_set_arabic(optset_T *args)
// reset rightleft mode // reset rightleft mode
if (win->w_p_rl) { if (win->w_p_rl) {
win->w_p_rl = false; win->w_p_rl = false;
changed_window_setting(curwin); changed_window_setting(win);
} }
// 'arabicshape' isn't reset, it is a global option and // 'arabicshape' isn't reset, it is a global option and
@ -1928,8 +1928,8 @@ static const char *did_set_arabic(optset_T *args)
// window may still want it "on". // window may still want it "on".
// Revert to the default keymap // Revert to the default keymap
curbuf->b_p_iminsert = B_IMODE_NONE; win->w_buffer->b_p_iminsert = B_IMODE_NONE;
curbuf->b_p_imsearch = B_IMODE_USE_INSERT; win->w_buffer->b_p_imsearch = B_IMODE_USE_INSERT;
} }
return errmsg; return errmsg;
@ -2051,9 +2051,7 @@ static const char *did_set_helpheight(optset_T *args)
{ {
// Change window height NOW // Change window height NOW
if (!ONE_WINDOW) { if (!ONE_WINDOW) {
buf_T *buf = (buf_T *)args->os_buf; if (curbuf->b_help && curwin->w_height < p_hh) {
win_T *win = (win_T *)args->os_win;
if (buf->b_help && win->w_height < p_hh) {
win_setheight((int)p_hh); win_setheight((int)p_hh);
} }
} }
@ -2382,14 +2380,16 @@ static const char *did_set_pumblend(optset_T *args FUNC_ATTR_UNUSED)
/// Process the updated 'readonly' option value. /// Process the updated 'readonly' option value.
static const char *did_set_readonly(optset_T *args) static const char *did_set_readonly(optset_T *args)
{ {
buf_T *buf = (buf_T *)args->os_buf;
// when 'readonly' is reset globally, also reset readonlymode // when 'readonly' is reset globally, also reset readonlymode
if (!curbuf->b_p_ro && (args->os_flags & OPT_LOCAL) == 0) { if (!buf->b_p_ro && (args->os_flags & OPT_LOCAL) == 0) {
readonlymode = false; readonlymode = false;
} }
// when 'readonly' is set may give W10 again // when 'readonly' is set may give W10 again
if (curbuf->b_p_ro) { if (buf->b_p_ro) {
curbuf->b_did_warn = false; buf->b_did_warn = false;
} }
redraw_titles(); redraw_titles();
@ -2505,8 +2505,7 @@ static const char *did_set_swapfile(optset_T *args)
if (buf->b_p_swf && p_uc) { if (buf->b_p_swf && p_uc) {
ml_open_file(buf); // create the swap file ml_open_file(buf); // create the swap file
} else { } else {
// no need to reset curbuf->b_may_swap, ml_open_file() will check // no need to reset buf->b_may_swap, ml_open_file() will check buf->b_p_swf
// buf->b_p_swf
mf_close_file(buf, true); // remove the swap file mf_close_file(buf, true); // remove the swap file
} }
return NULL; return NULL;
@ -2546,8 +2545,10 @@ static const char *did_set_titlelen(optset_T *args)
/// Process the updated 'undofile' option value. /// Process the updated 'undofile' option value.
static const char *did_set_undofile(optset_T *args) static const char *did_set_undofile(optset_T *args)
{ {
buf_T *buf = (buf_T *)args->os_buf;
// Only take action when the option was set. // Only take action when the option was set.
if (!curbuf->b_p_udf && !p_udf) { if (!buf->b_p_udf && !p_udf) {
return NULL; return NULL;
} }
@ -2560,7 +2561,7 @@ static const char *did_set_undofile(optset_T *args)
// only for the current buffer: Try to read in the undofile, // only for the current buffer: Try to read in the undofile,
// if one exists, the buffer wasn't changed and the buffer was // if one exists, the buffer wasn't changed and the buffer was
// loaded // loaded
if ((curbuf == bp if ((buf == bp
|| (args->os_flags & OPT_GLOBAL) || args->os_flags == 0) || (args->os_flags & OPT_GLOBAL) || args->os_flags == 0)
&& !bufIsChanged(bp) && bp->b_ml.ml_mfp != NULL) { && !bufIsChanged(bp) && bp->b_ml.ml_mfp != NULL) {
u_compute_hash(bp, hash); u_compute_hash(bp, hash);
@ -2600,7 +2601,7 @@ static const char *did_set_undolevels(optset_T *args)
if (pp == &p_ul) { // global 'undolevels' if (pp == &p_ul) { // global 'undolevels'
did_set_global_undolevels(args->os_newval.number, args->os_oldval.number); did_set_global_undolevels(args->os_newval.number, args->os_oldval.number);
} else if (pp == &curbuf->b_p_ul) { // buffer local 'undolevels' } else if (pp == &buf->b_p_ul) { // buffer local 'undolevels'
did_set_buflocal_undolevels(buf, args->os_newval.number, args->os_oldval.number); did_set_buflocal_undolevels(buf, args->os_newval.number, args->os_oldval.number);
} }
@ -2665,8 +2666,7 @@ static const char *did_set_winheight(optset_T *args)
{ {
// Change window height NOW // Change window height NOW
if (!ONE_WINDOW) { if (!ONE_WINDOW) {
win_T *win = (win_T *)args->os_win; if (curwin->w_height < p_wh) {
if (win->w_height < p_wh) {
win_setheight((int)p_wh); win_setheight((int)p_wh);
} }
} }
@ -2677,9 +2677,7 @@ static const char *did_set_winheight(optset_T *args)
/// Process the new 'winwidth' option value. /// Process the new 'winwidth' option value.
static const char *did_set_winwidth(optset_T *args) static const char *did_set_winwidth(optset_T *args)
{ {
win_T *win = (win_T *)args->os_win; if (!ONE_WINDOW && curwin->w_width < p_wiw) {
if (!ONE_WINDOW && win->w_width < p_wiw) {
win_setwidth((int)p_wiw); win_setwidth((int)p_wiw);
} }
return NULL; return NULL;

View File

@ -892,10 +892,11 @@ int expand_set_chars_option(optexpand_T *args, int *numMatches, char ***matches)
} }
/// The 'cinoptions' option is changed. /// The 'cinoptions' option is changed.
const char *did_set_cinoptions(optset_T *args FUNC_ATTR_UNUSED) const char *did_set_cinoptions(optset_T *args)
{ {
buf_T *buf = (buf_T *)args->os_buf;
// TODO(vim): recognize errors // TODO(vim): recognize errors
parse_cino(curbuf); parse_cino(buf);
return NULL; return NULL;
} }