vim icon indicating copy to clipboard operation
vim copied to clipboard

Add autocommand `BufDeletePost`

Open cykerway opened this issue 3 years ago • 5 comments

There should be a new autocommand BufDeletePost, which works the same as BufDelete but is triggered after a buffer is deleted. This is useful when you want to get the updated buffer list. Currently, this is done by using a standalone function for BufDelete with additional processing on <abuf>, but it makes code more complicated and less intuitive.

cykerway avatar Sep 03 '22 03:09 cykerway

There should be a new autocommand BufDeletePost, which works the same as BufDelete but is triggered after a buffer is deleted. This is useful when you want to get the updated buffer list. Currently, this is done by using a standalone function for BufDelete with additional processing on <abuf>, but it makes code more complicated and less intuitive.

How about renaming? It's like one buffer disappears and another pops up. In that case one event would be sufficient, right?

Perhaps it would then be BufListChanged ?

-- Our job was to build a computer information system for the branch banks. We were the perfect people for the job: Dean had seen a computer once, and I had heard Dean talk about it. (Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \
/// \
\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

brammool avatar Sep 03 '22 09:09 brammool

I don't think they are the same. For example: Open vim on Buffer 1, then switch to Buffer 2, then :bd#. Then Buffer 1 will be closed and no rename here. In this case, neither BufAdd nor BufDelete would fetch the updated buffer list.

Vim already has a few "Post" events (BufFilePost, BufWritePost, ...) which made me think BufDeletePost is a good name.

On the other hand, BufListChanged seems a combination of BufAdd and BufDeletePost. I am not aware of any kind of buffer list changes that wouldn't trigger one of these events. BufListChanged is more comprehensive while BufDeletePost gives finer control on buffer events.

cykerway avatar Sep 03 '22 10:09 cykerway

I don't think they are the same. For example: Open vim on Buffer 1, then switch to Buffer 2, then :bd#. Then Buffer 1 will be closed and no rename here.

Vim already has a few "Post" events (BufFilePost, BufWritePost, ...) which made me think BufDeletePost is a good name.

What I mean is that, if you want to keep track of the current buffer list, you want an event after the list of buffers changed in some way. Deleting a buffer is one, renaming is another one. There is no separate Rename event, thus we can't really add RenamePost. BufAdd can be used though. If we add BufDeletePost then you could trigger on both of these.

-- I recommend ordering large cargo containers of paper towels to make up whatever budget underruns you have. Paper products are always useful and they have the advantage of being completely flushable if you need to make room in the storage area later. (Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \
/// \
\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

brammool avatar Sep 03 '22 11:09 brammool

you want an event after the list of buffers changed in some way.

Yes.

Deleting a buffer is one, renaming is another one.

Yes. In addition, adding a buffer is a third one. So there are three kinds of operations.

There is no separate Rename event, thus we can't really add RenamePost. BufAdd can be used though.

This is what I mean: Use BufAdd for adding and renaming and BufDeletePost for deleting.

If we add BufDeletePost then you could trigger on both of these.

Yes, like this:

au BufAdd,BufDeletePost * call function

If you really prefer BufListChanged, then like this:

au BufListChanged * call function

I guess BufDeletePost is the easier one to implement. And <abuf> is more meaningful in BufDeletePost than BufListChanged.

cykerway avatar Sep 03 '22 13:09 cykerway

I'm sorry for commenting on an old discussion. But since this wasn't resolved I would like to add my two cents. I also favour BufDeletePost instead of BufListChanged because:

  1. We can describe "list changed" in terms of "add/delete" but we can't do the opposite with a one-liner.
  2. We can also introduce BufWipeoutPost with similar semantics.

m4c0 avatar Feb 15 '24 12:02 m4c0