New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tabline is not updated after :badd command #3770

Closed
itchyny opened this Issue Jan 6, 2019 · 14 comments

Comments

Projects
None yet
4 participants
@itchyny
Copy link

itchyny commented Jan 6, 2019

The :badd command does not seem to update the tabline, but I believe it should be updated.

Steps to reproduce the problem.

 $ vim -u NONE -N
:set showtabline=2
:set tabline=%{bufnr('$')}
:edit a
:edit b
:badd c

Actual behavior: the tabline shows 2.
Expected behavior: the tabline show 3 because there are three buffers.
Note that after checking the buffer list with :buffers, the tabline is evaluated and becomes 3.

Environment: Vim 8.1.695, iTerm2 3.2.7beta3, macOS 10.14.2

@h-east

This comment has been minimized.

Copy link

h-east commented Jan 6, 2019

@itchyny

Could you please try this patch?

diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 9990bca21..cb2aabc01 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3968,6 +3968,7 @@ do_ecmd(
 			tlnum = 1L;
 		}
 		(void)buflist_new(ffname, sfname, tlnum, BLN_LISTED);
+		redraw_tabline = TRUE;
 		goto theend;
 	    }
 	    buf = buflist_new(ffname, sfname, 0L,

PS
Perhaps the test will need to use terminal-dump.

@brammool

This comment has been minimized.

Copy link
Contributor

brammool commented Jan 6, 2019

@itchyny

This comment has been minimized.

Copy link

itchyny commented Jan 7, 2019

@h-east Thanks for the patch, I confirmed your patch solves the problem.

This fixes the specific example, but:

  • The tabline is redrawn on every :badd, even when it is irrelevant.
  • The tabline is still not redrawn on any other change that might
    require a redraw.

Thanks bram, for sharing your concern. I just come up with judging redraw is
necessary or not based on parsing the tabline/statusline values, but that might
too hard to implement at this moment. I agree that it's hard to decide where to
set the redraw flag because almost every state change may change the values of
tabline/statusline. I'm not sure there are other commands which cause the same
issue though.

@chrisbra

This comment has been minimized.

Copy link
Member

chrisbra commented Jan 7, 2019

I have worked around this problem in vim-airline using a BufAdd autocommand
Perhaps the tabline should always redrawn when the statusline is redrawn? Or is that more expansive?

@h-east

This comment has been minimized.

Copy link

h-east commented Jan 7, 2019

@chrisbra I rethink that using BufAdd autocommand makes sense👍

@itchyny

This comment has been minimized.

Copy link

itchyny commented Jan 7, 2019

I don't think au BufAdd * let &tabline = &tabline is a good solution to avoid the tabline redraw problem here. I can't recommend this weird config to the users who configure the tabline to show the buffer information.

@chrisbra

This comment has been minimized.

Copy link
Member

chrisbra commented Jan 7, 2019

au BufAdd * let &tabline = &tabline

I wasn't trying to suggest this, sorry for the confusion. I just wanted to mention, that this bug has caused some annoyances to me.

My suggestion (if it isn't too expansive) was to always refresh the tabline, if the statusline is also refreshed. That seems consistent.

@h-east

This comment has been minimized.

Copy link

h-east commented Jan 7, 2019

Is this a bug?
Since ":badd" only updates the buffer list and the current buffer does not change, in fact Vim does not need to update tabline.
When updating the tabline every time ":badd" comes to the problem Bram refers to.
In the end, I think that it will be a balance with cost.

@brammool

This comment has been minimized.

Copy link
Contributor

brammool commented Jan 7, 2019

@brammool

This comment has been minimized.

Copy link
Contributor

brammool commented Jan 7, 2019

@h-east

This comment has been minimized.

Copy link

h-east commented Jan 8, 2019

In the following case, :bwipeout redraws tabline even though there is no change in the buffer. It is interesting.

 $ vim -u NONE -N
:set showtabline=2
:set tabline=%{bufnr('$')}
:edit a
:badd c
:redraw!
:bwipeout 2

Here is a GDB back trace when the variable redraw_tabline changes from 0 to 1 at :bwipeout.

(gdb) bt
#0  0x000055eb364253cc in close_windows (buf=0x55eb381cfbf0, keep_curwin=0)
    at window.c:2205
#1  0x000055eb3620e49e in do_buffer (action=4, start=1, dir=1, count=3, forceit=
0) at buffer.c:1448
#2  0x000055eb3620dc86 in do_bufdel (command=4, arg=0x55eb3815a204 "", addr_coun
t=1, start_bnr=1, end_bnr=3, forceit=0) at buffer.c:1158
#3  0x000055eb36285b57 in ex_bunload (eap=0x7ffde966b890) at ex_docmd.c:5626
#4  0x000055eb3627f2f6 in do_one_cmd (cmdlinep=0x7ffde966bad0, sourcing=0, cstac
k=0x7ffde966bbc0, fgetline=0x55eb3629b01b <getexline>, cookie=0x0)
    at ex_docmd.c:2525
#5  0x000055eb3627c763 in do_cmdline (cmdline=0x0, fgetline=
    0x55eb3629b01b <getexline>, cookie=0x0, flags=0) at ex_docmd.c:1036
#6  0x000055eb3631d50b in nv_colon (cap=0x7ffde966c140) at normal.c:5397
#7  0x000055eb363157e3 in normal_cmd (oap=0x7ffde966c1d0, toplevel=1)
    at normal.c:1121
#8  0x000055eb36487839 in main_loop (cmdwin=0, noexmode=0) at main.c:1375
#9  0x000055eb36486eb9 in vim_main2 () at main.c:917
#10 0x000055eb36486571 in main (argc=2, argv=0x7ffde966c3d8) at main.c:441
@chrisbra

This comment has been minimized.

Copy link
Member

chrisbra commented Jan 8, 2019

or add a :redrawtabline command.

I have implemented a redrawtabline command already for the rare cases I thought it would be useful. However, I am not sure this:

 au BufAdd * :redrawtabline

is much better than:

au BufAdd * :let &tabline=&tabline

it doesn't fix the initial problem, that the tabline isn't updated when a buffer is added to the buffer list. That is also the reason, I threw the patch away and never submitted it :(

Is it so common to have info about the argument list in the tabline?

Not the argument list, but the buffer list is quite common for those fancy statusline/tabline plugins.

In fact, I actually got a feature request for vim-airline to display the statusline in the tabline. Besides the fact that the statusline is (obviously) being drawn at the top instead of the bottom, it does have the appeal of being always a single line and not to split for multiple windows. One problem with that request is, that the tabline is not updated often enough.

@brammool

This comment has been minimized.

Copy link
Contributor

brammool commented Jan 8, 2019

mckellyln added a commit to mckellyln/dotfiles that referenced this issue Jan 8, 2019

@itchyny

This comment has been minimized.

Copy link

itchyny commented Jan 9, 2019

Thanks Bram for adding redrawtabline at the patch 8.1.0706 (e12bab3, https://groups.google.com/d/msg/vim_dev/Vw2VyNmvHlc/FYVbnePcDwAJ). I think using redrawtabline command is a reasonable solution to this issue so closing. Thank you.

@itchyny itchyny closed this Jan 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment