blob: ae164e83052f1f5d808a6b78bc43493de15e4465 (
plain) (
tree)
|
|
local utils = {}
local scopes = {o = vim.o, b = vim.bo, w = vim.wo}
--- Apply a setting with a specified scope
function utils.opt(scope, key, value)
scopes[scope][key] = value
if scope ~= 'o' then scopes['o'][key] = value end
end
--- Apply an array of settings
function utils.opts(params)
for i, item in ipairs(params) do
utils.opt(item[1], item[2], item[3])
end
end
--- Key mapping
function utils.map(mode, lhs, rhs, opts)
local options = {noremap = true}
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
function utils.get_python_venv()
local lsputil = require('lspconfig/util')
local match
if vim.env.VIRTUAL_ENV then
return vim.env.VIRTUAL_ENV
end
match = vim.fn.glob(lsputil.path.join(vim.fn.getcwd(), 'Pipfile'))
if match ~= '' then
return vim.fn.trim(vim.fn.system('PIPENV_PIPFILE=' .. match .. ' pipenv --venv'))
end
match = vim.fn.system('test -f poetry.lock && poetry env info -p')
if vim.v.shell_error then
return vim.fn.trim(match)
end
return ''
end
return utils
|