Skip to content

fix(format): use global operatorfunc instead of buffer-local#133

Merged
YousefHadder merged 1 commit intomainfrom
fix/broken-operatorfunc
Nov 22, 2025
Merged

fix(format): use global operatorfunc instead of buffer-local#133
YousefHadder merged 1 commit intomainfrom
fix/broken-operatorfunc

Conversation

@YousefHadder
Copy link
Owner

Description

Brief description of the changes.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring
  • Performance improvement

Related Issues

Fixes #(issue number)

Testing

  • Tested manually
  • Added/updated tests (if applicable)

Checklist

  • Code follows project style
  • Self-reviewed my code
  • Commented complex logic
  • Updated documentation (if needed)
  • No new warnings generated

Copilot AI review requested due to automatic review settings November 22, 2025 02:04
@YousefHadder YousefHadder merged commit 8d97fc8 into main Nov 22, 2025
18 checks passed
@YousefHadder YousefHadder deleted the fix/broken-operatorfunc branch November 22, 2025 02:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where the operatorfunc option was incorrectly set as buffer-local (vim.bo) instead of global (vim.o), which is required for the g@ operator to function properly in Neovim.

Key Changes

  • Changed vim.bo.operatorfunc to vim.o.operatorfunc in two functions
  • Updated comments to reflect the corrected scope
Comments suppressed due to low confidence (2)

lua/markdown-plus/format/init.lua:70

  • The _toggle_format_with_repeat function lacks test coverage. Since other functions in format_spec.lua have extensive tests, this function should also be tested to ensure the operatorfunc mechanism and dot-repeat functionality work correctly.
function M._toggle_format_with_repeat(format_type, plug)
  -- Save state for repeat
  M._repeat_state.format_type = format_type

  -- Set operatorfunc for the g@ operator
  vim.o.operatorfunc = "v:lua.require'markdown-plus.format'._format_operatorfunc"

  -- Register with repeat.vim if available
  if plug then
    M.register_repeat(plug)
  end

  -- Return g@l for linewise operation (operatorfunc will handle word detection)
  return "g@l"
end

lua/markdown-plus/format/init.lua:86

  • The _clear_with_repeat function lacks test coverage. Since other functions in format_spec.lua have extensive tests, this function should also be tested to ensure the operatorfunc mechanism and clear formatting with dot-repeat functionality work correctly.
function M._clear_with_repeat(plug)
  -- Set operatorfunc for the g@ operator
  vim.o.operatorfunc = "v:lua.require'markdown-plus.format'._clear_operatorfunc"

  -- Register with repeat.vim if available
  if plug then
    M.register_repeat(plug)
  end

  -- Return g@l for linewise operation (operatorfunc will handle word detection)
  return "g@l"
end


-- Set operatorfunc (buffer-local to avoid conflicts)
vim.bo.operatorfunc = "v:lua.require'markdown-plus.format'._format_operatorfunc"
-- Set operatorfunc for the g@ operator
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment could better explain why global scope is required. Consider: -- Set operatorfunc globally (required by Vim for g@ operator to work correctly)

Suggested change
-- Set operatorfunc for the g@ operator
-- Set operatorfunc globally (required by Vim for g@ operator to work correctly; operatorfunc must be global, not buffer-local)

Copilot uses AI. Check for mistakes.
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