Skip to content

Commit 10b1cf2

Browse files
committed
fix(cmdline): do not autocorrect Command-line abbreviations
1 parent 121d830 commit 10b1cf2

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

doc/mini-cmdline.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ Notes:
205205
the lowest string distance.
206206
See |MiniCmdline.default_autocorrect_func()| for details.
207207

208+
- Word that matches some Command-line |abbreviation| is not autocorrected.
209+
208210
- If current command expects only a single argument (like |:colorscheme|), then
209211
autocorrection will happen only just before executing the command.
210212

lua/mini/cmdline.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ end
179179
--- the lowest string distance.
180180
--- See |MiniCmdline.default_autocorrect_func()| for details.
181181
---
182+
--- - Word that matches some Command-line |abbreviation| is not autocorrected.
183+
---
182184
--- - If current command expects only a single argument (like |:colorscheme|), then
183185
--- autocorrection will happen only just before executing the command.
184186
---
@@ -738,7 +740,7 @@ H.autocorrect = function(is_final)
738740
-- Compute autocorrection
739741
local state_to_use = is_final and state or state_prev
740742
local word = state_to_use.complpat
741-
if word == '' then return end
743+
if word == '' or vim.fn.maparg(word, 'c', true) ~= '' then return end
742744

743745
local func = H.cache.config.autocorrect.func or MiniCmdline.default_autocorrect_func
744746
local new_word = func({ word = word, type = state_to_use.compltype }) or word

tests/test_cmdline.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,30 @@ T['Autocorrect']['respects mappings'] = function()
840840
eq(child.fn.histget('cmd', -1), 'echo')
841841
end
842842

843+
T['Autocorrect']['respects abbreviations'] = function()
844+
child.lua([[
845+
_G.log = {}
846+
local orig = MiniCmdline.default_autocorrect_func
847+
MiniCmdline.default_autocorrect_func = function(...)
848+
table.insert(_G.log, vim.deepcopy({ ... }))
849+
return orig(...)
850+
end
851+
]])
852+
853+
child.cmd('cabbrev Y wincmd')
854+
child.cmd('cnoreabbrev <buffer> D bwipeout')
855+
856+
type_keys(':', 'Y', ' ')
857+
validate_cmdline('wincmd ')
858+
type_keys('<Esc>')
859+
860+
type_keys(':', 'D', '<CR>')
861+
eq(child.fn.histget('cmd', -1), 'bwipeout')
862+
863+
-- Should not call `config.autocorrect.func` for abbreviations
864+
eq(child.lua_get('_G.log'), {})
865+
end
866+
843867
T['Autocorrect']['can act after mappings appended text'] = function()
844868
-- Should act if text increases latest word
845869
child.cmd('cnoremap <C-x> www')

0 commit comments

Comments
 (0)