comment.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. local M = {}
  2. function M.config()
  3. local pre_hook = nil
  4. if lvim.builtin.treesitter.context_commentstring.enable then
  5. pre_hook = function(_ctx)
  6. return require("ts_context_commentstring.internal").calculate_commentstring()
  7. end
  8. end
  9. lvim.builtin.comment = {
  10. active = true,
  11. on_config_done = nil,
  12. ---Add a space b/w comment and the line
  13. ---@type boolean
  14. padding = true,
  15. ---Lines to be ignored while comment/uncomment.
  16. ---Could be a regex string or a function that returns a regex string.
  17. ---Example: Use '^$' to ignore empty lines
  18. ---@type string|function
  19. ignore = "^$",
  20. ---Whether to create basic (operator-pending) and extra mappings for NORMAL/VISUAL mode
  21. ---@type table
  22. mappings = {
  23. ---operator-pending mapping
  24. ---Includes `gcc`, `gcb`, `gc[count]{motion}` and `gb[count]{motion}`
  25. basic = true,
  26. ---Extra mapping
  27. ---Includes `gco`, `gcO`, `gcA`
  28. extra = true,
  29. ---Extended mapping
  30. ---Includes `g>`, `g<`, `g>[count]{motion}` and `g<[count]{motion}`
  31. extended = false,
  32. },
  33. ---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode
  34. ---@type table
  35. toggler = {
  36. ---line-comment toggle
  37. line = "gcc",
  38. ---block-comment toggle
  39. block = "gbc",
  40. },
  41. ---LHS of line and block comment operator-mode mapping in NORMAL/VISUAL mode
  42. ---@type table
  43. opleader = {
  44. ---line-comment opfunc mapping
  45. line = "gc",
  46. ---block-comment opfunc mapping
  47. block = "gb",
  48. },
  49. ---Pre-hook, called before commenting the line
  50. ---@type function|nil
  51. pre_hook = pre_hook,
  52. ---Post-hook, called after commenting is done
  53. ---@type function|nil
  54. post_hook = nil,
  55. }
  56. end
  57. function M.setup()
  58. local nvim_comment = require "Comment"
  59. nvim_comment.setup(lvim.builtin.comment)
  60. if lvim.builtin.comment.on_config_done then
  61. lvim.builtin.comment.on_config_done(nvim_comment)
  62. end
  63. end
  64. return M