Hi everyone,
I hope this is the right place to ask a question to Vim maintainers. My question is about this post: https://github.com/vim/vim/issues/6445
The summary of the post above is “I would like a ‘local to window’ option that pins a buffer to that window”. It’s a great idea however implementing it requires changes to commands in Vim. I was hoping to ask a couple questions. One about Quickfix and a related question about :argdo, :bufdo, :cdo, etc.
For example, if you have a window layout like this:
+--------------------+
| |
| code | 'nostickybuf'
| |
+--------------------+
| |
| terminal | 'stickybuf'
| |
+--------------------+
| quickfix |
+--------------------+
Where the terminal buffer’s window has stickybuf' enabled and 'switchbuf' includes 'uselast', I changed :cnext and other commands to prefer the last 'nostickybuf' window. But what should happen in that case when there is only one 'stickybuf' window + quickfix window, like this?
+--------------------+
| |
| code | 'stickybuf'
| |
+--------------------+
| quickfix |
+--------------------+
Here’s some ways I could see a command like :cnext running -
What do you think of this case?
Normally running these “do” commands will change a window to view whatever buffer you’re currently acting upon. Like the quickfix commands, I have it set to prefer a window that is 'nostickybuf'. But what should happen if there is no fallback, 'nostickybuf' window to choose? Should the “do” command error? Or should it continue to “do” but not change the window’s buffer to show each entry?
I could imagine not changing would cause commands like :bufdo s/foo/bar/c to become more complex because you wouldn’t be able to confirm the replacement in advance. Which led me to think maybe checking for a valid window first before the “do” command runs makes more sense and fail early if there’s no window to choose. What do you think?
The quickfix and “:foodo”-related commands are some of the more complicated cases but once we know what the best behavior in those cases are, I’m sure the rest will be easy.
Thank you!
Colin
Hi Christian,
Where the terminal buffer’s window has stickybuf’ enabled and ‘switchbuf’ includes ‘uselast’, I changed :cnext and other commands to prefer the last ‘nostickybuf’ window. … I don’t understand option 2. How would it succeed, if you do not change the windows buffer?
Admittedly that #2 was not well thought out. I was too closely relating :cnext-and-family commands to :foodo-and-family commands. I’m happy to do #3 as you’ve suggested :)
If you think of ‘stickybuf’ as making the window containing the buffer immutable, I would think we should open a new window then. Thinking about it, it seems similar to how help files are handled
Sure, we can do that. I’ll open a new window according to 'switchbuf' like :cnext and others already do.
This also sounds like you may want to reuse the ‘buftype’ option and add stickybuf as a new special value for it?
Originally I had 'stickybuf' as a “local to buffer” option like 'buftype' but setting 'stickybuf' on the buffer frequently caused hiccups during testing. For example, if 'stickybuf' buffers are not hidden, there’s a chance someone could open the 'stickybuf' buffer by accident and then think “whoops! I didn’t mean to go to this buffer, I’d better back out!” and try to call :edit # or something only for it to fail because the user is in a 'stickybuf' buffer. (I later added forceit[!] to those commands, but that’s besides the point). It was a frequent annoyance for me, during testing. 'stickybuf' as a “local to window” option was much more natural in my opinion because then the only concern left to solve is “when we split a 'stickybuf' window, should the new window also be 'stickybuf'?”. Currently I’m leaning towards “no” because if you’re making a split, you’re probably about to switch away from the buffer. Maybe that’s a bad assumption, please let me know.
Regarding buffer vs window attribute, I figured if someone wants 'stickybuf' to be buffer-like, they could still achieve the same effect even if 'stickybuf' is a window option by using a buffer autocmd.
Same here, if ‘stickybuf’ option is set, can we open a new window instead?
Do you mean
“if only windows with 'stickybuf' remain, rather than erroring, can we open a new window instead?”
or
“if 'stickybuf' option is set, can we always open a new window instead”
Either way works for me. Though I’d prefer it as a last resort, personally. Would you also want this new window opened according to 'switchbuf'? Currently I don’t know whether :argdo, :bufdo, :cdo consider 'switchbuf'. The :help doesn’t mention it, that I could find.
Last question for now - if we keep 'stickybuf' as a “local to window” option, should we add a ! to :windo? From :help :bufdo, I noticed a line that says “When the current file can’t be |abandon|ed and the [!] is not present, the command fails.”. Since :windo has no !, I was wondering if 'stickybuf' would be a good opportunity to give :windo parity with the other :foodo[!] commands.
Thanks,
Colin
Hello!
I had to take a break from this for a while but I’m back at it. Since then, I’ve encountered some scenarios that I wanted to double-check with you all.
Previously, we talked about creating a new split window if :foodo is called and all of the current windows are 'stickybuf'. I’ve added that behavior for :argdo, :bufdo, :cdo, and others.
Now for my questions, below:
If you could weigh in on what the expected behavior should be, that’d be really helpful.
Thank you!
Colin
Hello again,
Some good news and bad news.
Good news - I have a branch working and it even passing GitHub’s CI, which is comforting!
Bad news - I still have many questions ranging from simple things such as
“What should the error code be for when we need to display a message?”
I picked E922 since it is currently unused but I don’t know if there’s a standard to the error codes that I’m stepping over
to more complex decisions such as
And other decision-making related questions like that. Would you rather we keep communications to here while each point is sorted out or would you want to see a GitHub draft PR sooner and I can place remaining questions there? I’m happy to do either.
Thanks,
Colin