summaryrefslogtreecommitdiff
path: root/lua/telescope/make_entry.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/telescope/make_entry.lua')
-rw-r--r--lua/telescope/make_entry.lua129
1 files changed, 72 insertions, 57 deletions
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index 17a5e4c..bd1bf73 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -179,79 +179,94 @@ do
return {filename, lnum, col, text}
end
- local execute_keys = {
- path = function(t)
- return t.cwd .. path.separator .. t.filename, false
- end,
-
- filename = function(t)
- return parse(t)[1], true
- end,
-
- lnum = function(t)
- return parse(t)[2], true
- end,
-
- col = function(t)
- return parse(t)[3], true
- end,
-
- text = function(t)
- return parse(t)[4], true
- end,
- }
-
+ --- Special options:
+ --- - shorten_path: make the path appear short
+ --- - disable_coordinates: Don't show the line & row numbers
+ --- - only_sort_text: Only sort via the text. Ignore filename and other items
function make_entry.gen_from_vimgrep(opts)
+ local mt_vimgrep_entry
+
opts = opts or {}
+ local disable_devicons = opts.disable_devicons
local shorten_path = opts.shorten_path
local disable_coordinates = opts.disable_coordinates
- local disable_devicons = opts.disable_devicons
+ local only_sort_text = opts.only_sort_text
- local display_string = "%s:%s%s"
+ local execute_keys = {
+ path = function(t)
+ return t.cwd .. path.separator .. t.filename, false
+ end,
- local mt_vimgrep_entry = {}
+ filename = function(t)
+ return parse(t)[1], true
+ end,
- mt_vimgrep_entry.cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
- mt_vimgrep_entry.display = function(entry)
- local display_filename
- if shorten_path then
- display_filename = utils.path_shorten(entry.filename)
- else
- display_filename = entry.filename
- end
+ lnum = function(t)
+ return parse(t)[2], true
+ end,
- local coordinates = ""
- if not disable_coordinates then
- coordinates = string.format("%s:%s:", entry.lnum, entry.col)
- end
+ col = function(t)
+ return parse(t)[3], true
+ end,
- local display, hl_group = transform_devicons(
- entry.filename,
- string.format(display_string, display_filename, coordinates, entry.text),
- disable_devicons
- )
+ text = function(t)
+ return parse(t)[4], true
+ end,
+ }
- if hl_group then
- return display, { { {1, 3}, hl_group } }
- else
- return display
+ -- For text search only, the ordinal value is actually the text.
+ if only_sort_text then
+ execute_keys.ordinal = function(t)
+ return t.text
end
end
- mt_vimgrep_entry.__index = function(t, k)
- local raw = rawget(mt_vimgrep_entry, k)
- if raw then return raw end
+ local display_string = "%s:%s%s"
- local executor = rawget(execute_keys, k)
- if executor then
- local val, save = executor(t)
- if save then rawset(t, k, val) end
- return val
- end
+ mt_vimgrep_entry = {
+ cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd()),
- return rawget(t, rawget(lookup_keys, k))
- end
+ display = function(entry)
+ local display_filename
+ if shorten_path then
+ display_filename = utils.path_shorten(entry.filename)
+ else
+ display_filename = entry.filename
+ end
+
+ local coordinates = ""
+ if not disable_coordinates then
+ coordinates = string.format("%s:%s:", entry.lnum, entry.col)
+ end
+
+ local display, hl_group = transform_devicons(
+ entry.filename,
+ string.format(display_string, display_filename, coordinates, entry.text),
+ disable_devicons
+ )
+
+ if hl_group then
+ return display, { { {1, 3}, hl_group } }
+ else
+ return display
+ end
+ end,
+
+ __index = function(t, k)
+ local raw = rawget(mt_vimgrep_entry, k)
+ if raw then return raw end
+
+ local executor = rawget(execute_keys, k)
+ if executor then
+ local val, save = executor(t)
+ if save then rawset(t, k, val) end
+ return val
+ end
+
+ return rawget(t, rawget(lookup_keys, k))
+ end,
+ }
return function(line)
return setmetatable({line}, mt_vimgrep_entry)