From 789e0bf3105864808cd7879ae7989334511b412b Mon Sep 17 00:00:00 2001 From: bhagwan Date: Wed, 1 Sep 2021 19:39:01 -0700 Subject: [PATCH] added 'filetypes' provider --- README.md | 1 + lua/fzf-lua/actions.lua | 5 +++++ lua/fzf-lua/config.lua | 6 ++++++ lua/fzf-lua/init.lua | 1 + lua/fzf-lua/providers/nvim.lua | 21 +++++++++++++++++++++ 5 files changed, 34 insertions(+) diff --git a/README.md b/README.md index fb36a0b..9689bb2 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ nnoremap lua require('fzf-lua').files() |`spell_suggest`|spelling suggestions| |`tags`|project tags| |`btags`|buffer tags| +|`filetypes`|neovim filetypes| |`packadd`|:packadd | diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index f104da1..3381509 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -178,6 +178,11 @@ M.spell_apply = function(selected) vim.cmd("stopinsert") end +M.set_filetype = function(selected) + if not selected then return end + vim.api.nvim_buf_set_option(0, 'filetype', selected[1]) +end + M.packadd = function(selected) if not selected then return end for i = 1, #selected do diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 155b212..b569164 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -428,6 +428,12 @@ M.globals.nvim = { ["default"] = actions.spell_apply, }, }, + filetypes = { + prompt = 'Filetypes> ', + actions = { + ["default"] = actions.set_filetype, + }, + }, packadd = { prompt = 'packadd> ', actions = { diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index e6d38dd..d207b0d 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -81,6 +81,7 @@ M.commands = require'fzf-lua.providers.nvim'.commands M.command_history = require'fzf-lua.providers.nvim'.command_history M.search_history = require'fzf-lua.providers.nvim'.search_history M.spell_suggest = require'fzf-lua.providers.nvim'.spell_suggest +M.filetypes = require'fzf-lua.providers.nvim'.filetypes M.packadd = require'fzf-lua.providers.nvim'.packadd M.lsp_typedefs = require'fzf-lua.providers.lsp'.typedefs diff --git a/lua/fzf-lua/providers/nvim.lua b/lua/fzf-lua/providers/nvim.lua index 159a3a0..be34984 100644 --- a/lua/fzf-lua/providers/nvim.lua +++ b/lua/fzf-lua/providers/nvim.lua @@ -260,6 +260,27 @@ M.spell_suggest = function(opts) end +M.filetypes = function(opts) + + opts = config.normalize_opts(opts, config.globals.nvim.filetypes) + + coroutine.wrap(function () + + local entries = vim.fn.getcompletion('', 'filetype') + if vim.tbl_isempty(entries) then return end + + opts.nomulti = true + opts.preview = nil + opts.preview_window = 'hidden:down:0' + + local selected = core.fzf(opts, entries) + + if not selected then return end + actions.act(opts.actions, selected) + + end)() + +end M.packadd = function(opts)