Skip to content

Commit

Permalink
Enable abbreviations in the cmdline window.
Browse files Browse the repository at this point in the history
Doesn't get all the way there for e.g. /, but at least
gives one simple way to search with abbreviation support.

See :h q/ if you haven't previously used the cmdline window.

Ref: #205
  • Loading branch information
Julian committed Aug 29, 2022
1 parent e0a647c commit 71aac94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lua/lean/abbreviations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ function abbreviations._insert_char_pre()
end
end

function abbreviations._cmdwin_enter()
local came_from = vim.fn.win_getid(vim.fn.winnr('#'))
local ft = vim.api.nvim_get_option_value('filetype', { win = came_from })
if not ft:match('^lean*') then
set_augroup('LeanAbbreviationCmdwin', '')
return
end
set_augroup('LeanAbbreviationCmdwin', [[
autocmd InsertCharPre <buffer> lua require'lean.abbreviations'._insert_char_pre()
autocmd InsertLeave <buffer> lua require'lean.abbreviations'.convert()
autocmd BufLeave <buffer> lua require'lean.abbreviations'.convert()
]])
end

function abbreviations._cmdwin_leave()
set_augroup('LeanAbbreviationCmdwin', '')
end

local function convert_abbrev(abbrev)
if abbrev:find(abbreviations.leader) ~= 1 then return abbrev end
abbrev = abbrev:sub(#abbreviations.leader + 1)
Expand Down Expand Up @@ -219,6 +237,8 @@ function abbreviations.enable(opts)
set_augroup("LeanAbbreviations", [[
autocmd InsertCharPre *.lean lua require'lean.abbreviations'._insert_char_pre()
autocmd InsertLeave *.lean lua require'lean.abbreviations'.convert()
autocmd CmdwinEnter * lua require'lean.abbreviations'._cmdwin_enter()
autocmd CmdwinLeave * lua require'lean.abbreviations'._cmdwin_leave()
autocmd BufLeave *.lean lua require'lean.abbreviations'.convert()
]])
vim.cmd[[hi def leanAbbreviationMark cterm=underline gui=underline guisp=Gray]]
Expand Down
7 changes: 7 additions & 0 deletions lua/tests/abbreviations/abbreviations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ describe('unicode abbreviation expansion', function()
helpers.insert[[(\a]]
assert.contents.are[[]]
end))

it('expands abbreviations in command mode', helpers.clean_buffer(ft, '', function()
helpers.insert[[foo ε bar]]
vim.cmd('normal $')
helpers.feed[[q/a\e<Space><CR>ibaz]]
assert.is.equal('foo bazε bar', vim.api.nvim_get_current_line())
end))
end)
end)

Expand Down

0 comments on commit 71aac94

Please sign in to comment.