summaryrefslogtreecommitdiff
path: root/lua/telescope/previewers.lua
diff options
context:
space:
mode:
authorSenghan Bright <senghan.bright@deltaprojects.com>2020-09-25 06:16:48 +0200
committerGitHub <noreply@github.com>2020-09-25 00:16:48 -0400
commitc3f9b25606cea94bc4af55dbddf7d7d863be4517 (patch)
treef7640ee93bb11f191ee1388aa737128b0142b062 /lua/telescope/previewers.lua
parenta38bb06e7da233a975cbf27b897a22001c4fd206 (diff)
feature: Vim help-tags picker (#117)
* feature: Vim help-tags picker * fix: filtered results were wrong because of missing `entry.value` * fix: filtered (Vim only help) items are listed in results as empty entries. * fix: avoid search history pollution by replacing / in cmd returned by taglist() with search() * fix: improve search() formatting * fix: escape tilde in search() command * fix: improve help-preview * fix: improve search() * fix: search() string fixes. * fix: use no magic to do magic Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
Diffstat (limited to 'lua/telescope/previewers.lua')
-rw-r--r--lua/telescope/previewers.lua30
1 files changed, 19 insertions, 11 deletions
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua
index f3f6261..e28adce 100644
--- a/lua/telescope/previewers.lua
+++ b/lua/telescope/previewers.lua
@@ -58,7 +58,7 @@ end
local previewer_ns = vim.api.nvim_create_namespace('telescope.previewers')
local with_preview_window = function(status, bufnr, callable)
- if bufnr and vim.api.nvim_buf_call then
+ if bufnr and vim.api.nvim_buf_call and false then
vim.api.nvim_buf_call(bufnr, callable)
else
return context_manager.with(function()
@@ -365,17 +365,17 @@ previewers.qflist = defaulter(function(opts)
}
end, {})
--- WIP
previewers.help = defaulter(function(_)
return previewers.new {
preview_fn = function(_, entry, status)
with_preview_window(status, nil, function()
- local old_tags = vim.o.tags
- vim.o.tags = vim.fn.expand("$VIMRUNTIME") .. '/doc/tags'
+ local special_chars = ":~^.?/%[%]%*"
- local taglist = vim.fn.taglist('^' .. entry.value .. '$')
+ local escaped = vim.fn.escape(entry.value, special_chars)
+ local tagfile = vim.fn.expand("$VIMRUNTIME") .. '/doc/tags'
+ local taglist = vim.fn.taglist('^' .. escaped .. '$', tagfile)
if vim.tbl_isempty(taglist) then
- taglist = vim.fn.taglist(entry.value)
+ taglist = vim.fn.taglist(escaped, tagfile)
end
if vim.tbl_isempty(taglist) then
@@ -384,15 +384,23 @@ previewers.help = defaulter(function(_)
local best_entry = taglist[1]
local new_bufnr = vim.fn.bufnr(best_entry.filename, true)
-
vim.api.nvim_buf_set_option(new_bufnr, 'filetype', 'help')
vim.api.nvim_win_set_buf(status.preview_win, new_bufnr)
- vim.cmd [["gg"]]
- print(best_entry.cmd)
- vim.cmd(string.format([[execute "%s"]], best_entry.cmd))
+ local search_query = best_entry.cmd
+
+ -- remove leading '/'
+ search_query = search_query:sub(2)
+
+ -- Set the query to "very nomagic".
+ -- This should make it work quite nicely given tags.
+ search_query = [[\V]] .. search_query
+
+ log.trace([[lua vim.fn.search("]], search_query, [[")]])
- vim.o.tags = old_tags
+ vim.cmd "norm! gg"
+ vim.fn.search(search_query, "W")
+ vim.cmd "norm zt"
end)
end
}