Skip to content

fix: replace BufModifiedSet with OptionSet for Neovim 0.11 compat#49

Merged
Hajime-Suzuki merged 3 commits into
Hajime-Suzuki:mainfrom
iqrar-eng:fix/buf-modified-set
May 20, 2026
Merged

fix: replace BufModifiedSet with OptionSet for Neovim 0.11 compat#49
Hajime-Suzuki merged 3 commits into
Hajime-Suzuki:mainfrom
iqrar-eng:fix/buf-modified-set

Conversation

@iqrar-eng
Copy link
Copy Markdown
Contributor

BufModifiedSet was removed in Neovim 0.11. Replacing with OptionSet pattern=modified which has been available since Vim 7.4.729 so no version guard is needed.

Copy link
Copy Markdown
Owner

@Hajime-Suzuki Hajime-Suzuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the PR! Migrating off BufModifiedSet is the right move for Neovim 0.13.

One correction: BufModifiedSet wasn't removed in 0.11. It still works on stable 0.11/0.12. Removal is in neovim#35610 and only affects 0.13 nightly today.

Also, OptionSet modified only became reliable in 0.13 (same PR). On 0.11/0.12 it doesn't fire on edits, so this change would break modified-icon updates for stable users.

Could we keep a version guard?

if vim.fn.has("nvim-0.13") == 1 then
  -- OptionSet modified
else
  -- BufModifiedSet
end

Same approach as nvim-tree#3325 and barbar#668.

@iqrar-eng
Copy link
Copy Markdown
Contributor Author

iqrar-eng commented May 20, 2026

Thanks for the clarification — and thank you very much for vuffers.nvim!

The version guard approach (vim.fn.has("nvim-0.13")) turned out to be unreliable — BufModifiedSet was invalid even when the check passed. Switched to checking if the event actually exists at runtime instead:

if vim.fn.exists("##BufModifiedSet") == 1 then
  vim.api.nvim_create_autocmd({ "BufModifiedSet" }, {
    pattern = "*",
    group = constants.AUTO_CMD_GROUP,
    callback = function(buffer)
      if not buf_utils.is_valid_buf(buffer) then
        return
      end
      logger.debug("BufModifiedSet", { buffer = buffer })
      ui.update_modified_icon(buffer)
    end,
  })
else
  vim.api.nvim_create_autocmd({ "OptionSet" }, {
    pattern = "modified",
    group = constants.AUTO_CMD_GROUP,
    callback = function(buffer)
      if not buf_utils.is_valid_buf(buffer) then
        return
      end
      logger.debug("OptionSet modified", { buffer = buffer })
      ui.update_modified_icon(buffer)
    end,
  })
end

vim.fn.exists("##BufModifiedSet") returns 1 only if the event is supported by the running Neovim binary, so no version guessing needed. Let me know if anything needs adjusting.

@Hajime-Suzuki Hajime-Suzuki merged commit 4da3292 into Hajime-Suzuki:main May 20, 2026
@Hajime-Suzuki
Copy link
Copy Markdown
Owner

Thank you so much for your contribution! 🙏

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.

2 participants