Skip to content
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

Fixing buffer menu having stale items with terminal / cmdline window #1025

Merged

Conversation

ychin
Copy link
Member

@ychin ychin commented Mar 16, 2020

Currently, when using special buffers like terminals / command-line window / quickfix / location list, these buffers will get added to the "Buffers" menu, but they don't get removed when the buffers are gone, leaving stale menu items. Fix buffer menu to be more robust.

  1. Currently the buffer menu works by using the buffer name to add/remove the entries, but it's error-prone because the buffer could have been renamed under-the-hood. While it uses BufFilePre/Post autocommands to handle normal buffer renames, it doesn't work for the command-line window (accessible via q:) which gets renamed without sending the autocommand. Instead, change the menus to cached a dictionary a bufnum -> menu name, so it will always know how to remove a buffer from itself.
  2. Add BufFilePre/Post autocommands to command-line windows when it changes the buffer name to "[Command Line]".
  3. Add BufFilePre/Post autocommands to terminal windows when it changes the buffer name to the command, e.g. "!/bin/zsh".

Either (1) or (2)+(3) will fix the issue, but just doing all of them as this seems like the right thing to do (2 + 3) also means the menu items show the correct names instead of just saying "[No Name]".

This doesn't fix the following which needs to be fixed later:

  1. Quickfix and Location List don't send BufDeleted autocmds. This leads to them also leaving stale buffer menu items as there's no way for the script to know that those buffers are gone.

Also add unit tests for cmdline-win / terminal buffer menus

Note: This fix misc test_cmdline failures in MacVim due to the menu item not being able to be removed.

This is a duplicate of vim/vim#5787 to fix this issue on this repository.

Currently, when using special buffers like terminals / command-line
window / quickfix / location list, these buffers will get added to the
"Buffers" menu, but they don't get removed when the buffers are gone,
leaving stale menu items. Fix buffer menu to be more robust.

1. Currently the buffer menu works by using the buffer name to
   add/remove the entries, but it's error-prone because the buffer could
   have been renamed under-the-hood. While it uses BufFilePre/Post
   autocommands to handle normal buffer renames, it doesn't work for the
   command-line window (accessible via `q:`) which gets renamed without
   sending the autocommand. Instead, change the menus to cached a
   dictionary a bufnum -> menu name, so it will always know how to
   remove a buffer from itself.
2. Add BufFilePre/Post autocommands to command-line windows when it
   changes the buffer name to "[Command Line]".
3. Add BufFilePre/Post autocommands to terminal windows when it
   changes the buffer name to the command, e.g. "!/bin/zsh".

Either (1) or (2)+(3) will fix the issue, but just doing all of them as
this seems like the right thing to do (2 + 3) also means the menu items
show the correct names instead of just saying "[No Name]".

This doesn't fix the following which needs to be fixed later:
1. Quickfix and Location List don't send BufDeleted autocmds. This leads
   to them also leaving stale buffer menu items as there's no way for
   the script to know that those buffers are gone.

Also add unit tests for cmdline-win / terminal buffer menus

Note: This fix misc test_cmdline failures in MacVim due to the menu item
not being able to be removed.

This is a duplicate of vim/vim#5787
@ychin ychin added this to the snapshot-163 milestone Mar 16, 2020
@ychin ychin merged commit 052c47a into macvim-dev:master Mar 17, 2020
@ychin ychin deleted the mvim-fix-cmdline-term-buffer-menu-stale-items branch March 17, 2020 07:43
ychin added a commit to ychin/macvim that referenced this pull request Apr 11, 2020
Vim patch 8.2.539

General:

- MacVim now reports its app category to be "Productivity" for Screen
  Time. macvim-dev#1032

Fixes:

- Fix MacVim not reporting its version number correctly. macvim-dev#1011
- Fix mvim:// protocol handler not handling line number. macvim-dev#1020
- Fix opening MacVim from the Dock not setting UTF.8 in locale. macvim-dev#1033
- Buffer menu now doesn't show stale menu items from command-line
  windows or terminal windows. macvim-dev#1025

Targets macOS 10.9+

Script interfaces have compatibility with these versions:
TODO
- Lua 5.3
- Perl 5.18
- Python2 2.7
- Python3 3.7
- Ruby 2.7
ychin added a commit that referenced this pull request Apr 12, 2020
Vim patch 8.2.539

General:

- MacVim now reports its app category to be "Productivity" for Screen
  Time. #1032

Fixes:

- Fix MacVim not reporting its version number correctly. #1011
- Fix mvim:// protocol handler not handling line number. #1020
- Fix opening MacVim from the Dock not setting UTF-8 in locale. #1033
- Buffer menu now doesn't show stale menu items from command-line
  windows or terminal windows. #1025

Targets macOS 10.9+

Script interfaces have compatibility with these versions:
- Lua 5.3
- Perl 5.18
- Python2 2.7
- Python3 3.7
- Ruby 2.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant