retrovim 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/.conda/retrovim.yaml +259 -0
  2. package/.conda/terax.icns +0 -0
  3. package/.conda/terax.ico +0 -0
  4. package/.conda/terax.png +0 -0
  5. package/.github/workflows/release.yml +95 -0
  6. package/.gitmodules +3 -0
  7. package/.npm/kanata_touchcursor.js +28 -0
  8. package/.npm/nvim.js +26 -0
  9. package/.npm/yazi.js +26 -0
  10. package/.npm/zsh.js +17 -0
  11. package/.pip/kanata_touchcursor/__init__.py +28 -0
  12. package/.pip/nvim/__init__.py +31 -0
  13. package/.pip/yazi/__init__.py +31 -0
  14. package/.pip/zsh/__init__.py +22 -0
  15. package/CHANGELOG.md +26 -0
  16. package/LICENSE +674 -0
  17. package/README.md +336 -0
  18. package/kanata/touchcursor.kbd +164 -0
  19. package/nvim/init.lua +813 -0
  20. package/nvim/plugins/mini.nvim/.github/DISCUSSION_TEMPLATE/q-a.yml +72 -0
  21. package/nvim/plugins/mini.nvim/.github/ISSUE_TEMPLATE/bug-report.yml +136 -0
  22. package/nvim/plugins/mini.nvim/.github/ISSUE_TEMPLATE/config.yml +5 -0
  23. package/nvim/plugins/mini.nvim/.github/ISSUE_TEMPLATE/feature-request.yml +75 -0
  24. package/nvim/plugins/mini.nvim/.github/PULL_REQUEST_TEMPLATE.md +2 -0
  25. package/nvim/plugins/mini.nvim/.github/workflows/quality-control.yml +150 -0
  26. package/nvim/plugins/mini.nvim/.pre-commit-config.yaml +20 -0
  27. package/nvim/plugins/mini.nvim/.stylua.toml +7 -0
  28. package/nvim/plugins/mini.nvim/.styluaignore +1 -0
  29. package/nvim/plugins/mini.nvim/CHANGELOG.md +1894 -0
  30. package/nvim/plugins/mini.nvim/CODE_OF_CONDUCT.md +132 -0
  31. package/nvim/plugins/mini.nvim/CONTRIBUTING.md +331 -0
  32. package/nvim/plugins/mini.nvim/LICENSE +21 -0
  33. package/nvim/plugins/mini.nvim/MAINTAINING.md +330 -0
  34. package/nvim/plugins/mini.nvim/Makefile +51 -0
  35. package/nvim/plugins/mini.nvim/README.md +261 -0
  36. package/nvim/plugins/mini.nvim/TESTING.md +1011 -0
  37. package/nvim/plugins/mini.nvim/benchmarks/starter/README.md +35 -0
  38. package/nvim/plugins/mini.nvim/benchmarks/starter/benchmark.sh +56 -0
  39. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_dashboard-alpha.lua +21 -0
  40. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_dashboard-original.lua +17 -0
  41. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_dashboard-starter.lua +18 -0
  42. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_empty.lua +4 -0
  43. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_starter-default.lua +7 -0
  44. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_startify-alpha.lua +10 -0
  45. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_startify-original.lua +7 -0
  46. package/nvim/plugins/mini.nvim/benchmarks/starter/init-files/init_startify-starter.lua +20 -0
  47. package/nvim/plugins/mini.nvim/benchmarks/starter/install.sh +10 -0
  48. package/nvim/plugins/mini.nvim/benchmarks/starter/make_summary.py +68 -0
  49. package/nvim/plugins/mini.nvim/benchmarks/starter/startup-summary.md +10 -0
  50. package/nvim/plugins/mini.nvim/colors/miniautumn.lua +55 -0
  51. package/nvim/plugins/mini.nvim/colors/minicyan.lua +95 -0
  52. package/nvim/plugins/mini.nvim/colors/minischeme.lua +95 -0
  53. package/nvim/plugins/mini.nvim/colors/minispring.lua +53 -0
  54. package/nvim/plugins/mini.nvim/colors/minisummer.lua +49 -0
  55. package/nvim/plugins/mini.nvim/colors/miniwinter.lua +51 -0
  56. package/nvim/plugins/mini.nvim/colors/randomhue.lua +16 -0
  57. package/nvim/plugins/mini.nvim/doc/mini-ai.txt +889 -0
  58. package/nvim/plugins/mini.nvim/doc/mini-align.txt +923 -0
  59. package/nvim/plugins/mini.nvim/doc/mini-animate.txt +937 -0
  60. package/nvim/plugins/mini.nvim/doc/mini-base16.txt +285 -0
  61. package/nvim/plugins/mini.nvim/doc/mini-basics.txt +359 -0
  62. package/nvim/plugins/mini.nvim/doc/mini-bracketed.txt +622 -0
  63. package/nvim/plugins/mini.nvim/doc/mini-bufremove.txt +123 -0
  64. package/nvim/plugins/mini.nvim/doc/mini-clue.txt +760 -0
  65. package/nvim/plugins/mini.nvim/doc/mini-cmdline.txt +392 -0
  66. package/nvim/plugins/mini.nvim/doc/mini-colors.txt +880 -0
  67. package/nvim/plugins/mini.nvim/doc/mini-comment.txt +230 -0
  68. package/nvim/plugins/mini.nvim/doc/mini-completion.txt +477 -0
  69. package/nvim/plugins/mini.nvim/doc/mini-cursorword.txt +105 -0
  70. package/nvim/plugins/mini.nvim/doc/mini-deps.txt +590 -0
  71. package/nvim/plugins/mini.nvim/doc/mini-diff.txt +661 -0
  72. package/nvim/plugins/mini.nvim/doc/mini-doc.txt +434 -0
  73. package/nvim/plugins/mini.nvim/doc/mini-extra.txt +856 -0
  74. package/nvim/plugins/mini.nvim/doc/mini-files.txt +1018 -0
  75. package/nvim/plugins/mini.nvim/doc/mini-fuzzy.txt +160 -0
  76. package/nvim/plugins/mini.nvim/doc/mini-git.txt +425 -0
  77. package/nvim/plugins/mini.nvim/doc/mini-hipatterns.txt +489 -0
  78. package/nvim/plugins/mini.nvim/doc/mini-hues.txt +420 -0
  79. package/nvim/plugins/mini.nvim/doc/mini-icons.txt +508 -0
  80. package/nvim/plugins/mini.nvim/doc/mini-indentscope.txt +485 -0
  81. package/nvim/plugins/mini.nvim/doc/mini-input.txt +932 -0
  82. package/nvim/plugins/mini.nvim/doc/mini-jump.txt +202 -0
  83. package/nvim/plugins/mini.nvim/doc/mini-jump2d.txt +525 -0
  84. package/nvim/plugins/mini.nvim/doc/mini-keymap.txt +449 -0
  85. package/nvim/plugins/mini.nvim/doc/mini-map.txt +717 -0
  86. package/nvim/plugins/mini.nvim/doc/mini-misc.txt +431 -0
  87. package/nvim/plugins/mini.nvim/doc/mini-move.txt +181 -0
  88. package/nvim/plugins/mini.nvim/doc/mini-notify.txt +434 -0
  89. package/nvim/plugins/mini.nvim/doc/mini-nvim.txt +431 -0
  90. package/nvim/plugins/mini.nvim/doc/mini-operators.txt +472 -0
  91. package/nvim/plugins/mini.nvim/doc/mini-pairs.txt +346 -0
  92. package/nvim/plugins/mini.nvim/doc/mini-pick.txt +1535 -0
  93. package/nvim/plugins/mini.nvim/doc/mini-sessions.txt +239 -0
  94. package/nvim/plugins/mini.nvim/doc/mini-snippets.txt +1291 -0
  95. package/nvim/plugins/mini.nvim/doc/mini-splitjoin.txt +536 -0
  96. package/nvim/plugins/mini.nvim/doc/mini-starter.txt +618 -0
  97. package/nvim/plugins/mini.nvim/doc/mini-statusline.txt +361 -0
  98. package/nvim/plugins/mini.nvim/doc/mini-surround.txt +863 -0
  99. package/nvim/plugins/mini.nvim/doc/mini-tabline.txt +151 -0
  100. package/nvim/plugins/mini.nvim/doc/mini-test.txt +966 -0
  101. package/nvim/plugins/mini.nvim/doc/mini-trailspace.txt +91 -0
  102. package/nvim/plugins/mini.nvim/doc/mini-visits.txt +937 -0
  103. package/nvim/plugins/mini.nvim/logo.png +0 -0
  104. package/nvim/plugins/mini.nvim/lua/mini/ai.lua +2244 -0
  105. package/nvim/plugins/mini.nvim/lua/mini/align.lua +2076 -0
  106. package/nvim/plugins/mini.nvim/lua/mini/animate.lua +2127 -0
  107. package/nvim/plugins/mini.nvim/lua/mini/base16.lua +1752 -0
  108. package/nvim/plugins/mini.nvim/lua/mini/basics.lua +772 -0
  109. package/nvim/plugins/mini.nvim/lua/mini/bracketed.lua +2013 -0
  110. package/nvim/plugins/mini.nvim/lua/mini/bufremove.lua +283 -0
  111. package/nvim/plugins/mini.nvim/lua/mini/clue.lua +2096 -0
  112. package/nvim/plugins/mini.nvim/lua/mini/cmdline.lua +1182 -0
  113. package/nvim/plugins/mini.nvim/lua/mini/colors.lua +2483 -0
  114. package/nvim/plugins/mini.nvim/lua/mini/comment.lua +586 -0
  115. package/nvim/plugins/mini.nvim/lua/mini/completion.lua +2094 -0
  116. package/nvim/plugins/mini.nvim/lua/mini/cursorword.lua +311 -0
  117. package/nvim/plugins/mini.nvim/lua/mini/deps.lua +1660 -0
  118. package/nvim/plugins/mini.nvim/lua/mini/diff.lua +1938 -0
  119. package/nvim/plugins/mini.nvim/lua/mini/doc.lua +1371 -0
  120. package/nvim/plugins/mini.nvim/lua/mini/extra.lua +2290 -0
  121. package/nvim/plugins/mini.nvim/lua/mini/files.lua +3145 -0
  122. package/nvim/plugins/mini.nvim/lua/mini/fuzzy.lua +356 -0
  123. package/nvim/plugins/mini.nvim/lua/mini/git.lua +1737 -0
  124. package/nvim/plugins/mini.nvim/lua/mini/hipatterns.lua +1042 -0
  125. package/nvim/plugins/mini.nvim/lua/mini/hues.lua +2088 -0
  126. package/nvim/plugins/mini.nvim/lua/mini/icons.lua +2254 -0
  127. package/nvim/plugins/mini.nvim/lua/mini/indentscope.lua +1158 -0
  128. package/nvim/plugins/mini.nvim/lua/mini/init.lua +427 -0
  129. package/nvim/plugins/mini.nvim/lua/mini/input.lua +2183 -0
  130. package/nvim/plugins/mini.nvim/lua/mini/jump.lua +609 -0
  131. package/nvim/plugins/mini.nvim/lua/mini/jump2d.lua +1244 -0
  132. package/nvim/plugins/mini.nvim/lua/mini/keymap.lua +880 -0
  133. package/nvim/plugins/mini.nvim/lua/mini/map.lua +1709 -0
  134. package/nvim/plugins/mini.nvim/lua/mini/misc.lua +969 -0
  135. package/nvim/plugins/mini.nvim/lua/mini/move.lua +509 -0
  136. package/nvim/plugins/mini.nvim/lua/mini/notify.lua +938 -0
  137. package/nvim/plugins/mini.nvim/lua/mini/operators.lua +1349 -0
  138. package/nvim/plugins/mini.nvim/lua/mini/pairs.lua +657 -0
  139. package/nvim/plugins/mini.nvim/lua/mini/pick.lua +3876 -0
  140. package/nvim/plugins/mini.nvim/lua/mini/sessions.lua +689 -0
  141. package/nvim/plugins/mini.nvim/lua/mini/snippets.lua +2828 -0
  142. package/nvim/plugins/mini.nvim/lua/mini/splitjoin.lua +1132 -0
  143. package/nvim/plugins/mini.nvim/lua/mini/starter.lua +1599 -0
  144. package/nvim/plugins/mini.nvim/lua/mini/statusline.lua +686 -0
  145. package/nvim/plugins/mini.nvim/lua/mini/surround.lua +2388 -0
  146. package/nvim/plugins/mini.nvim/lua/mini/tabline.lua +564 -0
  147. package/nvim/plugins/mini.nvim/lua/mini/test.lua +2516 -0
  148. package/nvim/plugins/mini.nvim/lua/mini/trailspace.lua +215 -0
  149. package/nvim/plugins/mini.nvim/lua/mini/visits.lua +1577 -0
  150. package/nvim/plugins/mini.nvim/readmes/mini-ai.md +190 -0
  151. package/nvim/plugins/mini.nvim/readmes/mini-align.md +203 -0
  152. package/nvim/plugins/mini.nvim/readmes/mini-animate.md +214 -0
  153. package/nvim/plugins/mini.nvim/readmes/mini-base16.md +198 -0
  154. package/nvim/plugins/mini.nvim/readmes/mini-basics.md +184 -0
  155. package/nvim/plugins/mini.nvim/readmes/mini-bracketed.md +193 -0
  156. package/nvim/plugins/mini.nvim/readmes/mini-bufremove.md +139 -0
  157. package/nvim/plugins/mini.nvim/readmes/mini-clue.md +260 -0
  158. package/nvim/plugins/mini.nvim/readmes/mini-cmdline.md +183 -0
  159. package/nvim/plugins/mini.nvim/readmes/mini-colors.md +169 -0
  160. package/nvim/plugins/mini.nvim/readmes/mini-comment.md +183 -0
  161. package/nvim/plugins/mini.nvim/readmes/mini-completion.md +217 -0
  162. package/nvim/plugins/mini.nvim/readmes/mini-cursorword.md +137 -0
  163. package/nvim/plugins/mini.nvim/readmes/mini-deps.md +271 -0
  164. package/nvim/plugins/mini.nvim/readmes/mini-diff.md +289 -0
  165. package/nvim/plugins/mini.nvim/readmes/mini-doc.md +198 -0
  166. package/nvim/plugins/mini.nvim/readmes/mini-extra.md +158 -0
  167. package/nvim/plugins/mini.nvim/readmes/mini-files.md +247 -0
  168. package/nvim/plugins/mini.nvim/readmes/mini-fuzzy.md +134 -0
  169. package/nvim/plugins/mini.nvim/readmes/mini-git.md +168 -0
  170. package/nvim/plugins/mini.nvim/readmes/mini-hipatterns.md +176 -0
  171. package/nvim/plugins/mini.nvim/readmes/mini-hues.md +285 -0
  172. package/nvim/plugins/mini.nvim/readmes/mini-icons.md +183 -0
  173. package/nvim/plugins/mini.nvim/readmes/mini-indentscope.md +191 -0
  174. package/nvim/plugins/mini.nvim/readmes/mini-input.md +163 -0
  175. package/nvim/plugins/mini.nvim/readmes/mini-jump.md +161 -0
  176. package/nvim/plugins/mini.nvim/readmes/mini-jump2d.md +197 -0
  177. package/nvim/plugins/mini.nvim/readmes/mini-keymap.md +205 -0
  178. package/nvim/plugins/mini.nvim/readmes/mini-map.md +191 -0
  179. package/nvim/plugins/mini.nvim/readmes/mini-misc.md +145 -0
  180. package/nvim/plugins/mini.nvim/readmes/mini-move.md +163 -0
  181. package/nvim/plugins/mini.nvim/readmes/mini-notify.md +175 -0
  182. package/nvim/plugins/mini.nvim/readmes/mini-operators.md +193 -0
  183. package/nvim/plugins/mini.nvim/readmes/mini-pairs.md +158 -0
  184. package/nvim/plugins/mini.nvim/readmes/mini-pick.md +340 -0
  185. package/nvim/plugins/mini.nvim/readmes/mini-sessions.md +164 -0
  186. package/nvim/plugins/mini.nvim/readmes/mini-snippets.md +373 -0
  187. package/nvim/plugins/mini.nvim/readmes/mini-splitjoin.md +194 -0
  188. package/nvim/plugins/mini.nvim/readmes/mini-starter.md +176 -0
  189. package/nvim/plugins/mini.nvim/readmes/mini-statusline.md +155 -0
  190. package/nvim/plugins/mini.nvim/readmes/mini-surround.md +190 -0
  191. package/nvim/plugins/mini.nvim/readmes/mini-tabline.md +156 -0
  192. package/nvim/plugins/mini.nvim/readmes/mini-test.md +175 -0
  193. package/nvim/plugins/mini.nvim/readmes/mini-trailspace.md +137 -0
  194. package/nvim/plugins/mini.nvim/readmes/mini-visits.md +243 -0
  195. package/nvim/plugins/mini.nvim/scripts/dual_log.sh +13 -0
  196. package/nvim/plugins/mini.nvim/scripts/dual_push.sh +15 -0
  197. package/nvim/plugins/mini.nvim/scripts/dual_release.sh +102 -0
  198. package/nvim/plugins/mini.nvim/scripts/dual_sync.sh +115 -0
  199. package/nvim/plugins/mini.nvim/scripts/init-deps-example.lua +59 -0
  200. package/nvim/plugins/mini.nvim/scripts/lint-filename-length.sh +16 -0
  201. package/nvim/plugins/mini.nvim/scripts/lintcommit-ci.sh +18 -0
  202. package/nvim/plugins/mini.nvim/scripts/lintcommit.lua +393 -0
  203. package/nvim/plugins/mini.nvim/scripts/minidoc.lua +57 -0
  204. package/nvim/plugins/mini.nvim/scripts/minimal_init.lua +28 -0
  205. package/nvim/plugins/mini.nvim/scripts/minitest.lua +4 -0
  206. package/package.json +16 -0
  207. package/pyproject.toml +43 -0
  208. package/yazi/init.lua +12 -0
  209. package/yazi/keymap.toml +114 -0
  210. package/yazi/lesskey +5 -0
  211. package/yazi/plugins/bookmarks.yazi/main.lua +86 -0
  212. package/yazi/plugins/cd-git-root.yazi/main.lua +31 -0
  213. package/yazi/plugins/smart-enter.yazi/main.lua +11 -0
  214. package/yazi/theme.toml +26 -0
  215. package/yazi/yazi.toml +15 -0
  216. package/zsh/.zshrc +145 -0
  217. package/zsh/starship.toml +20 -0
  218. package/zsh/zsh-patina.toml +2 -0
