autopairs.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. local M = {}
  2. function M.config()
  3. lvim.builtin.autopairs = {
  4. active = true,
  5. on_config_done = nil,
  6. ---@usage modifies the function or method delimiter by filetypes
  7. map_char = {
  8. all = "(",
  9. tex = "{",
  10. },
  11. ---@usage check bracket in same line
  12. enable_check_bracket_line = false,
  13. ---@usage check treesitter
  14. check_ts = true,
  15. ts_config = {
  16. lua = { "string", "source" },
  17. javascript = { "string", "template_string" },
  18. java = false,
  19. },
  20. disable_filetype = { "TelescopePrompt", "spectre_panel" },
  21. ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]], "%s+", ""),
  22. enable_moveright = true,
  23. ---@usage disable when recording or executing a macro
  24. disable_in_macro = false,
  25. ---@usage add bracket pairs after quote
  26. enable_afterquote = true,
  27. ---@usage map the <BS> key
  28. map_bs = true,
  29. ---@usage map <c-w> to delete a pair if possible
  30. map_c_w = false,
  31. ---@usage disable when insert after visual block mode
  32. disable_in_visualblock = false,
  33. ---@usage change default fast_wrap
  34. fast_wrap = {
  35. map = "<M-e>",
  36. chars = { "{", "[", "(", '"', "'" },
  37. pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
  38. offset = 0, -- Offset from pattern match
  39. end_key = "$",
  40. keys = "qwertyuiopzxcvbnmasdfghjkl",
  41. check_comma = true,
  42. highlight = "Search",
  43. highlight_grey = "Comment",
  44. },
  45. }
  46. end
  47. M.setup = function()
  48. local status_ok, autopairs = pcall(require, "nvim-autopairs")
  49. if not status_ok then
  50. return
  51. end
  52. autopairs.setup {
  53. check_ts = lvim.builtin.autopairs.check_ts,
  54. enable_check_bracket_line = lvim.builtin.autopairs.enable_check_bracket_line,
  55. ts_config = lvim.builtin.autopairs.ts_config,
  56. disable_filetype = lvim.builtin.autopairs.disable_filetype,
  57. disable_in_macro = lvim.builtin.autopairs.disable_in_macro,
  58. ignored_next_char = lvim.builtin.autopairs.ignored_next_char,
  59. enable_moveright = lvim.builtin.autopairs.enable_moveright,
  60. enable_afterquote = lvim.builtin.autopairs.enable_afterquote,
  61. map_c_w = lvim.builtin.autopairs.map_c_w,
  62. map_bs = lvim.builtin.autopairs.map_bs,
  63. disable_in_visualblock = lvim.builtin.autopairs.disable_in_visualblock,
  64. fast_wrap = lvim.builtin.autopairs.fast_wrap,
  65. }
  66. if lvim.builtin.autopairs.on_config_done then
  67. lvim.builtin.autopairs.on_config_done(autopairs)
  68. end
  69. pcall(function()
  70. local function on_confirm_done(...)
  71. require("nvim-autopairs.completion.cmp").on_confirm_done()(...)
  72. end
  73. require("cmp").event:off("confirm_done", on_confirm_done)
  74. require("cmp").event:on("confirm_done", on_confirm_done)
  75. end)
  76. end
  77. return M