chore: use stylua for formatting (#1040)

* chore: stylua job and config

* reformat with stylua
This commit is contained in:
Simon Hauser
2021-07-23 17:42:37 +02:00
committed by GitHub
parent 664690029f
commit 79644ab677
75 changed files with 3201 additions and 2809 deletions

View File

@@ -1,15 +1,15 @@
local actions = require('telescope.actions')
local action_set = require('telescope.actions.set')
local action_state = require('telescope.actions.state')
local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local Path = require('plenary.path')
local pickers = require('telescope.pickers')
local previewers = require('telescope.previewers')
local sorters = require('telescope.sorters')
local utils = require('telescope.utils')
local actions = require "telescope.actions"
local action_set = require "telescope.actions.set"
local action_state = require "telescope.actions.state"
local finders = require "telescope.finders"
local make_entry = require "telescope.make_entry"
local Path = require "plenary.path"
local pickers = require "telescope.pickers"
local previewers = require "telescope.previewers"
local sorters = require "telescope.sorters"
local utils = require "telescope.utils"
local conf = require('telescope.config').values
local conf = require("telescope.config").values
local filter = vim.tbl_filter
@@ -25,7 +25,7 @@ internal.builtin = function(opts)
local objs = {}
for k, v in pairs(require'telescope.builtin') do
for k, v in pairs(require "telescope.builtin") do
local debug_info = debug.getinfo(v)
table.insert(objs, {
filename = string.sub(debug_info.source, 2),
@@ -33,11 +33,11 @@ internal.builtin = function(opts)
})
end
local title = 'Telescope Builtin'
local title = "Telescope Builtin"
if opts.include_extensions then
title = 'Telescope Pickers'
for ext, funcs in pairs(require'telescope'.extensions) do
title = "Telescope Pickers"
for ext, funcs in pairs(require("telescope").extensions) do
for func_name, func_obj in pairs(funcs) do
local debug_info = debug.getinfo(func_obj)
table.insert(objs, {
@@ -50,7 +50,7 @@ internal.builtin = function(opts)
pickers.new(opts, {
prompt_title = title,
finder = finders.new_table {
finder = finders.new_table {
results = objs,
entry_maker = function(entry)
return {
@@ -58,44 +58,44 @@ internal.builtin = function(opts)
text = entry.text,
display = entry.text,
ordinal = entry.text,
filename = entry.filename
filename = entry.filename,
}
end
end,
},
previewer = previewers.builtin.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(_)
actions.select_default:replace(actions.run_builtin)
return true
end
end,
}):find()
end
internal.planets = function(opts)
local show_pluto = opts.show_pluto or false
local sourced_file = require('plenary.debug_utils').sourced_filepath()
local sourced_file = require("plenary.debug_utils").sourced_filepath()
local base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h:h")
local globbed_files = vim.fn.globpath(base_directory .. '/data/memes/planets/', '*', true, true)
local globbed_files = vim.fn.globpath(base_directory .. "/data/memes/planets/", "*", true, true)
local acceptable_files = {}
for _, v in ipairs(globbed_files) do
if show_pluto or not v:find("pluto") then
table.insert(acceptable_files,vim.fn.fnamemodify(v, ':t'))
if show_pluto or not v:find "pluto" then
table.insert(acceptable_files, vim.fn.fnamemodify(v, ":t"))
end
end
pickers.new {
prompt_title = 'Planets',
pickers.new({
prompt_title = "Planets",
finder = finders.new_table {
results = acceptable_files,
entry_maker = function(line)
return {
ordinal = line,
display = line,
filename = base_directory .. '/data/memes/planets/' .. line,
filename = base_directory .. "/data/memes/planets/" .. line,
}
end
end,
},
previewer = previewers.cat.new(opts),
sorter = conf.generic_sorter(opts),
@@ -109,14 +109,16 @@ internal.planets = function(opts)
return true
end,
}:find()
}):find()
end
internal.symbols = function(opts)
local files = vim.api.nvim_get_runtime_file('data/telescope-sources/*.json', true)
local files = vim.api.nvim_get_runtime_file("data/telescope-sources/*.json", true)
if table.getn(files) == 0 then
print("No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim " ..
"for some prebuild symbols or how to create you own symbol source.")
print(
"No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim "
.. "for some prebuild symbols or how to create you own symbol source."
)
return
end
@@ -142,31 +144,31 @@ internal.symbols = function(opts)
end
pickers.new(opts, {
prompt_title = 'Symbols',
finder = finders.new_table {
results = results,
prompt_title = "Symbols",
finder = finders.new_table {
results = results,
entry_maker = function(entry)
return {
value = entry,
ordinal = entry[1] .. ' ' .. entry[2],
display = entry[1] .. ' ' .. entry[2],
ordinal = entry[1] .. " " .. entry[2],
display = entry[1] .. " " .. entry[2],
}
end
end,
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(_)
actions.select_default:replace(actions.insert_symbol)
return true
end
end,
}):find()
end
internal.commands = function(opts)
pickers.new(opts, {
prompt_title = 'Commands',
prompt_title = "Commands",
finder = finders.new_table {
results = (function()
local command_iter = vim.api.nvim_get_commands({})
local command_iter = vim.api.nvim_get_commands {}
local commands = {}
for _, cmd in pairs(command_iter) do
@@ -195,7 +197,7 @@ internal.commands = function(opts)
end)
return true
end
end,
}):find()
end
@@ -207,9 +209,9 @@ internal.quickfix = function(opts)
end
pickers.new(opts, {
prompt_title = 'Quickfix',
finder = finders.new_table {
results = locations,
prompt_title = "Quickfix",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts),
},
previewer = conf.qflist_previewer(opts),
@@ -230,9 +232,9 @@ internal.loclist = function(opts)
end
pickers.new(opts, {
prompt_title = 'Loclist',
finder = finders.new_table {
results = locations,
prompt_title = "Loclist",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts),
},
previewer = conf.qflist_previewer(opts),
@@ -248,8 +250,8 @@ internal.oldfiles = function(opts)
local results = {}
if opts.include_current_session then
for _, buffer in ipairs(vim.split(vim.fn.execute(':buffers! t'), "\n")) do
local match = tonumber(string.match(buffer, '%s*(%d+)'))
for _, buffer in ipairs(vim.split(vim.fn.execute ":buffers! t", "\n")) do
local match = tonumber(string.match(buffer, "%s*(%d+)"))
if match then
local file = vim.api.nvim_buf_get_name(match)
if vim.loop.fs_stat(file) and match ~= current_buffer then
@@ -267,15 +269,15 @@ internal.oldfiles = function(opts)
if opts.cwd_only then
local cwd = vim.loop.cwd()
cwd = cwd:gsub([[\]],[[\\]])
cwd = cwd:gsub([[\]], [[\\]])
results = vim.tbl_filter(function(file)
return vim.fn.matchstrpos(file, cwd)[2] ~= -1
end, results)
end
pickers.new(opts, {
prompt_title = 'Oldfiles',
finder = finders.new_table{
prompt_title = "Oldfiles",
finder = finders.new_table {
results = results,
entry_maker = opts.entry_maker or make_entry.gen_from_file(opts),
},
@@ -285,7 +287,7 @@ internal.oldfiles = function(opts)
end
internal.command_history = function(opts)
local history_string = vim.fn.execute('history cmd')
local history_string = vim.fn.execute "history cmd"
local history_list = vim.split(history_string, "\n")
local results = {}
@@ -296,15 +298,15 @@ internal.command_history = function(opts)
end
pickers.new(opts, {
prompt_title = 'Command History',
prompt_title = "Command History",
finder = finders.new_table(results),
sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map)
map('i', '<CR>', actions.set_command_line)
map('n', '<CR>', actions.set_command_line)
map('n', '<C-e>', actions.edit_command_line)
map('i', '<C-e>', actions.edit_command_line)
map("i", "<CR>", actions.set_command_line)
map("n", "<CR>", actions.set_command_line)
map("n", "<C-e>", actions.edit_command_line)
map("i", "<C-e>", actions.edit_command_line)
-- TODO: Find a way to insert the text... it seems hard.
-- map('i', '<C-i>', actions.insert_value, { expr = true })
@@ -315,7 +317,7 @@ internal.command_history = function(opts)
end
internal.search_history = function(opts)
local search_string = vim.fn.execute('history search')
local search_string = vim.fn.execute "history search"
local search_list = vim.split(search_string, "\n")
local results = {}
@@ -326,15 +328,15 @@ internal.search_history = function(opts)
end
pickers.new(opts, {
prompt_title = 'Search History',
prompt_title = "Search History",
finder = finders.new_table(results),
sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map)
map('i', '<CR>', actions.set_search_line)
map('n', '<CR>', actions.set_search_line)
map('n', '<C-e>', actions.edit_search_line)
map('i', '<C-e>', actions.edit_search_line)
map("i", "<CR>", actions.set_search_line)
map("n", "<CR>", actions.set_search_line)
map("n", "<C-e>", actions.edit_search_line)
map("i", "<C-e>", actions.edit_search_line)
-- TODO: Find a way to insert the text... it seems hard.
-- map('i', '<C-i>', actions.insert_value, { expr = true })
@@ -346,12 +348,10 @@ end
internal.vim_options = function(opts)
-- Load vim options.
local vim_opts = loadfile(
Path:new({utils.data_directory(), 'options', 'options.lua'}):absolute()
)().options
local vim_opts = loadfile(Path:new({ utils.data_directory(), "options", "options.lua" }):absolute())().options
pickers.new(opts, {
prompt_title = 'options',
prompt_title = "options",
finder = finders.new_table {
results = vim_opts,
entry_maker = opts.entry_maker or make_entry.gen_from_vimoptions(opts),
@@ -403,7 +403,7 @@ internal.vim_options = function(opts)
end)
return true
end
end,
}):find()
end
@@ -411,9 +411,9 @@ internal.help_tags = function(opts)
opts.lang = utils.get_default(opts.lang, vim.o.helplang)
opts.fallback = utils.get_default(opts.fallback, true)
local langs = vim.split(opts.lang, ',', true)
if opts.fallback and not vim.tbl_contains(langs, 'en') then
table.insert(langs, 'en')
local langs = vim.split(opts.lang, ",", true)
if opts.fallback and not vim.tbl_contains(langs, "en") then
table.insert(langs, "en")
end
local langs_map = {}
for _, lang in ipairs(langs) do
@@ -426,18 +426,18 @@ internal.help_tags = function(opts)
if tag_files[lang] then
table.insert(tag_files[lang], file)
else
tag_files[lang] = {file}
tag_files[lang] = { file }
end
end
end
local help_files = {}
local all_files = vim.fn.globpath(vim.o.runtimepath, 'doc/*', 1, 1)
local all_files = vim.fn.globpath(vim.o.runtimepath, "doc/*", 1, 1)
for _, fullpath in ipairs(all_files) do
local file = utils.path_tail(fullpath)
if file == 'tags' then
add_tag_file('en', fullpath)
elseif file:match('^tags%-..$') then
if file == "tags" then
add_tag_file("en", fullpath)
elseif file:match "^tags%-..$" then
local lang = file:sub(-2)
add_tag_file(lang, fullpath)
else
@@ -450,10 +450,10 @@ internal.help_tags = function(opts)
local delimiter = string.char(9)
for _, lang in ipairs(langs) do
for _, file in ipairs(tag_files[lang] or {}) do
local lines = vim.split(Path:new(file):read(), '\n', true)
local lines = vim.split(Path:new(file):read(), "\n", true)
for _, line in ipairs(lines) do
-- TODO: also ignore tagComment starting with ';'
if not line:match'^!_TAG_' then
if not line:match "^!_TAG_" then
local fields = vim.split(line, delimiter, true)
if #fields == 3 and not tags_map[fields[1]] then
table.insert(tags, {
@@ -470,16 +470,16 @@ internal.help_tags = function(opts)
end
pickers.new(opts, {
prompt_title = 'Help',
prompt_title = "Help",
finder = finders.new_table {
results = tags,
entry_maker = function(entry)
return {
value = entry.name .. '@' .. entry.lang,
value = entry.name .. "@" .. entry.lang,
display = entry.name,
ordinal = entry.name,
filename = entry.filename,
cmd = entry.cmd
cmd = entry.cmd,
}
end,
},
@@ -489,51 +489,51 @@ internal.help_tags = function(opts)
action_set.select:replace(function(_, cmd)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
if cmd == 'default' or cmd == 'horizontal' then
vim.cmd('help ' .. selection.value)
elseif cmd == 'vertical' then
vim.cmd('vert bo help ' .. selection.value)
elseif cmd == 'tab' then
vim.cmd('tab help ' .. selection.value)
if cmd == "default" or cmd == "horizontal" then
vim.cmd("help " .. selection.value)
elseif cmd == "vertical" then
vim.cmd("vert bo help " .. selection.value)
elseif cmd == "tab" then
vim.cmd("tab help " .. selection.value)
end
end)
return true
end
end,
}):find()
end
internal.man_pages = function(opts)
opts.sections = utils.get_default(opts.sections, {'1'})
assert(vim.tbl_islist(opts.sections), 'sections should be a list')
opts.sections = utils.get_default(opts.sections, { "1" })
assert(vim.tbl_islist(opts.sections), "sections should be a list")
opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function()
local is_darwin = vim.loop.os_uname().sysname == 'Darwin'
return is_darwin and {'apropos', ' '} or {'apropos', ''}
local is_darwin = vim.loop.os_uname().sysname == "Darwin"
return is_darwin and { "apropos", " " } or { "apropos", "" }
end)
opts.entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts)
pickers.new(opts, {
prompt_title = 'Man',
finder = finders.new_oneshot_job(opts.man_cmd, opts),
prompt_title = "Man",
finder = finders.new_oneshot_job(opts.man_cmd, opts),
previewer = previewers.man.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
action_set.select:replace(function(_, cmd)
local selection = action_state.get_selected_entry()
local args = selection.section .. ' ' .. selection.value
local args = selection.section .. " " .. selection.value
actions.close(prompt_bufnr)
if cmd == 'default' or cmd == 'horizontal' then
vim.cmd('Man ' .. args)
elseif cmd == 'vertical' then
vim.cmd('vert bo Man ' .. args)
elseif cmd == 'tab' then
vim.cmd('tab Man ' .. args)
if cmd == "default" or cmd == "horizontal" then
vim.cmd("Man " .. args)
elseif cmd == "vertical" then
vim.cmd("vert bo Man " .. args)
elseif cmd == "tab" then
vim.cmd("tab Man " .. args)
end
end)
return true
end
end,
}):find()
end
@@ -543,9 +543,11 @@ internal.reloader = function(opts)
-- filter out packages we don't want and track the longest package name
opts.column_len = 0
for index, module_name in pairs(package_list) do
if type(require(module_name)) ~= 'table' or
module_name:sub(1,1) == "_" or
package.searchpath(module_name, package.path) == nil then
if
type(require(module_name)) ~= "table"
or module_name:sub(1, 1) == "_"
or package.searchpath(module_name, package.path) == nil
then
table.remove(package_list, index)
elseif #module_name > opts.column_len then
opts.column_len = #module_name
@@ -553,7 +555,7 @@ internal.reloader = function(opts)
end
pickers.new(opts, {
prompt_title = 'Packages',
prompt_title = "Packages",
finder = finders.new_table {
results = package_list,
entry_maker = opts.entry_maker or make_entry.gen_from_packages(opts),
@@ -566,19 +568,19 @@ internal.reloader = function(opts)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
require('plenary.reload').reload_module(selection.value)
require("plenary.reload").reload_module(selection.value)
print(string.format("[%s] - module reloaded", selection.value))
end)
return true
end
end,
}):find()
end
internal.buffers = function(opts)
local bufnrs = filter(function(b)
if 1 ~= vim.fn.buflisted(b) then
return false
return false
end
-- only hide unloaded buffers if opts.show_all_buffers is false, keep them listed if true or nil
if opts.show_all_buffers == false and not vim.api.nvim_buf_is_loaded(b) then
@@ -592,7 +594,9 @@ internal.buffers = function(opts)
end
return true
end, vim.api.nvim_list_bufs())
if not next(bufnrs) then return end
if not next(bufnrs) then
return
end
if opts.sort_mru then
table.sort(bufnrs, function(a, b)
return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused
@@ -602,7 +606,7 @@ internal.buffers = function(opts)
local buffers = {}
local default_selection_idx = 1
for _, bufnr in ipairs(bufnrs) do
local flag = bufnr == vim.fn.bufnr('') and '%' or (bufnr == vim.fn.bufnr('#') and '#' or ' ')
local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ")
if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then
default_selection_idx = 2
@@ -628,10 +632,10 @@ internal.buffers = function(opts)
end
pickers.new(opts, {
prompt_title = 'Buffers',
finder = finders.new_table {
prompt_title = "Buffers",
finder = finders.new_table {
results = buffers,
entry_maker = opts.entry_maker or make_entry.gen_from_buffer(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_buffer(opts),
},
previewer = conf.grep_previewer(opts),
sorter = conf.generic_sorter(opts),
@@ -640,7 +644,7 @@ internal.buffers = function(opts)
end
internal.colorscheme = function(opts)
local before_color = vim.api.nvim_exec('colorscheme', true)
local before_color = vim.api.nvim_exec("colorscheme", true)
local need_restore = true
local colors = opts.colors or { before_color }
@@ -652,10 +656,7 @@ internal.colorscheme = function(opts)
colors,
vim.tbl_filter(function(color)
return color ~= before_color
end, vim.fn.getcompletion(
'',
'color'
))
end, vim.fn.getcompletion("", "color"))
)
local previewer
@@ -681,7 +682,7 @@ internal.colorscheme = function(opts)
del_win(status.preview_win)
del_win(status.preview_border_win)
end
vim.cmd('colorscheme ' .. entry.value)
vim.cmd("colorscheme " .. entry.value)
end,
}
else
@@ -697,14 +698,14 @@ internal.colorscheme = function(opts)
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
end
vim.cmd('colorscheme ' .. entry.value)
vim.cmd("colorscheme " .. entry.value)
end,
}
end
end
local picker = pickers.new(opts, {
prompt_title = 'Change Colorscheme',
prompt_title = "Change Colorscheme",
finder = finders.new_table {
results = colors,
},
@@ -716,7 +717,7 @@ internal.colorscheme = function(opts)
actions.close(prompt_bufnr)
need_restore = false
vim.cmd('colorscheme ' .. selection.value)
vim.cmd("colorscheme " .. selection.value)
end)
return true
@@ -729,7 +730,7 @@ internal.colorscheme = function(opts)
picker.close_windows = function(status)
close_windows(status)
if need_restore then
vim.cmd('colorscheme ' .. before_color)
vim.cmd("colorscheme " .. before_color)
end
end
end
@@ -744,8 +745,8 @@ internal.marks = function(opts)
-- Pop off the header.
table.remove(marks_table, 1)
pickers.new(opts,{
prompt_title = 'Marks',
pickers.new(opts, {
prompt_title = "Marks",
finder = finders.new_table {
results = marks_table,
entry_maker = opts.entry_maker or make_entry.gen_from_marks(opts),
@@ -756,7 +757,7 @@ internal.marks = function(opts)
end
internal.registers = function(opts)
local registers_table = {"\"", "_", "#", "=", "_", "/", "*", "+", ":", ".", "%"}
local registers_table = { '"', "_", "#", "=", "_", "/", "*", "+", ":", ".", "%" }
-- named
for i = 0, 9 do
@@ -768,8 +769,8 @@ internal.registers = function(opts)
table.insert(registers_table, string.char(i))
end
pickers.new(opts,{
prompt_title = 'Registers',
pickers.new(opts, {
prompt_title = "Registers",
finder = finders.new_table {
results = registers_table,
entry_maker = opts.entry_maker or make_entry.gen_from_registers(opts),
@@ -778,7 +779,7 @@ internal.registers = function(opts)
sorter = sorters.get_levenshtein_sorter(),
attach_mappings = function(_, map)
actions.select_default:replace(actions.paste_register)
map('i', '<C-e>', actions.edit_register)
map("i", "<C-e>", actions.edit_register)
return true
end,
@@ -787,7 +788,7 @@ end
-- TODO: make filtering include the mapping and the action
internal.keymaps = function(opts)
local modes = {"n", "i", "c"}
local modes = { "n", "i", "c" }
local keymaps_table = {}
for _, mode in pairs(modes) do
@@ -802,7 +803,7 @@ internal.keymaps = function(opts)
end
pickers.new(opts, {
prompt_title = 'Key Maps',
prompt_title = "Key Maps",
finder = finders.new_table {
results = keymaps_table,
entry_maker = function(line)
@@ -810,29 +811,27 @@ internal.keymaps = function(opts)
valid = line ~= "",
value = line,
ordinal = utils.display_termcodes(line.lhs) .. line.rhs,
display = line.mode .. ' ' .. utils.display_termcodes(line.lhs) .. ' ' .. line.rhs
display = line.mode .. " " .. utils.display_termcodes(line.lhs) .. " " .. line.rhs,
}
end
end,
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true),
"t", true)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true), "t", true)
return actions.close(prompt_bufnr)
end)
return true
end
end,
}):find()
end
internal.filetypes = function(opts)
local filetypes = vim.fn.getcompletion('', 'filetype')
local filetypes = vim.fn.getcompletion("", "filetype")
pickers.new(opts, {
prompt_title = 'Filetypes',
prompt_title = "Filetypes",
finder = finders.new_table {
results = filetypes,
},
@@ -841,28 +840,28 @@ internal.filetypes = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('setfiletype ' .. selection[1])
vim.cmd("setfiletype " .. selection[1])
end)
return true
end
end,
}):find()
end
internal.highlights = function(opts)
local highlights = vim.fn.getcompletion('', 'highlight')
local highlights = vim.fn.getcompletion("", "highlight")
pickers.new(opts, {
prompt_title = 'Highlights',
prompt_title = "Highlights",
finder = finders.new_table {
results = highlights,
entry_maker = opts.entry_maker or make_entry.gen_from_highlights(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_highlights(opts),
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('hi ' .. selection.value)
vim.cmd("hi " .. selection.value)
end)
return true
end,
@@ -873,10 +872,10 @@ end
internal.autocommands = function(opts)
local autocmd_table = {}
local pattern = {}
local pattern = {}
pattern.BUFFER = "<buffer=%d+>"
pattern.EVENT = "[%a]+"
pattern.GROUP = "[%a%d_:]+"
pattern.EVENT = "[%a]+"
pattern.GROUP = "[%a%d_:]+"
pattern.INDENT = "^%s%s%s%s" -- match indentation of 4 spaces
local event, group, ft_pat, cmd, source_file, source_lnum
@@ -902,7 +901,7 @@ internal.autocommands = function(opts)
-- non event/group lines
ft_pat = line:match(pattern.INDENT .. "(%S+)")
if ft_pat then
if ft_pat:match("^%d+") then
if ft_pat:match "^%d+" then
ft_pat = "<buffer=" .. ft_pat .. ">"
end
current_ft = ft_pat
@@ -920,13 +919,13 @@ internal.autocommands = function(opts)
end
if current_ft and cmd then
source_file, source_lnum = line:match("Last set from (.*) line (.*)")
source_file, source_lnum = line:match "Last set from (.*) line (.*)"
if source_file then
local autocmd = {}
autocmd.event = current_event
autocmd.group = current_group
autocmd.ft_pattern = current_ft
autocmd.command = cmd
autocmd.event = current_event
autocmd.group = current_group
autocmd.ft_pattern = current_ft
autocmd.command = cmd
autocmd.source_file = source_file
autocmd.source_lnum = source_lnum
table.insert(autocmd_table, autocmd)
@@ -937,12 +936,12 @@ internal.autocommands = function(opts)
end
local cmd_output = vim.fn.execute("verb autocmd *", "silent")
for line in cmd_output:gmatch("[^\r\n]+") do
for line in cmd_output:gmatch "[^\r\n]+" do
inner_loop(line)
end
pickers.new(opts,{
prompt_title = 'autocommands',
pickers.new(opts, {
prompt_title = "autocommands",
finder = finders.new_table {
results = autocmd_table,
entry_maker = opts.entry_maker or make_entry.gen_from_autocommands(opts),
@@ -953,22 +952,24 @@ internal.autocommands = function(opts)
action_set.select:replace(function(_, type)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd(action_state.select_key_to_edit_key(type) .. ' ' .. selection.value)
vim.cmd(action_state.select_key_to_edit_key(type) .. " " .. selection.value)
end)
return true
end
end,
}):find()
end
internal.spell_suggest = function(opts)
if not vim.wo.spell then return false end
if not vim.wo.spell then
return false
end
local cursor_word = vim.fn.expand("<cword>")
local cursor_word = vim.fn.expand "<cword>"
local suggestions = vim.fn.spellsuggest(cursor_word)
pickers.new(opts, {
prompt_title = 'Spelling Suggestions',
prompt_title = "Spelling Suggestions",
finder = finders.new_table {
results = suggestions,
},
@@ -977,11 +978,11 @@ internal.spell_suggest = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('normal! ciw' .. selection[1])
vim.cmd('stopinsert')
vim.cmd("normal! ciw" .. selection[1])
vim.cmd "stopinsert"
end)
return true
end
end,
}):find()
end
@@ -999,22 +1000,17 @@ internal.tagstack = function(opts)
tag.lnum = tag.from[2]
tag.col = tag.from[3]
tag.text = vim.api.nvim_buf_get_lines(
tag.bufnr,
tag.lnum - 1,
tag.lnum,
false
)[1] or ''
tag.text = vim.api.nvim_buf_get_lines(tag.bufnr, tag.lnum - 1, tag.lnum, false)[1] or ""
end
end
if vim.tbl_isempty(tags) then
print("No tagstack available")
print "No tagstack available"
return
end
pickers.new(opts, {
prompt_title = 'TagStack',
prompt_title = "TagStack",
finder = finders.new_table {
results = tags,
entry_maker = make_entry.gen_from_quickfix(opts),
@@ -1032,14 +1028,14 @@ internal.jumplist = function(opts)
local sorted_jumplist = {}
for i = #jumplist, 1, -1 do
if vim.api.nvim_buf_is_valid(jumplist[i].bufnr) then
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum, jumplist[i].lnum+1,
false)[1] or ''
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum, jumplist[i].lnum + 1, false)[1]
or ""
table.insert(sorted_jumplist, jumplist[i])
end
end
pickers.new(opts, {
prompt_title = 'Jumplist',
prompt_title = "Jumplist",
finder = finders.new_table {
results = sorted_jumplist,
entry_maker = make_entry.gen_from_quickfix(opts),