diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2021-07-23 17:42:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-23 11:42:37 -0400 |
| commit | 79644ab67731c7ba956c354bf0545282f34e10cc (patch) | |
| tree | e65dbf73b3442ab1aa9fc59fc56a35b4c9edf1e0 /lua/telescope/command.lua | |
| parent | 664690029fdb302bee8d3f27a458383e8477add7 (diff) | |
chore: use stylua for formatting (#1040)
* chore: stylua job and config
* reformat with stylua
Diffstat (limited to 'lua/telescope/command.lua')
| -rw-r--r-- | lua/telescope/command.lua | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/lua/telescope/command.lua b/lua/telescope/command.lua index 9013ffc..c123b7b 100644 --- a/lua/telescope/command.lua +++ b/lua/telescope/command.lua @@ -1,15 +1,18 @@ -local themes = require('telescope.themes') -local builtin = require('telescope.builtin') -local extensions = require('telescope._extensions').manager -local config = require('telescope.config') +local themes = require "telescope.themes" +local builtin = require "telescope.builtin" +local extensions = require("telescope._extensions").manager +local config = require "telescope.config" local command = {} local arg_value = { - ['nil'] = nil,['""'] = '',['"'] = '' + ["nil"] = nil, + ['""'] = "", + ['"'] = "", } local bool_type = { - ['false'] = false,['true'] = true + ["false"] = false, + ["true"] = true, } -- convert command line string arguments to @@ -18,17 +21,17 @@ local function convert_user_opts(user_opts) local default_opts = config.values local _switch = { - ['boolean'] = function(key,val) - if val == 'false' then + ["boolean"] = function(key, val) + if val == "false" then user_opts[key] = false return end user_opts[key] = true end, - ['number'] = function(key,val) + ["number"] = function(key, val) user_opts[key] = tonumber(val) end, - ['string'] = function(key,val) + ["string"] = function(key, val) if arg_value[val] ~= nil then user_opts[key] = arg_value[val] return @@ -37,22 +40,22 @@ local function convert_user_opts(user_opts) if bool_type[val] ~= nil then user_opts[key] = bool_type[val] end - end + end, } local _switch_metatable = { - __index = function(_,k) - print(string.format('Type of %s does not match',k)) - end + __index = function(_, k) + print(string.format("Type of %s does not match", k)) + end, } - setmetatable(_switch,_switch_metatable) + setmetatable(_switch, _switch_metatable) - for key,val in pairs(user_opts) do + for key, val in pairs(user_opts) do if default_opts[key] ~= nil then - _switch[type(default_opts[key])](key,val) + _switch[type(default_opts[key])](key, val) else - _switch['string'](key,val) + _switch["string"](key, val) end end end @@ -69,14 +72,14 @@ end local function run_command(args) local user_opts = args or {} if next(user_opts) == nil and not user_opts.cmd then - print('[Telescope] your command miss args') + print "[Telescope] your command miss args" return end local cmd = user_opts.cmd local opts = user_opts.opts or {} - local extension_type = user_opts.extension_type or '' - local theme = user_opts.theme or '' + local extension_type = user_opts.extension_type or "" + local theme = user_opts.theme or "" if next(opts) ~= nil then convert_user_opts(opts) @@ -96,7 +99,7 @@ local function run_command(args) return end - if rawget(extensions,cmd) then + if rawget(extensions, cmd) then extensions[cmd][cmd](opts) end end @@ -106,12 +109,12 @@ end -- input in command line `Telescope gh <TAB>` -- Returns a list for each extension. function command.get_extensions_subcommand() - local exts = require('telescope._extensions').manager + local exts = require("telescope._extensions").manager local complete_ext_table = {} - for cmd,value in pairs(exts) do + for cmd, value in pairs(exts) do if type(value) == "table" then local subcmds = {} - for key,_ in pairs(value) do + for key, _ in pairs(value) do table.insert(subcmds, key) end complete_ext_table[cmd] = subcmds @@ -121,36 +124,36 @@ function command.get_extensions_subcommand() end local split_keywords = { - ['find_command'] = true, - ['vimgrep_arguments'] = true, - ['sections'] = true, - ['search_dirs'] = true + ["find_command"] = true, + ["vimgrep_arguments"] = true, + ["sections"] = true, + ["search_dirs"] = true, } function command.register_keyword(keyword) split_keywords[keyword] = true end -function command.load_command(cmd,...) - local args = {...} +function command.load_command(cmd, ...) + local args = { ... } if cmd == nil then - run_command({cmd = 'builtin'}) + run_command { cmd = "builtin" } return end local user_opts = {} - user_opts['cmd'] = cmd + user_opts["cmd"] = cmd user_opts.opts = {} - for _,arg in ipairs(args) do - if arg:find('=',1) == nil then - user_opts['extension_type'] = arg + for _, arg in ipairs(args) do + if arg:find("=", 1) == nil then + user_opts["extension_type"] = arg else - local param = vim.split(arg,'=') - if param[1] == 'theme' then - user_opts['theme'] = param[2] + local param = vim.split(arg, "=") + if param[1] == "theme" then + user_opts["theme"] = param[2] elseif split_keywords[param[1]] then - user_opts.opts[param[1]] = vim.split(param[2],',') + user_opts.opts[param[1]] = vim.split(param[2], ",") else user_opts.opts[param[1]] = param[2] end |
