1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

refactor: local fn = vim.fn

This commit is contained in:
jdhao 2022-05-15 21:16:02 +08:00
parent 424981683e
commit 4899a82b35
4 changed files with 23 additions and 18 deletions

View File

@ -1,3 +1,4 @@
local fn = vim.fn
local api = vim.api local api = vim.api
local lsp = vim.lsp local lsp = vim.lsp
@ -135,9 +136,9 @@ if utils.executable('bash-language-server') then
}) })
end end
local sumneko_binary_path = vim.fn.exepath("lua-language-server") local sumneko_binary_path = fn.exepath("lua-language-server")
if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then
local sumneko_root_path = vim.fn.fnamemodify(sumneko_binary_path, ":h:h:h") local sumneko_root_path = fn.fnamemodify(sumneko_binary_path, ":h:h:h")
local runtime_path = vim.split(package.path, ";") local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?.lua")
@ -173,10 +174,10 @@ if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then
end end
-- Change diagnostic signs. -- Change diagnostic signs.
vim.fn.sign_define("DiagnosticSignError", { text = "", texthl = "DiagnosticSignError" }) fn.sign_define("DiagnosticSignError", { text = "", texthl = "DiagnosticSignError" })
vim.fn.sign_define("DiagnosticSignWarn", { text = "!", texthl = "DiagnosticSignWarn" }) fn.sign_define("DiagnosticSignWarn", { text = "!", texthl = "DiagnosticSignWarn" })
vim.fn.sign_define("DiagnosticSignInformation", { text = "", texthl = "DiagnosticSignInfo" }) fn.sign_define("DiagnosticSignInformation", { text = "", texthl = "DiagnosticSignInfo" })
vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
-- global config for diagnostic -- global config for diagnostic
vim.diagnostic.config({ vim.diagnostic.config({

View File

@ -1,3 +1,5 @@
local fn = vim.fn
local function spell() local function spell()
if vim.o.spell then if vim.o.spell then
return string.format("[SPELL]") return string.format("[SPELL]")
@ -9,7 +11,7 @@ end
local function ime_state() local function ime_state()
if vim.g.is_mac then if vim.g.is_mac then
-- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11 -- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11
local layout = vim.fn.libcall(vim.g.XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '') local layout = fn.libcall(vim.g.XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '')
if layout == '0' then if layout == '0' then
return '[CN]' return '[CN]'
end end
@ -35,20 +37,20 @@ end
local function mixed_indent() local function mixed_indent()
local space_pat = [[\v^ +]] local space_pat = [[\v^ +]]
local tab_pat = [[\v^\t+]] local tab_pat = [[\v^\t+]]
local space_indent = vim.fn.search(space_pat, 'nwc') local space_indent = fn.search(space_pat, 'nwc')
local tab_indent = vim.fn.search(tab_pat, 'nwc') local tab_indent = fn.search(tab_pat, 'nwc')
local mixed = (space_indent > 0 and tab_indent > 0) local mixed = (space_indent > 0 and tab_indent > 0)
local mixed_same_line local mixed_same_line
if not mixed then if not mixed then
mixed_same_line = vim.fn.search([[\v^(\t+ | +\t)]], 'nwc') mixed_same_line = fn.search([[\v^(\t+ | +\t)]], 'nwc')
mixed = mixed_same_line > 0 mixed = mixed_same_line > 0
end end
if not mixed then return '' end if not mixed then return '' end
if mixed_same_line ~= nil and mixed_same_line > 0 then if mixed_same_line ~= nil and mixed_same_line > 0 then
return 'MI:'..mixed_same_line return 'MI:'..mixed_same_line
end end
local space_indent_cnt = vim.fn.searchcount({pattern=space_pat, max_count=1e3}).total local space_indent_cnt = fn.searchcount({pattern=space_pat, max_count=1e3}).total
local tab_indent_cnt = vim.fn.searchcount({pattern=tab_pat, max_count=1e3}).total local tab_indent_cnt = fn.searchcount({pattern=tab_pat, max_count=1e3}).total
if space_indent_cnt > tab_indent_cnt then if space_indent_cnt > tab_indent_cnt then
return 'MI:'..tab_indent return 'MI:'..tab_indent
else else

View File

@ -359,7 +359,7 @@ require("packer").startup({
end, end,
config = { config = {
max_jobs = 16, max_jobs = 16,
compile_path = util.join_paths(vim.fn.stdpath('data'), 'site', 'lua', 'packer_compiled.lua'), compile_path = util.join_paths(fn.stdpath('data'), 'site', 'lua', 'packer_compiled.lua'),
}, },
}) })

View File

@ -1,3 +1,5 @@
local fn = vim.fn
-- inspect something -- inspect something
function inspect(item) function inspect(item)
vim.pretty_print(item) vim.pretty_print(item)
@ -6,7 +8,7 @@ end
local M = {} local M = {}
function M.executable(name) function M.executable(name)
if vim.fn.executable(name) > 0 then if fn.executable(name) > 0 then
return true return true
end end
@ -14,12 +16,12 @@ function M.executable(name)
end end
function M.may_create_dir() function M.may_create_dir()
local fpath = vim.fn.expand('<afile>') local fpath = fn.expand('<afile>')
local parent_dir = vim.fn.fnamemodify(fpath, ":p:h") local parent_dir = fn.fnamemodify(fpath, ":p:h")
local res = vim.fn.isdirectory(parent_dir) local res = fn.isdirectory(parent_dir)
if res == 0 then if res == 0 then
vim.fn.mkdir(parent_dir, 'p') fn.mkdir(parent_dir, 'p')
end end
end end