mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-23 17:49:57 +08:00
perf(flygrep): use noautocmd to open flygrep windows
This commit is contained in:
parent
af78a5f0db
commit
7a6ffd9524
@ -30,6 +30,14 @@ end
|
|||||||
local function isdirectory(dir)
|
local function isdirectory(dir)
|
||||||
return vim.fn.isdirectory(dir) == 1
|
return vim.fn.isdirectory(dir) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function noautocmd(f) -- {{{
|
||||||
|
local ei = vim.o.eventignore
|
||||||
|
vim.o.eventignore = 'all'
|
||||||
|
pcall(f)
|
||||||
|
vim.o.eventignore = ei
|
||||||
|
end
|
||||||
|
-- }}}
|
||||||
local timer_start = vim.fn.timer_start
|
local timer_start = vim.fn.timer_start
|
||||||
local timer_stop = vim.fn.timer_stop
|
local timer_stop = vim.fn.timer_stop
|
||||||
|
|
||||||
@ -291,13 +299,15 @@ local function preview_timer(_)
|
|||||||
end
|
end
|
||||||
local flygrep_win_height = 16
|
local flygrep_win_height = 16
|
||||||
if not window.is_float(preview_win_id) then
|
if not window.is_float(preview_win_id) then
|
||||||
preview_win_id = vim.api.nvim_open_win(preview_bufnr, false, {
|
noautocmd(function()
|
||||||
relative = 'editor',
|
preview_win_id = vim.api.nvim_open_win(preview_bufnr, false, {
|
||||||
width = vim.o.columns,
|
relative = 'editor',
|
||||||
height = 8,
|
width = vim.o.columns,
|
||||||
row = vim.o.lines - flygrep_win_height - 2 - 8,
|
height = 8,
|
||||||
col = 0,
|
row = vim.o.lines - flygrep_win_height - 2 - 8,
|
||||||
})
|
col = 0,
|
||||||
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
vim.api.nvim_buf_set_lines(preview_bufnr, 0, -1, false, vim.fn.readfile(filename, ''))
|
vim.api.nvim_buf_set_lines(preview_bufnr, 0, -1, false, vim.fn.readfile(filename, ''))
|
||||||
local ft = vim.filetype.match({ filename = filename })
|
local ft = vim.filetype.match({ filename = filename })
|
||||||
@ -307,11 +317,13 @@ local function preview_timer(_)
|
|||||||
local ftdetect_autocmd = vim.api.nvim_get_autocmds({
|
local ftdetect_autocmd = vim.api.nvim_get_autocmds({
|
||||||
group = 'filetypedetect',
|
group = 'filetypedetect',
|
||||||
event = 'BufRead',
|
event = 'BufRead',
|
||||||
pattern = '*.' .. vim.fn.fnamemodify(filename, ':e')
|
pattern = '*.' .. vim.fn.fnamemodify(filename, ':e'),
|
||||||
})
|
})
|
||||||
-- logger.info(vim.inspect(ftdetect_autocmd))
|
-- logger.info(vim.inspect(ftdetect_autocmd))
|
||||||
if ftdetect_autocmd[1] then
|
if ftdetect_autocmd[1] then
|
||||||
if ftdetect_autocmd[1].command and vim.startswith(ftdetect_autocmd[1].command, 'set filetype=') then
|
if
|
||||||
|
ftdetect_autocmd[1].command and vim.startswith(ftdetect_autocmd[1].command, 'set filetype=')
|
||||||
|
then
|
||||||
ft = ftdetect_autocmd[1].command:gsub('set filetype=', '')
|
ft = ftdetect_autocmd[1].command:gsub('set filetype=', '')
|
||||||
vim.api.nvim_buf_set_option(preview_bufnr, 'syntax', ft)
|
vim.api.nvim_buf_set_option(preview_bufnr, 'syntax', ft)
|
||||||
end
|
end
|
||||||
@ -740,13 +752,15 @@ function M.open(argv)
|
|||||||
mpt._handle_fly = flygrep
|
mpt._handle_fly = flygrep
|
||||||
buffer_id = vim.api.nvim_create_buf(false, true)
|
buffer_id = vim.api.nvim_create_buf(false, true)
|
||||||
local flygrep_win_height = 16
|
local flygrep_win_height = 16
|
||||||
flygrep_win_id = vim.api.nvim_open_win(buffer_id, true, {
|
noautocmd(function()
|
||||||
relative = 'editor',
|
flygrep_win_id = vim.api.nvim_open_win(buffer_id, true, {
|
||||||
width = vim.o.columns,
|
relative = 'editor',
|
||||||
height = flygrep_win_height,
|
width = vim.o.columns,
|
||||||
row = vim.o.lines - flygrep_win_height - 2,
|
height = flygrep_win_height,
|
||||||
col = 0,
|
row = vim.o.lines - flygrep_win_height - 2,
|
||||||
})
|
col = 0,
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
if vim.fn.exists('&winhighlight') == 1 then
|
if vim.fn.exists('&winhighlight') == 1 then
|
||||||
vim.cmd('set winhighlight=Normal:Pmenu,EndOfBuffer:Pmenu,CursorLine:PmenuSel')
|
vim.cmd('set winhighlight=Normal:Pmenu,EndOfBuffer:Pmenu,CursorLine:PmenuSel')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user