mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06: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:
parent
a2aeed013c
commit
cdace43b6c
@ -1726,7 +1726,8 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
|
||||
file_id_valid)) != NULL) {
|
||||
xfree(ffname);
|
||||
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) {
|
||||
// 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] 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
|
||||
/// options are touched.
|
||||
/// @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,
|
||||
linenr_T lnum, colnr_T col,
|
||||
bool copy_options)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
FUNC_ATTR_NONNULL_ARG(1)
|
||||
{
|
||||
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.col = col;
|
||||
}
|
||||
if (copy_options) {
|
||||
if (copy_options && win != NULL) {
|
||||
// Save the window-specific option values.
|
||||
copy_winopt(&win->w_onebuf_opt, &wip->wi_opt);
|
||||
wip->wi_fold_manual = win->w_fold_manual;
|
||||
@ -2566,29 +2568,39 @@ static bool wininfo_other_tab_diff(wininfo_T *wip)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find info for the current window in buffer "buf".
|
||||
* If not found, return the info for the most recently used window.
|
||||
* When "skip_diff_buffer" is true avoid windows with 'diff' set that is in
|
||||
* another tab page.
|
||||
* Returns NULL when there isn't any info.
|
||||
*/
|
||||
static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer)
|
||||
// Find info for the current window in buffer "buf".
|
||||
// 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
|
||||
// another tab page.
|
||||
// Returns NULL when there isn't any info.
|
||||
static wininfo_T *find_wininfo(buf_T *buf, bool need_options,
|
||||
bool skip_diff_buffer)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
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
|
||||
&& (!skip_diff_buffer || !wininfo_other_tab_diff(wip))
|
||||
)
|
||||
&& (!need_options || wip->wi_optset)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If no wininfo for curwin, use the first in the list (that doesn't have
|
||||
* 'diff' set and is in another tab page). */
|
||||
// If no wininfo for curwin, use the first in the list (that doesn't have
|
||||
// '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 (skip_diff_buffer) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -2607,12 +2619,10 @@ static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer)
|
||||
*/
|
||||
void get_winopts(buf_T *buf)
|
||||
{
|
||||
wininfo_T *wip;
|
||||
|
||||
clear_winopt(&curwin->w_onebuf_opt);
|
||||
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
|
||||
&& wip->wi_win->w_buffer == buf) {
|
||||
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 };
|
||||
|
||||
wininfo_T *wip = find_wininfo(buf, false);
|
||||
wininfo_T *const wip = find_wininfo(buf, false, false);
|
||||
return (wip == NULL) ? &no_position : &(wip->wi_fpos);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,9 @@ enum bln_values {
|
||||
BLN_DUMMY = 4, // Allocating dummy buffer
|
||||
BLN_NEW = 8, // create a new 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()
|
||||
|
@ -2333,8 +2333,10 @@ int do_ecmd(
|
||||
if (tlnum <= 0)
|
||||
tlnum = 1L;
|
||||
}
|
||||
// Add BLN_NOCURWIN to avoid a new wininfo items are associated
|
||||
// with the current window.
|
||||
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)) {
|
||||
curwin->w_alt_fnum = newbuf->b_fnum;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ func Test_badd_options()
|
||||
new SomeNewBuffer
|
||||
setlocal numberwidth=3
|
||||
wincmd p
|
||||
badd SomeNewBuffer
|
||||
badd +1 SomeNewBuffer
|
||||
new SomeNewBuffer
|
||||
call assert_equal(3, &numberwidth)
|
||||
close
|
||||
|
Loading…
Reference in New Issue
Block a user