Skip to content

Commit 04c62f2

Browse files
Freed-Wusmeikx
and
smeikx
committed
🩹 Convert method declarations to regular functions
The colon syntax is meant for methods, which are functions that take a ‘self’ parameter as first argument. If a function is declared as a method, and it is later invoked with dot syntax, the first argument could be replaced with an empty table. Co-authored-by: smeikx <smeikx@noreply.codeberg.org>
1 parent fe1ec72 commit 04c62f2

File tree

4 files changed

+57
-56
lines changed

4 files changed

+57
-56
lines changed

.pre-commit-config.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
hooks:
2626
- id: remove-crlf
2727
- repo: https://github.com/codespell-project/codespell
28-
rev: v2.3.0
28+
rev: v2.4.1
2929
hooks:
3030
- id: codespell
3131
additional_dependencies:
@@ -37,23 +37,23 @@ repos:
3737
args:
3838
- --msg-filename
3939
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
40-
rev: 3.0.3
40+
rev: 3.2.0
4141
hooks:
4242
- id: editorconfig-checker
4343
- repo: https://github.com/jumanjihouse/pre-commit-hooks
4444
rev: 3.0.0
4545
hooks:
4646
- id: check-mailmap
4747
- repo: https://github.com/rhysd/actionlint
48-
rev: v1.7.6
48+
rev: v1.7.7
4949
hooks:
5050
- id: actionlint
5151
- repo: https://github.com/adrienverge/yamllint
5252
rev: v1.35.1
5353
hooks:
5454
- id: yamllint
5555
- repo: https://github.com/executablebooks/mdformat
56-
rev: 0.7.21
56+
rev: 0.7.22
5757
hooks:
5858
- id: mdformat
5959
additional_dependencies:
@@ -67,7 +67,7 @@ repos:
6767
- mdformat-config
6868
- mdformat-web
6969
- repo: https://github.com/DavidAnson/markdownlint-cli2
70-
rev: v0.17.1
70+
rev: v0.17.2
7171
hooks:
7272
- id: markdownlint-cli2
7373
additional_dependencies:
@@ -77,6 +77,6 @@ repos:
7777
hooks:
7878
- id: luacheck
7979
- repo: https://github.com/NixOS/nixfmt
80-
rev: 8d4bd690c247004d90d8554f0b746b1231fe2436
80+
rev: e825e956ae967ee24aa502a90099956d1f8bc1ed
8181
hooks:
8282
- id: nixfmt

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ $ luarocks --lua-version 5.1 --local --tree ~/.local/share/nvim/rocks install ri
9595
Refer [config](https://rime-nvim.readthedocs.io/en/latest/modules/lua.rime.config.html):
9696

9797
```lua
98-
require('rime.nvim'):setup({
98+
require('rime.nvim').setup({
9999
-- ...
100100
})
101101
```
@@ -111,7 +111,7 @@ any non-printable key will be passed to rime only if rime window is opened. If
111111
you want to pass a key to rime in any case, try:
112112

113113
```lua
114-
vim.keymap.set('i', '<C-\\>', require('rime.nvim'):callback('<C-\\>'))
114+
vim.keymap.set('i', '<C-\\>', require('rime.nvim').callback('<C-\\>'))
115115
```
116116

117117
It is useful for some key such as the key for switching input schema.
@@ -127,7 +127,7 @@ Because only printable key can be passed to rime when rime window is closed.
127127
Like [cmp-rime](https://github.com/Ninlives/cmp-rime):
128128

129129
```lua
130-
require('cmp'):setup {
130+
require('cmp').setup {
131131
-- ...
132132
sources = {
133133
-- ...
@@ -145,7 +145,7 @@ You can customize it. Such as:
145145
Only display input schema name in insert mode:
146146

147147
```lua
148-
require('rime.nvim'):setup({
148+
require('rime.nvim').setup({
149149
get_new_symbol = function (old, name)
150150
if old == M.airline_mode_map.i
151151
return name
@@ -160,7 +160,7 @@ See airline's `g:airline_mode_map` to know `i`, `R`, `s`, ...
160160
Disable this feature:
161161

162162
```lua
163-
require('rime.nvim'):setup({
163+
require('rime.nvim').setup({
164164
update_status_bar = function () end
165165
})
166166
```

lua/rime/nvim/cmp.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ function M.get_keyword_pattern()
2828
return '\\%([!-~]\\)*'
2929
end
3030

31-
-- luacheck: ignore 212/self
3231
---complete
3332
---@param request table
3433
---@param callback table
35-
function M:complete(request, callback)
34+
-- luacheck: ignore 212/self
35+
---@diagnostic disable-next-line: unused-local
36+
function M.complete(self, request, callback)
3637
local keys = string.sub(request.context.cursor_before_line, request.offset)
3738
M._callback_table[request.context.id] = callback
3839
local cursor = request.context.cursor
3940
local context_id = request.context.id
40-
local menu = nvim_rime:get_context_with_all_candidates(keys).menu
41+
local menu = nvim_rime.get_context_with_all_candidates(keys).menu
4142
local items = {}
4243
for i, candidate in ipairs(menu.candidates) do
4344
local item = {

lua/rime/nvim/init.lua

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---rime support for neovim
22
---@diagnostic disable: undefined-global
3-
-- luacheck: ignore 112 113 212/self
3+
-- luacheck: ignore 112 113
44
local rime = require "rime"
55
local M = require "rime.config"
66

77
---setup
88
---@param conf table
9-
function M:setup(conf)
9+
function M.setup(conf)
1010
M = vim.tbl_deep_extend("keep", conf, M)
1111
end
1212

1313
---process key. wrap `lua.rime.utils.parse_key`()
1414
---@param key string
1515
---@param modifiers string[]
1616
---@see process_keys
17-
function M:process_key(key, modifiers)
17+
function M.process_key(key, modifiers)
1818
modifiers = modifiers or {}
1919
local keycode, mask = require("rime.utils").parse_key(key, modifiers)
2020
return M.session_id:process_key(keycode, mask)
@@ -24,10 +24,10 @@ end
2424
---@param keys string
2525
---@param modifiers string[]
2626
---@see process_key
27-
function M:process_keys(keys, modifiers)
27+
function M.process_keys(keys, modifiers)
2828
modifiers = modifiers or {}
2929
for key in keys:gmatch("(.)") do
30-
if M:process_key(key, modifiers) == false then
30+
if M.process_key(key, modifiers) == false then
3131
return false
3232
end
3333
end
@@ -36,27 +36,27 @@ end
3636

3737
---get callback for draw UI
3838
---@param key string
39-
function M:callback(key)
39+
function M.callback(key)
4040
return function()
4141
if vim.b.rime_is_enabled then
42-
return M:draw_ui(key)
42+
return M.draw_ui(key)
4343
end
4444
end
4545
end
4646

4747
---get rime commit
48-
function M:get_commit_text()
48+
function M.get_commit_text()
4949
if M.session_id:commit_composition() then
5050
return M.session_id:get_commit().text
5151
end
5252
return ""
5353
end
5454

5555
---reset keymaps
56-
function M:reset_keymaps()
56+
function M.reset_keymaps()
5757
if M.preedit ~= "" and M.has_set_keymaps == false then
5858
for _, lhs in ipairs(M.keys.special) do
59-
vim.keymap.set("i", lhs, M:callback(lhs), { buffer = 0, noremap = true, nowait = true, })
59+
vim.keymap.set("i", lhs, M.callback(lhs), { buffer = 0, noremap = true, nowait = true, })
6060
end
6161
M.has_set_keymaps = true
6262
elseif M.preedit == "" and M.has_set_keymaps == true then
@@ -69,7 +69,7 @@ end
6969

7070
---feed keys
7171
---@param text string
72-
function M:feed_keys(text)
72+
function M.feed_keys(text)
7373
if vim.v.char ~= "" then
7474
vim.v.char = text
7575
else
@@ -81,35 +81,35 @@ function M:feed_keys(text)
8181
vim.api.nvim_buf_set_text(0, r - 1, c, r - 1, c, { text })
8282
vim.api.nvim_win_set_cursor(0, { r, c + #text })
8383
end
84-
M:win_close()
84+
M.win_close()
8585
M.preedit = ""
86-
M:reset_keymaps()
86+
M.reset_keymaps()
8787
end
8888

8989
---draw UI. wrap `lua.rime.utils.draw_ui`()
9090
---@param key string
91-
function M:draw_ui(key)
91+
function M.draw_ui(key)
9292
if key == "" then
9393
key = vim.v.char
9494
end
9595
if M.preedit == "" then
9696
for _, disable_key in ipairs(M.keys.disable) do
9797
if key == vim.keycode(disable_key) then
98-
M:disable()
99-
M:update_status_bar()
98+
M.disable()
99+
M.update_status_bar()
100100
end
101101
end
102102
end
103-
if M:process_key(key, {}) == false then
103+
if M.process_key(key, {}) == false then
104104
if #key == 1 then
105-
M:feed_keys(key)
105+
M.feed_keys(key)
106106
end
107107
return
108108
end
109-
M:update_status_bar()
109+
M.update_status_bar()
110110
local context = M.session_id:get_context()
111111
if context.menu.num_candidates == 0 then
112-
M:feed_keys(M:get_commit_text())
112+
M.feed_keys(M.get_commit_text())
113113
return
114114
end
115115
vim.v.char = ""
@@ -144,11 +144,11 @@ function M:draw_ui(key)
144144
end
145145
end
146146
)
147-
M:reset_keymaps()
147+
M.reset_keymaps()
148148
end
149149

150150
---close IME window
151-
function M:win_close()
151+
function M.win_close()
152152
vim.schedule(
153153
function()
154154
if M.win_id ~= 0 and vim.api.nvim_win_is_valid(M.win_id) then
@@ -160,12 +160,12 @@ function M:win_close()
160160
end
161161

162162
---clear composition
163-
function M:clear_composition()
163+
function M.clear_composition()
164164
M.session_id:clear_composition()
165165
end
166166

167167
---initial
168-
function M:init()
168+
function M.init()
169169
if M.session_id == nil then
170170
vim.fn.mkdir(M.traits.log_dir, "p")
171171
local traits = M.traits
@@ -181,23 +181,23 @@ end
181181
---enable IME
182182
---@see disable
183183
---@see toggle
184-
function M:enable()
185-
M:init()
184+
function M.enable()
185+
M.init()
186186
for _, nowait_key in ipairs(M.keys.nowait) do
187187
vim.keymap.set("i", nowait_key, nowait_key, { buffer = 0, noremap = true, nowait = true })
188188
end
189189

190190
vim.api.nvim_create_autocmd("InsertCharPre", {
191191
group = M.augroup_id,
192192
buffer = 0,
193-
callback = M:callback(""),
193+
callback = M.callback(""),
194194
})
195195
vim.api.nvim_create_autocmd({ "InsertLeave", "WinLeave" }, {
196196
group = M.augroup_id,
197197
buffer = 0,
198198
callback = function()
199-
M:clear_composition()
200-
M:win_close()
199+
M.clear_composition()
200+
M.win_close()
201201
end
202202
})
203203
vim.b.rime_is_enabled = true
@@ -206,7 +206,7 @@ end
206206
---disable IME
207207
---@see enable
208208
---@see toggle
209-
function M:disable()
209+
function M.disable()
210210
for _, nowait_key in ipairs(M.keys.nowait) do
211211
vim.keymap.del("i", nowait_key, { buffer = 0 })
212212
end
@@ -218,26 +218,26 @@ end
218218
---toggle IME
219219
---@see enable
220220
---@see disable
221-
function M:toggle()
221+
function M.toggle()
222222
if vim.b.rime_is_enabled then
223-
M:disable()
223+
M.disable()
224224
else
225-
M:enable()
225+
M.enable()
226226
end
227-
M:update_status_bar()
227+
M.update_status_bar()
228228
end
229229

230230
---get context with all candidates, useful for `lua.rime.nvim.cmp`
231231
---@param keys string
232232
---@return table
233-
function M:get_context_with_all_candidates(keys)
234-
M:init()
235-
M:process_keys(keys, {})
233+
function M.get_context_with_all_candidates(keys)
234+
M.init()
235+
M.process_keys(keys, {})
236236
local context = rime.get_context(M.sessionId)
237237
if (keys ~= '') then
238238
local result = context
239239
while (not context.menu.is_last_page) do
240-
M:process_key('=', {})
240+
M.process_key('=', {})
241241
context = rime.get_context(M.sessionId)
242242
result.menu.num_candidates = result.menu.num_candidates + context.menu.num_candidates
243243
if (result.menu.select_keys and context.menu.select_keys) then
@@ -248,7 +248,7 @@ function M:get_context_with_all_candidates(keys)
248248
end
249249
end
250250
end
251-
M:clear_composition()
251+
M.clear_composition()
252252
return context
253253
end
254254

@@ -257,15 +257,15 @@ end
257257
---@param old string
258258
---@param name string
259259
---@return string
260-
function M:get_new_symbol(old, name)
260+
function M.get_new_symbol(old, name)
261261
if old == M.airline_mode_map.i or old == M.airline_mode_map.ic or old == M.airline_mode_map.ix then
262262
return name
263263
end
264264
return old .. name
265265
end
266266

267267
---update status bar by `airline_mode_map`. see `help airline`.
268-
function M:update_status_bar()
268+
function M.update_status_bar()
269269
if vim.g.airline_mode_map then
270270
if M.airline_mode_map == nil then
271271
M.airline_mode_map = vim.tbl_deep_extend("keep", vim.g.airline_mode_map, M.default.airline_mode_map)
@@ -283,7 +283,7 @@ function M:update_status_bar()
283283
if schema.schema_id == schema_id then
284284
for k, _ in pairs(M.default.airline_mode_map) do
285285
vim.g.airline_mode_map = vim.tbl_deep_extend("keep",
286-
{ [k] = M:get_new_symbol(M.airline_mode_map[k], schema.name) }, vim.g.airline_mode_map)
286+
{ [k] = M.get_new_symbol(M.airline_mode_map[k], schema.name) }, vim.g.airline_mode_map)
287287
end
288288
break
289289
end

0 commit comments

Comments
 (0)