summaryrefslogtreecommitdiff
path: root/lua/telescope/builtin/internal.lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2022-06-12 15:09:41 +0200
committerSimon Hauser <simon.hauser@helsinki-systems.de>2022-06-30 14:01:51 +0200
commit77e2b8ceea048b42773fc454658c17448caa2a93 (patch)
treeeb93131c4367ed37ed8eafd7e58ffaf988fe666a /lua/telescope/builtin/internal.lua
parent838c32d6a86c8a4b8f3333f66e797f7cad2e3c1b (diff)
chore: cleanup autocmd builtin (#1947)
Diffstat (limited to 'lua/telescope/builtin/internal.lua')
-rw-r--r--lua/telescope/builtin/internal.lua103
1 files changed, 26 insertions, 77 deletions
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua
index e4a5704..4519b93 100644
--- a/lua/telescope/builtin/internal.lua
+++ b/lua/telescope/builtin/internal.lua
@@ -1170,95 +1170,44 @@ internal.highlights = function(opts)
end
internal.autocommands = function(opts)
- local autocmd_table = {}
-
- local pattern = {}
- pattern.BUFFER = "<buffer=%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
- local current_event, current_group, current_ft
-
- local inner_loop = function(line)
- -- capture group and event
- group, event = line:match("^(" .. pattern.GROUP .. ")%s+(" .. pattern.EVENT .. ")")
- -- ..or just an event
- if event == nil then
- event = line:match("^(" .. pattern.EVENT .. ")")
- end
-
- if event then
- group = group or "<anonymous>"
- if event ~= current_event or group ~= current_group then
- current_event = event
- current_group = group
- end
- return
- end
-
- -- non event/group lines
- ft_pat = line:match(pattern.INDENT .. "(%S+)")
- if ft_pat then
- if ft_pat:match "^%d+" then
- ft_pat = "<buffer=" .. ft_pat .. ">"
- end
- current_ft = ft_pat
-
- -- is there a command on the same line?
- cmd = line:match(pattern.INDENT .. "%S+%s+(.+)")
-
- return
- end
-
- if current_ft and cmd == nil then
- -- trim leading spaces
- cmd = line:gsub("^%s+", "")
- return
- end
-
- if current_ft and cmd then
- source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$"
- source_lnum = line:match "line (%d*)$" or "1"
- if source_file then
- local autocmd = {}
- 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)
-
- cmd = nil
- end
- end
- end
-
- local cmd_output = vim.fn.execute("verb autocmd *", "silent")
- for line in cmd_output:gmatch "[^\r\n]+" do
- inner_loop(line)
- end
-
+ local autocmds = vim.api.nvim_get_autocmds {}
+ table.sort(autocmds, function(lhs, rhs)
+ return lhs.event < rhs.event
+ end)
pickers.new(opts, {
prompt_title = "autocommands",
finder = finders.new_table {
- results = autocmd_table,
+ results = autocmds,
entry_maker = opts.entry_maker or make_entry.gen_from_autocommands(opts),
},
previewer = previewers.autocommands.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
- action_set.select:replace(function(_, type)
+ action_set.select:replace_if(function()
local selection = action_state.get_selected_entry()
if selection == nil then
- utils.__warn_no_selection "builtin.autocommands"
- return
+ return false
end
-
+ local val = selection.value
+ local output = vim.fn.execute(
+ "verb autocmd " .. val.group_name .. " " .. val.event .. " " .. val.pattern,
+ "silent"
+ )
+ for line in output:gmatch "[^\r\n]+" do
+ local source_file = line:match "Last set from (.*) line %d*$" or line:match "Last set from (.*)$"
+ if source_file and source_file ~= "Lua" then
+ selection.filename = source_file
+ local source_lnum = line:match "line (%d*)$" or "1"
+ selection.lnum = tonumber(source_lnum)
+ selection.col = 1
+ return false
+ end
+ end
+ return true
+ end, function()
+ local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
- vim.cmd(action_state.select_key_to_edit_key(type) .. " " .. selection.value)
+ print("You selected autocmd: " .. vim.inspect(selection.value))
end)
return true