mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
vim-patch:8.2.1904: still using default option values after using ":badd +1"
Problem: Still using default option values after using ":badd +1".
Solution: Find a window where options were set. Don't set the window when
using ":badd".
89b693e562
This commit is contained in:
@@ -1726,7 +1726,8 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
|
|||||||
file_id_valid)) != NULL) {
|
file_id_valid)) != NULL) {
|
||||||
xfree(ffname);
|
xfree(ffname);
|
||||||
if (lnum != 0) {
|
if (lnum != 0) {
|
||||||
buflist_setfpos(buf, curwin, lnum, (colnr_T)0, false);
|
buflist_setfpos(buf, (flags & BLN_NOCURWIN) ? NULL : curwin,
|
||||||
|
lnum, (colnr_T)0, false);
|
||||||
}
|
}
|
||||||
if ((flags & BLN_NOOPT) == 0) {
|
if ((flags & BLN_NOOPT) == 0) {
|
||||||
// Copy the options now, if 'cpo' doesn't have 's' and not done already.
|
// Copy the options now, if 'cpo' doesn't have 's' and not done already.
|
||||||
@@ -2486,6 +2487,7 @@ buflist_nr2name(
|
|||||||
///
|
///
|
||||||
/// @param[in,out] buf Buffer for which line and column are set.
|
/// @param[in,out] buf Buffer for which line and column are set.
|
||||||
/// @param[in,out] win Window for which line and column are set.
|
/// @param[in,out] win Window for which line and column are set.
|
||||||
|
/// May be NULL when using :badd.
|
||||||
/// @param[in] lnum Line number to be set. If it is zero then only
|
/// @param[in] lnum Line number to be set. If it is zero then only
|
||||||
/// options are touched.
|
/// options are touched.
|
||||||
/// @param[in] col Column number to be set.
|
/// @param[in] col Column number to be set.
|
||||||
@@ -2493,7 +2495,7 @@ buflist_nr2name(
|
|||||||
void buflist_setfpos(buf_T *const buf, win_T *const win,
|
void buflist_setfpos(buf_T *const buf, win_T *const win,
|
||||||
linenr_T lnum, colnr_T col,
|
linenr_T lnum, colnr_T col,
|
||||||
bool copy_options)
|
bool copy_options)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
wininfo_T *wip;
|
wininfo_T *wip;
|
||||||
|
|
||||||
@@ -2528,7 +2530,7 @@ void buflist_setfpos(buf_T *const buf, win_T *const win,
|
|||||||
wip->wi_fpos.lnum = lnum;
|
wip->wi_fpos.lnum = lnum;
|
||||||
wip->wi_fpos.col = col;
|
wip->wi_fpos.col = col;
|
||||||
}
|
}
|
||||||
if (copy_options) {
|
if (copy_options && win != NULL) {
|
||||||
// Save the window-specific option values.
|
// Save the window-specific option values.
|
||||||
copy_winopt(&win->w_onebuf_opt, &wip->wi_opt);
|
copy_winopt(&win->w_onebuf_opt, &wip->wi_opt);
|
||||||
wip->wi_fold_manual = win->w_fold_manual;
|
wip->wi_fold_manual = win->w_fold_manual;
|
||||||
@@ -2566,29 +2568,39 @@ static bool wininfo_other_tab_diff(wininfo_T *wip)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Find info for the current window in buffer "buf".
|
||||||
* Find info for the current window in buffer "buf".
|
// If not found, return the info for the most recently used window.
|
||||||
* If not found, return the info for the most recently used window.
|
// When "need_options" is true skip entries where wi_optset is false.
|
||||||
* When "skip_diff_buffer" is true avoid windows with 'diff' set that is in
|
// When "skip_diff_buffer" is true avoid windows with 'diff' set that is in
|
||||||
* another tab page.
|
// another tab page.
|
||||||
* Returns NULL when there isn't any info.
|
// Returns NULL when there isn't any info.
|
||||||
*/
|
static wininfo_T *find_wininfo(buf_T *buf, bool need_options,
|
||||||
static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer)
|
bool skip_diff_buffer)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
wininfo_T *wip;
|
wininfo_T *wip;
|
||||||
|
|
||||||
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
|
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
|
||||||
if (wip->wi_win == curwin
|
if (wip->wi_win == curwin
|
||||||
&& (!skip_diff_buffer || !wininfo_other_tab_diff(wip))
|
&& (!skip_diff_buffer || !wininfo_other_tab_diff(wip))
|
||||||
)
|
&& (!need_options || wip->wi_optset)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If no wininfo for curwin, use the first in the list (that doesn't have
|
// If no wininfo for curwin, use the first in the list (that doesn't have
|
||||||
* 'diff' set and is in another tab page). */
|
// 'diff' set and is in another tab page).
|
||||||
|
// If "need_options" is true skip entries that don't have options set,
|
||||||
|
// unless the window is editing "buf", so we can copy from the window
|
||||||
|
// itself.
|
||||||
if (wip == NULL) {
|
if (wip == NULL) {
|
||||||
if (skip_diff_buffer) {
|
if (skip_diff_buffer) {
|
||||||
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
|
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
|
||||||
if (!wininfo_other_tab_diff(wip)) {
|
if (!wininfo_other_tab_diff(wip)
|
||||||
|
&& (!need_options
|
||||||
|
|| wip->wi_optset
|
||||||
|
|| (wip->wi_win != NULL
|
||||||
|
&& wip->wi_win->w_buffer == buf))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2607,12 +2619,10 @@ static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer)
|
|||||||
*/
|
*/
|
||||||
void get_winopts(buf_T *buf)
|
void get_winopts(buf_T *buf)
|
||||||
{
|
{
|
||||||
wininfo_T *wip;
|
|
||||||
|
|
||||||
clear_winopt(&curwin->w_onebuf_opt);
|
clear_winopt(&curwin->w_onebuf_opt);
|
||||||
clearFolding(curwin);
|
clearFolding(curwin);
|
||||||
|
|
||||||
wip = find_wininfo(buf, true);
|
wininfo_T *const wip = find_wininfo(buf, true, true);
|
||||||
if (wip != NULL && wip->wi_win != curwin && wip->wi_win != NULL
|
if (wip != NULL && wip->wi_win != curwin && wip->wi_win != NULL
|
||||||
&& wip->wi_win->w_buffer == buf) {
|
&& wip->wi_win->w_buffer == buf) {
|
||||||
win_T *wp = wip->wi_win;
|
win_T *wp = wip->wi_win;
|
||||||
@@ -2649,7 +2659,7 @@ pos_T *buflist_findfpos(buf_T *buf)
|
|||||||
{
|
{
|
||||||
static pos_T no_position = { 1, 0, 0 };
|
static pos_T no_position = { 1, 0, 0 };
|
||||||
|
|
||||||
wininfo_T *wip = find_wininfo(buf, false);
|
wininfo_T *const wip = find_wininfo(buf, false, false);
|
||||||
return (wip == NULL) ? &no_position : &(wip->wi_fpos);
|
return (wip == NULL) ? &no_position : &(wip->wi_fpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,9 @@ enum bln_values {
|
|||||||
BLN_DUMMY = 4, // Allocating dummy buffer
|
BLN_DUMMY = 4, // Allocating dummy buffer
|
||||||
BLN_NEW = 8, // create a new buffer
|
BLN_NEW = 8, // create a new buffer
|
||||||
BLN_NOOPT = 16, // Don't copy options to existing buffer
|
BLN_NOOPT = 16, // Don't copy options to existing buffer
|
||||||
|
// BLN_DUMMY_OK = 32, // also find an existing dummy buffer
|
||||||
|
// BLN_REUSE = 64, // may re-use number from buf_reuse
|
||||||
|
BLN_NOCURWIN = 128, // buffer is not associated with curwin
|
||||||
};
|
};
|
||||||
|
|
||||||
// Values for action argument for do_buffer()
|
// Values for action argument for do_buffer()
|
||||||
|
@@ -2333,8 +2333,10 @@ int do_ecmd(
|
|||||||
if (tlnum <= 0)
|
if (tlnum <= 0)
|
||||||
tlnum = 1L;
|
tlnum = 1L;
|
||||||
}
|
}
|
||||||
|
// Add BLN_NOCURWIN to avoid a new wininfo items are associated
|
||||||
|
// with the current window.
|
||||||
const buf_T *const newbuf
|
const buf_T *const newbuf
|
||||||
= buflist_new(ffname, sfname, tlnum, BLN_LISTED);
|
= buflist_new(ffname, sfname, tlnum, BLN_LISTED | BLN_NOCURWIN);
|
||||||
if (newbuf != NULL && (flags & ECMD_ALTBUF)) {
|
if (newbuf != NULL && (flags & ECMD_ALTBUF)) {
|
||||||
curwin->w_alt_fnum = newbuf->b_fnum;
|
curwin->w_alt_fnum = newbuf->b_fnum;
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@ func Test_badd_options()
|
|||||||
new SomeNewBuffer
|
new SomeNewBuffer
|
||||||
setlocal numberwidth=3
|
setlocal numberwidth=3
|
||||||
wincmd p
|
wincmd p
|
||||||
badd SomeNewBuffer
|
badd +1 SomeNewBuffer
|
||||||
new SomeNewBuffer
|
new SomeNewBuffer
|
||||||
call assert_equal(3, &numberwidth)
|
call assert_equal(3, &numberwidth)
|
||||||
close
|
close
|
||||||
|
Reference in New Issue
Block a user