summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2020-11-19 18:59:44 +0100
committerGitHub <noreply@github.com>2020-11-19 18:59:44 +0100
commit929a30378c3ff9e4e8252df1f18f32967ecc844c (patch)
treec72c18bcbd0fd598014728205d4df67b3e8d49e1
parent319e8ed8922e072f83adb9a7899d39db03dccd31 (diff)
Feat: Add filetypes builtin (#263)
-rw-r--r--README.md1
-rw-r--r--lua/telescope/builtin/init.lua26
2 files changed, 25 insertions, 2 deletions
diff --git a/README.md b/README.md
index 6364f38..528450b 100644
--- a/README.md
+++ b/README.md
@@ -373,6 +373,7 @@ Built-in function ready to be bound to any key you like :smile:.
| `builtin.reloader` | Lists lua modules and reload them on enter |
| `builtin.vim_options` | Lists vim options and on enter edit the options value |
| `builtin.keymaps` | Lists normal-mode mappings |
+| `builtin.filetypes | Lists all filetypes |
| `builtin.git_commits` | Lists git commits with diff preview and on enter checkout the commit.|
| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and
checkouts it out on enter|
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index 9653e0c..8bb082f 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -888,6 +888,28 @@ builtin.keymaps = function(opts)
}):find()
end
+builtin.filetypes = function(opts)
+ opts = opts or {}
+
+ local filetypes = vim.fn.getcompletion('', 'filetype')
+
+ pickers.new({}, {
+ prompt_title = 'Filetypes',
+ finder = finders.new_table {
+ results = filetypes,
+ },
+ sorter = conf.generic_sorter(),
+ attach_mappings = function(prompt_bufnr)
+ actions.goto_file_selection_edit:replace(function()
+ local selection = actions.get_selected_entry()
+ actions.close(prompt_bufnr)
+ vim.cmd('setfiletype ' .. selection[1])
+ end)
+ return true
+ end
+ }):find()
+end
+
builtin.tags = function(opts)
opts = opts or {}
@@ -913,10 +935,10 @@ builtin.tags = function(opts)
},
previewer = previewers.ctags.new(opts),
sorter = conf.generic_sorter(opts),
- attach_mappings = function(prompt_bufnr)
+ attach_mappings = function()
actions._goto_file_selection:enhance {
post = function()
- local selection = actions.get_selected_entry(prompt_bufnr)
+ local selection = actions.get_selected_entry()
local scode = string.gsub(selection.scode, '[$]$', '')
scode = string.gsub(scode, [[\\]], [[\]])