@@ -0,0 +1,586 @@
1
+ --- *mini.comment* Comment lines
2
+ ---
3
+ --- MIT License Copyright (c) 2021 Evgeni Chasnovski
4
+
5
+ --- Features:
6
+ --- - Commenting in Normal mode respects |count| and is dot-repeatable.
7
+ ---
8
+ --- - Comment structure by default is inferred from |'commentstring'|: either
9
+ --- from current buffer or from locally active tree-sitter language.
10
+ --- It can be customized via `options.custom_commentstring`
11
+ --- (see |MiniComment.config| for details).
12
+ ---
13
+ --- - Allows custom hooks before and after successful commenting.
14
+ ---
15
+ --- - Configurable options for some nuanced behavior.
16
+ ---
17
+ --- What it doesn't do:
18
+ --- - Block and sub-line comments. This will only support per-line commenting.
19
+ ---
20
+ --- - Handle indentation with mixed tab and space.
21
+ ---
22
+ --- - Preserve trailing whitespace in empty lines.
23
+ ---
24
+ --- Notes:
25
+ --- - To use tree-sitter aware commenting, global value of |'commentstring'|
26
+ --- should be `''` (empty string). This is the default value, so make sure to
27
+ --- not set it manually to a different value.
28
+ ---
29
+ --- # Setup ~
30
+ ---
31
+ --- This module needs a setup with `require('mini.comment').setup({})` (replace
32
+ --- `{}` with your `config` table). It will create global Lua table
33
+ --- `MiniComment` which you can use for scripting or manually (with
34
+ --- `:lua MiniComment.*`).
35
+ ---
36
+ --- See |MiniComment.config| for `config` structure and default values.
37
+ ---
38
+ --- You can override runtime config settings locally to buffer inside
39
+ --- `vim.b.minicomment_config` which should have same structure as
40
+ --- `MiniComment.config`. See |mini.nvim-buffer-local-config| for more details.
41
+ ---
42
+ --- # Disabling ~
43
+ ---
44
+ --- To disable core functionality, set `vim.g.minicomment_disable` (globally) or
45
+ --- `vim.b.minicomment_disable` (for a buffer) to `true`. Considering high number
46
+ --- of different scenarios and customization intentions, writing exact rules
47
+ --- for disabling module's functionality is left to user. See
48
+ --- |mini.nvim-disabling-recipes| for common recipes.
49
+ ---@tag MiniComment
50
+
51
+ -- Module definition ==========================================================
52
+ local MiniComment = {}
53
+ local H = {}
54
+
55
+ --- Module setup
56
+ ---
57
+ ---@param config table|nil Module config table. See |MiniComment.config|.
58
+ ---
59
+ ---@usage >lua
60
+ --- require('mini.comment').setup() -- use default config
61
+ --- -- OR
62
+ --- require('mini.comment').setup({}) -- replace {} with your config table
63
+ --- <
64
+ MiniComment.setup = function(config)
65
+ -- TODO: Remove after Neovim=0.9 support is dropped
66
+ if vim.fn.has('nvim-0.10') == 0 then
67
+ vim.notify(
68
+ '(mini.comment) Neovim<0.10 is soft deprecated (module works but is not supported).'
69
+ .. " It will be deprecated after the next 'mini.nvim' release (module might not work)."
70
+ .. ' Please update your Neovim version.'
71
+ )
72
+ end
73
+
74
+ -- Export module
75
+ _G.MiniComment = MiniComment
76
+
77
+ -- Setup config
78
+ config = H.setup_config(config)
79
+
80
+ -- Apply config
81
+ H.apply_config(config)
82
+ end
83
+
84
+ --- Defaults ~
85
+ ---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
86
+ ---@text # Options ~
87
+ ---
88
+ --- ## Custom commentstring ~
89
+ ---
90
+ --- `options.custom_commentstring` can be a function customizing |'commentstring'|
91
+ --- option used to infer comment structure. It is called once before every
92
+ --- commenting action with the following arguments:
93
+ --- - `ref_position` - position at which to compute |'commentstring'| (might be
94
+ --- relevant for a text with locally different commenting rules). Its structure
95
+ --- is the same as `opts.ref_position` in |MiniComment.toggle_lines()|.
96
+ ---
97
+ --- Its output should be a valid |'commentstring'| (string containing `%s`).
98
+ ---
99
+ --- If not set or the output is `nil`, |MiniComment.get_commentstring()| is used.
100
+ ---
101
+ --- For example, this option can be used to always use buffer |'commentstring'|
102
+ --- even in case of present active tree-sitter parser: >lua
103
+ ---
104
+ --- require('mini.comment').setup({
105
+ --- options = {
106
+ --- custom_commentstring = function() return vim.bo.commentstring end,
107
+ --- }
108
+ --- })
109
+ --- <
110
+ --- # Hooks ~
111
+ ---
112
+ --- `hooks.pre` and `hooks.post` functions are executed before and after successful
113
+ --- commenting action (toggle or computing textobject). They will be called
114
+ --- with a single table argument which has the following fields:
115
+ --- - <action> `(string)` - action name. One of "toggle" (when actual toggle
116
+ --- direction is yet unknown), "comment", "uncomment", "textobject".
117
+ --- - <line_start> `(number|nil)` - action start line. Can be absent if yet unknown.
118
+ --- - <line_end> `(number|nil)` - action end line. Can be absent if yet unknown.
119
+ --- - <ref_position> `(table|nil)` - reference position.
120
+ ---
121
+ --- Notes:
122
+ --- - Changing |'commentstring'| in `hooks.pre` is allowed and will take effect.
123
+ --- - If hook returns `false`, any further action is terminated.
124
+ MiniComment.config = {
125
+ -- Options which control module behavior
126
+ options = {
127
+ -- Function to compute custom 'commentstring' (optional)
128
+ custom_commentstring = nil,
129
+
130
+ -- Whether to ignore blank lines in actions and textobject
131
+ ignore_blank_line = false,
132
+
133
+ -- Whether to recognize as comment only lines without indent
134
+ start_of_line = false,
135
+
136
+ -- Whether to force single space inner padding for comment parts
137
+ pad_comment_parts = true,
138
+ },
139
+
140
+ -- Module mappings. Use `''` (empty string) to disable one.
141
+ mappings = {
142
+ -- Toggle comment (like `gcip` - comment inner paragraph) for both
143
+ -- Normal and Visual modes
144
+ comment = 'gc',
145
+
146
+ -- Toggle comment on current line
147
+ comment_line = 'gcc',
148
+
149
+ -- Toggle comment on visual selection
150
+ comment_visual = 'gc',
151
+
152
+ -- Define 'comment' textobject (like `dgc` - delete whole comment block)
153
+ -- Works also in Visual mode if mapping differs from `comment_visual`
154
+ textobject = 'gc',
155
+ },
156
+
157
+ -- Hook functions to be executed at certain stage of commenting
158
+ hooks = {
159
+ -- Before successful commenting. Does nothing by default.
160
+ pre = function() end,
161
+ -- After successful commenting. Does nothing by default.
162
+ post = function() end,
163
+ },
164
+ }
165
+ --minidoc_afterlines_end
166
+
167
+ -- Module functionality =======================================================
168
+ --- Main function to be mapped
169
+ ---
170
+ --- It is meant to be used in expression mappings (see |:map-<expr>|) to enable
171
+ --- dot-repeatability and commenting on range. There is no need to do this
172
+ --- manually, everything is done inside |MiniComment.setup()|.
173
+ ---
174
+ --- It has a somewhat unintuitive logic (because of how expression mapping with
175
+ --- dot-repeatability works): it should be called without arguments inside
176
+ --- expression mapping and with argument when action should be performed.
177
+ ---
178
+ ---@param mode string|nil Optional string with |'operatorfunc'| mode (see |g@|).
179
+ ---
180
+ ---@return string|nil `'g@'` if called without argument, `''` otherwise (but after
181
+ --- performing action).
182
+ MiniComment.operator = function(mode)
183
+ if H.is_disabled() then return '' end
184
+
185
+ -- If used without arguments inside expression mapping:
186
+ -- - Set itself as `operatorfunc` to be called later to perform action.
187
+ -- - Return 'g@' which will then be executed resulting into waiting for a
188
+ -- motion or text object. This textobject will then be recorded using `'[`
189
+ -- and `']` marks. After that, `operatorfunc` is called with `mode` equal
190
+ -- to one of "line", "char", or "block".
191
+ -- NOTE: setting `operatorfunc` inside this function enables usage of 'count'
192
+ -- like `10gc_` toggles comments of 10 lines below (starting with current).
193
+ if mode == nil then
194
+ vim.o.operatorfunc = 'v:lua.MiniComment.operator'
195
+ return 'g@'
196
+ end
197
+
198
+ -- If called with non-nil `mode`, get target region and act on it
199
+ -- This also works in expression mapping in Visual mode, as `g@` seems to
200
+ -- place these marks on start and end of visual selection
201
+ local mark_left, mark_right = '[', ']'
202
+ local lnum_from, col_from = unpack(vim.api.nvim_buf_get_mark(0, mark_left))
203
+ local lnum_to, col_to = unpack(vim.api.nvim_buf_get_mark(0, mark_right))
204
+
205
+ -- Do nothing if "from" mark is after "to" (like in empty textobject)
206
+ if (lnum_from > lnum_to) or (lnum_from == lnum_to and col_from > col_to) then return end
207
+
208
+ -- NOTE: use cursor position as reference for possibly computing local
209
+ -- tree-sitter-based 'commentstring'. Recompute every time for a proper
210
+ -- dot-repeat. In Visual and sometimes Normal mode it uses left position.
211
+ local cursor = vim.api.nvim_win_get_cursor(0)
212
+ MiniComment.toggle_lines(lnum_from, lnum_to, { ref_position = { cursor[1], cursor[2] + 1 } })
213
+ return ''
214
+ end
215
+
216
+ --- Toggle comments between two line numbers
217
+ ---
218
+ --- It uncomments if lines are comment (every line is a comment or blank) and
219
+ --- comments otherwise. It respects indentation and doesn't insert trailing
220
+ --- whitespace. Toggle commenting not in visual mode is also dot-repeatable
221
+ --- and respects |count|.
222
+ ---
223
+ --- # Notes ~
224
+ ---
225
+ --- - Comment structure is inferred from buffer's |'commentstring'| option or
226
+ --- local language of tree-sitter parser (if active).
227
+ ---
228
+ --- - Call to this function will remove all |extmarks| from target range.
229
+ ---
230
+ ---@param line_start number Start line number (inclusive from 1 to number of lines).
231
+ ---@param line_end number End line number (inclusive from 1 to number of lines).
232
+ ---@param opts table|nil Options. Possible fields:
233
+ --- - <ref_position> `(table)` - A two-value array with `{ row, col }` (both
234
+ --- starting at 1) of reference position at which |'commentstring'| value
235
+ --- will be computed. Default: `{ line_start, 1 }`.
236
+ MiniComment.toggle_lines = function(line_start, line_end, opts)
237
+ if H.is_disabled() then return end
238
+
239
+ opts = opts or {}
240
+ local ref_position = vim.deepcopy(opts.ref_position) or { line_start, 1 }
241
+
242
+ local n_lines = vim.api.nvim_buf_line_count(0)
243
+ if not (1 <= line_start and line_start <= n_lines and 1 <= line_end and line_end <= n_lines) then
244
+ error('(mini.comment) `line_start` and `line_end` should be within range [1; ' .. n_lines .. '].')
245
+ end
246
+ if not (line_start <= line_end) then
247
+ error('(mini.comment) `line_start` should be less than or equal to `line_end`.')
248
+ end
249
+
250
+ local config = H.get_config()
251
+ local hook_arg = { action = 'toggle', line_start = line_start, line_end = line_end, ref_position = ref_position }
252
+ if config.hooks.pre(hook_arg) == false then return end
253
+
254
+ local parts = H.get_comment_parts(ref_position, config.options)
255
+ local lines = vim.api.nvim_buf_get_lines(0, line_start - 1, line_end, false)
256
+ local indent, is_comment = H.get_lines_info(lines, parts, config.options)
257
+
258
+ local f = is_comment and H.make_uncomment_function(parts) or H.make_comment_function(parts, indent, config.options)
259
+
260
+ -- NOTE: Direct of `nvim_buf_set_lines()` essentially removes (squashes to
261
+ -- empty range at either side of the region) both regular and extended marks
262
+ -- inside region. It can be resolved at least in the following ways:
263
+ -- 1. Use `lockmarks`. Preserves regular but does nothing for extmarks.
264
+ -- 2. Use `vim.fn.setline(line_start, new_lines)`. Preserves regular marks,
265
+ -- but squashes extmarks within a single line.
266
+ -- 3. Refactor to use precise editing of lines with `nvim_buf_set_text()`.
267
+ -- Preserves both regular and extended marks.
268
+ --
269
+ -- But:
270
+ -- - Options 2 and 3 are **significantly** slower for a large-ish regions.
271
+ -- Toggle of ~4000 lines takes 20 ms for 1, 200 ms for 2, 400 ms for 3.
272
+ --
273
+ -- - Preserving extmarks is not a universally good thing to do. It looks like
274
+ -- a good idea for extmarks which are not used for directly highlighting
275
+ -- text (like for 'mini.diff' signs or smartly tracking buffer position).
276
+ -- However, preserving extmarks is not 100% desirable when they highlight
277
+ -- text area, as every comment toggle at least results in a flickering
278
+ -- due to those extmarks still highlighting a (un)commented region.
279
+ -- Main example is LSP semantic token highlighting. Although it can have
280
+ -- special treatment (precisely clear those extmarks in the target region),
281
+ -- it is not 100% effective (they are restored after undo, again resulting
282
+ -- into flicker) and there might be more unnoticed issues.
283
+ --
284
+ -- So all in all, computing and replacing whole lines with `lockmarks` is the
285
+ -- best compromise so far. It also aligns with treating "toggle comment" in
286
+ -- a semantic way (those lines lines now have completely different meaning)
287
+ -- rather than in a text edit way (add comment parts to those lines).
288
+ _G._from, _G._to, _G._lines = line_start - 1, line_end, vim.tbl_map(f, lines)
289
+ vim.cmd('lockmarks lua pcall(vim.api.nvim_buf_set_lines, 0, _G._from, _G._to, false, _G._lines)')
290
+ _G._from, _G._to, _G._lines = nil, nil, nil
291
+
292
+ hook_arg.action = is_comment and 'uncomment' or 'comment'
293
+ if config.hooks.post(hook_arg) == false then return end
294
+ end
295
+
296
+ --- Select comment textobject
297
+ ---
298
+ --- This selects all commented lines adjacent to cursor line. If `ignore_blank_line`
299
+ --- option is enabled (see |MiniComment.config|), blank lines between commented
300
+ --- lines are treated as part of textobject.
301
+ --- Designed to be used with operator mode mappings (see |mapmode-o|).
302
+ MiniComment.textobject = function()
303
+ if H.is_disabled() then return end
304
+
305
+ local config = H.get_config()
306
+ local hook_args = { action = 'textobject' }
307
+ if config.hooks.pre(hook_args) == false then return end
308
+
309
+ local lnum_cur = vim.fn.line('.')
310
+ local parts = H.get_comment_parts({ lnum_cur, vim.fn.col('.') }, config.options)
311
+ local comment_check = H.make_comment_check(parts, config.options)
312
+ local lnum_from, lnum_to
313
+
314
+ local ignore_blank_line = config.options.ignore_blank_line
315
+ local check = function(lnum)
316
+ if lnum == 0 then return false end
317
+ local l = vim.fn.getline(lnum)
318
+ return comment_check(l) or (ignore_blank_line and H.is_blank(l))
319
+ end
320
+
321
+ -- Recognize textobject if on comment or (possibly) blank between comments
322
+ local lnum_prev = vim.fn.prevnonblank(lnum_cur)
323
+ local is_in_comments = (lnum_prev == lnum_cur and check(lnum_prev))
324
+ or (ignore_blank_line and lnum_prev ~= lnum_cur and check(lnum_prev) and check(vim.fn.nextnonblank(lnum_cur)))
325
+
326
+ if is_in_comments then
327
+ lnum_from = lnum_cur
328
+ while (lnum_from >= 2) and check(lnum_from - 1) do
329
+ lnum_from = lnum_from - 1
330
+ end
331
+ if ignore_blank_line then lnum_from = vim.fn.nextnonblank(lnum_from) end
332
+
333
+ lnum_to = lnum_cur
334
+ local n_lines = vim.api.nvim_buf_line_count(0)
335
+ while (lnum_to <= n_lines - 1) and check(lnum_to + 1) do
336
+ lnum_to = lnum_to + 1
337
+ end
338
+ if ignore_blank_line then lnum_to = vim.fn.prevnonblank(lnum_to) end
339
+
340
+ local is_visual = vim.tbl_contains({ 'v', 'V', '\22' }, vim.fn.mode())
341
+ if is_visual then vim.cmd('normal! \27') end
342
+
343
+ -- This visual selection doesn't seem to change `'<` and `'>` marks when
344
+ -- executed as `onoremap` mapping
345
+ vim.cmd('normal! ' .. lnum_from .. 'GV' .. lnum_to .. 'G')
346
+ end
347
+
348
+ hook_args.line_start, hook_args.line_end = lnum_from, lnum_to
349
+ if config.hooks.post(hook_args) == false then return end
350
+ end
351
+
352
+ --- Get |'commentstring'|
353
+ ---
354
+ --- This represents default approach of computing relevant |'commentstring'|
355
+ --- option in current buffer. Used to infer comment structure.
356
+ ---
357
+ --- It has the following logic:
358
+ --- - If there is an active tree-sitter parser, try to get |'commentstring'| from
359
+ --- the local language at `ref_position`.
360
+ ---
361
+ --- - If first step is not successful, use buffer's |'commentstring'| directly.
362
+ ---
363
+ ---@param ref_position table Reference position inside current buffer at which
364
+ --- to compute |'commentstring'|. Same structure as `opts.ref_position`
365
+ --- in |MiniComment.toggle_lines()|.
366
+ ---
367
+ ---@return string Relevant value of |'commentstring'|.
368
+ MiniComment.get_commentstring = function(ref_position)
369
+ local buf_cs = vim.bo.commentstring
370
+
371
+ -- TODO: Remove `opts.error` after compatibility with Neovim=0.11 is dropped
372
+ local has_parser, parser = pcall(vim.treesitter.get_parser, 0, nil, { error = false })
373
+ if not has_parser or parser == nil then return buf_cs end
374
+
375
+ -- Try to get 'commentstring' associated with local tree-sitter language.
376
+ -- This is useful for injected languages (like markdown with code blocks).
377
+ -- Sources:
378
+ -- - https://github.com/neovim/neovim/pull/22634#issue-1620078948
379
+ -- - https://github.com/neovim/neovim/pull/22643
380
+ local row, col = ref_position[1] - 1, ref_position[2] - 1
381
+ local ref_range = { row, col, row, col + 1 }
382
+
383
+ -- - Get 'commentstring' from the deepest LanguageTree which both contains
384
+ -- reference range and has valid 'commentstring' (meaning it has at least
385
+ -- one associated 'filetype' with valid 'commentstring').
386
+ -- In simple cases using `parser:language_for_range()` would be enough, but
387
+ -- it fails for languages without valid 'commentstring' (like 'comment').
388
+ local ts_cs, res_level = nil, 0
389
+ local traverse
390
+
391
+ traverse = function(lang_tree, level)
392
+ if not lang_tree:contains(ref_range) then return end
393
+
394
+ local lang = lang_tree:lang()
395
+ local filetypes = vim.treesitter.language.get_filetypes(lang)
396
+ for _, ft in ipairs(filetypes) do
397
+ -- Using `vim.filetype.get_option()` for performance as it has caching
398
+ local cur_cs = vim.filetype.get_option(ft, 'commentstring')
399
+ if type(cur_cs) == 'string' and cur_cs ~= '' and level > res_level then
400
+ ts_cs, res_level = cur_cs, level
401
+ end
402
+ end
403
+
404
+ for _, child_lang_tree in pairs(lang_tree:children()) do
405
+ traverse(child_lang_tree, level + 1)
406
+ end
407
+ end
408
+ traverse(parser, 1)
409
+
410
+ return ts_cs or buf_cs
411
+ end
412
+
413
+ -- Helper data ================================================================
414
+ -- Module default config
415
+ H.default_config = vim.deepcopy(MiniComment.config)
416
+
417
+ -- Helper functionality =======================================================
418
+ -- Settings -------------------------------------------------------------------
419
+ H.setup_config = function(config)
420
+ H.check_type('config', config, 'table', true)
421
+ config = vim.tbl_deep_extend('force', vim.deepcopy(H.default_config), config or {})
422
+
423
+ H.check_type('options', config.options, 'table')
424
+ H.check_type('options.custom_commentstring', config.options.custom_commentstring, 'function', true)
425
+ H.check_type('options.ignore_blank_line', config.options.ignore_blank_line, 'boolean')
426
+ H.check_type('options.start_of_line', config.options.start_of_line, 'boolean')
427
+ H.check_type('options.pad_comment_parts', config.options.pad_comment_parts, 'boolean')
428
+
429
+ H.check_type('mappings', config.mappings, 'table')
430
+ H.check_type('mappings.comment', config.mappings.comment, 'string')
431
+ H.check_type('mappings.comment_line', config.mappings.comment_line, 'string')
432
+ H.check_type('mappings.comment_visual', config.mappings.comment_visual, 'string')
433
+ H.check_type('mappings.textobject', config.mappings.textobject, 'string')
434
+
435
+ H.check_type('hooks', config.hooks, 'table')
436
+ H.check_type('hooks.pre', config.hooks.pre, 'function')
437
+ H.check_type('hooks.post', config.hooks.post, 'function')
438
+
439
+ return config
440
+ end
441
+
442
+ H.apply_config = function(config)
443
+ MiniComment.config = config
444
+
445
+ -- Make mappings
446
+ local operator_rhs = function() return MiniComment.operator() end
447
+ H.map('n', config.mappings.comment, operator_rhs, { expr = true, desc = 'Comment' })
448
+ H.map('x', config.mappings.comment_visual, operator_rhs, { expr = true, desc = 'Comment selection' })
449
+ H.map(
450
+ 'n',
451
+ config.mappings.comment_line,
452
+ function() return MiniComment.operator() .. '_' end,
453
+ { expr = true, desc = 'Comment line' }
454
+ )
455
+ -- Use `<Cmd>...<CR>` to have proper dot-repeat
456
+ -- See https://github.com/neovim/neovim/issues/23406
457
+ local modes = config.mappings.textobject == config.mappings.comment_visual and { 'o' } or { 'x', 'o' }
458
+ H.map(modes, config.mappings.textobject, '<Cmd>lua MiniComment.textobject()<CR>', { desc = 'Comment textobject' })
459
+ end
460
+
461
+ H.is_disabled = function() return vim.g.minicomment_disable == true or vim.b.minicomment_disable == true end
462
+
463
+ H.get_config = function(config)
464
+ return vim.tbl_deep_extend('force', MiniComment.config, vim.b.minicomment_config or {}, config or {})
465
+ end
466
+
467
+ -- Core implementations -------------------------------------------------------
468
+ H.get_comment_parts = function(ref_position, options)
469
+ local cs
470
+ if vim.is_callable(options.custom_commentstring) then cs = options.custom_commentstring(ref_position) end
471
+ cs = cs or MiniComment.get_commentstring(ref_position)
472
+
473
+ if cs == nil or cs == '' then
474
+ vim.api.nvim_echo({ { '(mini.comment) ', 'WarningMsg' }, { [[Option 'commentstring' is empty.]] } }, true, {})
475
+ return { left = '', right = '' }
476
+ end
477
+
478
+ if not (type(cs) == 'string' and string.find(cs, '%%s') ~= nil) then
479
+ H.error(vim.inspect(cs) .. " is not a valid 'commentstring'.")
480
+ end
481
+
482
+ -- Structure of 'commentstring': <left part> <%s> <right part>
483
+ local left, right = string.match(cs, '^(.-)%%s(.-)$')
484
+
485
+ -- Force single space padding if requested
486
+ if options.pad_comment_parts then
487
+ left, right = vim.trim(left), vim.trim(right)
488
+ left, right = left == '' and '' or (left .. ' '), right == '' and '' or (' ' .. right)
489
+ end
490
+ return { left = left, right = right }
491
+ end
492
+
493
+ H.make_comment_check = function(parts, options)
494
+ local l_esc, r_esc = vim.pesc(parts.left), vim.pesc(parts.right)
495
+ local prefix = options.start_of_line and '' or '%s-'
496
+
497
+ -- Commented line has the following structure:
498
+ -- <whitespace> <trimmed left> <anything> <trimmed right> <whitespace>
499
+ local regex = '^' .. prefix .. vim.trim(l_esc) .. '.*' .. vim.trim(r_esc) .. '%s-$'
500
+
501
+ return function(line) return string.find(line, regex) ~= nil end
502
+ end
503
+
504
+ H.get_lines_info = function(lines, parts, options)
505
+ local comment_check = H.make_comment_check(parts, options)
506
+
507
+ local is_commented = true
508
+ local indent, indent_width = nil, math.huge
509
+
510
+ for _, l in ipairs(lines) do
511
+ -- Update lines indent: minimum of all indents except blank lines
512
+ local _, indent_width_cur, indent_cur = string.find(l, '^(%s*)')
513
+
514
+ -- Ignore blank lines completely when making a decision
515
+ if indent_width_cur < l:len() then
516
+ -- NOTE: Copying actual indent instead of recreating it with `indent_width`
517
+ -- allows to handle both tabs and spaces
518
+ if indent_width_cur < indent_width then
519
+ indent_width, indent = indent_width_cur, indent_cur
520
+ end
521
+
522
+ -- Update comment info: commented if every non-blank line is commented
523
+ if is_commented then is_commented = comment_check(l) end
524
+ end
525
+ end
526
+
527
+ -- `indent` can still be `nil` in case all `lines` are empty
528
+ return indent or '', is_commented
529
+ end
530
+
531
+ H.make_comment_function = function(parts, indent, options)
532
+ local prefix = options.start_of_line and (parts.left .. indent) or (indent .. parts.left)
533
+ local nonindent_start = string.len(indent) + 1
534
+ local suffix = parts.right
535
+
536
+ local blank_comment = indent .. vim.trim(parts.left) .. vim.trim(parts.right)
537
+ local ignore_blank_line = options.ignore_blank_line
538
+
539
+ return function(line)
540
+ if H.is_blank(line) then return ignore_blank_line and line or blank_comment end
541
+
542
+ return prefix .. string.sub(line, nonindent_start) .. suffix
543
+ end
544
+ end
545
+
546
+ H.make_uncomment_function = function(parts)
547
+ local l_esc, r_esc = vim.pesc(parts.left), vim.pesc(parts.right)
548
+ local regex = '^(%s*)' .. l_esc .. '(.*)' .. r_esc .. '(%s-)$'
549
+ local regex_trimmed = '^(%s*)' .. vim.trim(l_esc) .. '(.*)' .. vim.trim(r_esc) .. '(%s-)$'
550
+
551
+ return function(line)
552
+ -- Try regex with exact comment parts first, fall back to trimmed parts
553
+ local indent, new_line, trail = line:match(regex)
554
+ if new_line == nil then
555
+ indent, new_line, trail = line:match(regex_trimmed)
556
+ end
557
+
558
+ -- Return original if line is not commented
559
+ if new_line == nil then return line end
560
+
561
+ -- Prevent trailing whitespace
562
+ if H.is_blank(new_line) then
563
+ indent, trail = '', ''
564
+ end
565
+
566
+ return indent .. new_line .. trail
567
+ end
568
+ end
569
+
570
+ -- Utilities ------------------------------------------------------------------
571
+ H.error = function(msg) error('(mini.comment) ' .. msg, 0) end
572
+
573
+ H.check_type = function(name, val, ref, allow_nil)
574
+ if type(val) == ref or (ref == 'callable' and vim.is_callable(val)) or (allow_nil and val == nil) then return end
575
+ H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
576
+ end
577
+
578
+ H.map = function(mode, lhs, rhs, opts)
579
+ if lhs == '' then return end
580
+ opts = vim.tbl_deep_extend('force', { silent = true }, opts or {})
581
+ vim.keymap.set(mode, lhs, rhs, opts)
582
+ end
583
+
584
+ H.is_blank = function(x) return string.find(x, '^%s*$') ~= nil end
585
+
586
+ return MiniComment