comment.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. ---extended mapping
  27. ---Includes `g>`, `g<`, `g>[count]{motion}` and `g<[count]{motion}`
  28. extra = false,
  29. },
  30. ---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode
  31. ---@type table
  32. toggler = {
  33. ---line-comment toggle
  34. line = "gcc",
  35. ---block-comment toggle
  36. block = "gbc",
  37. },
  38. ---LHS of line and block comment operator-mode mapping in NORMAL/VISUAL mode
  39. ---@type table
  40. opleader = {
  41. ---line-comment opfunc mapping
  42. line = "gc",
  43. ---block-comment opfunc mapping
  44. block = "gb",
  45. },
  46. ---Pre-hook, called before commenting the line
  47. ---@type function|nil
  48. pre_hook = pre_hook,
  49. ---Post-hook, called after commenting is done
  50. ---@type function|nil
  51. post_hook = nil,
  52. }
  53. end
  54. function M.setup()
  55. local nvim_comment = require "Comment"
  56. nvim_comment.setup(lvim.builtin.comment)
  57. if lvim.builtin.comment.on_config_done then
  58. lvim.builtin.comment.on_config_done(nvim_comment)
  59. end
  60. end
  61. return M