Skip to content

Commit

Permalink
feat(telescope): add prettier previewer that displays open buffers (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejboczar authored Nov 13, 2023
1 parent 51fff4d commit a4180c7
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 17 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,16 @@ require('possession').setup {
delete_buffers = false,
},
telescope = {
previewer = nil, -- or false to disable previewer
previewer = {
enabled = true,
previewer = 'pretty', -- or 'raw' or fun(opts): Previewer
wrap_lines = true,
include_empty_plugin_data = false,
cwd_colors = {
cwd = 'Comment',
tab_cwd = { '#cc241d', '#b16286', '#d79921', '#689d6a', '#d65d0e', '#458588' }
}
},
list = {
default_action = 'load',
mappings = {
Expand Down
33 changes: 28 additions & 5 deletions doc/possession.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,34 @@ telescope~
`table`
Configuration for builtin possession telescope pickers.

telescope.previewer~
`string|Previewer`
Show previewer for each session. By default is `nil`, which shows the
default previewer. `false` disables previewer. To use a custom previewer
pass a telescope Previewer object (see source code for example).
telescope.previewer.enabled~
`boolean`
Show previewer in telescope picker.

telescope.previewer.previewer~
`'pretty'|'raw'|function(opts):Previewer`
Select previewer to use, either one of the ones included in this plugin or
a custom previewer that will be returned from the function.

telescope.previewer.wrap_lines~
`boolean`
|wrap| lines in the preview window.

telescope.previewer.include_empty_plugin_data~
`boolean`
Remove keys in `plugin_data` with no important data.

telescope.previewer.cwd_colors.cwd~
`string`
Color to use when highlighting sesion cwd in paths. Interpreted as hex
color if it starts with `#`, otherwise as a name of a highlight group.

telescope.previewer.cwd_colors.tab_cwd~
`string[]`
Colors to use when highlighting sesion tab_cwd in paths. Interpreted as hex
color if it starts with `#`, otherwise as a name of a highlight group.
The colors will be assigned to consecutive tab cwds, modulo-wrapping to
start if there are move tab cwds than colors defined for this settings.

telescope.list~
`table`
Expand Down
15 changes: 15 additions & 0 deletions lua/possession.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ local function setup(opts)
commands.migrate(o.fargs[1])
end)
end

local function set_hl(name, color)
local val = { default = true }
if vim.startswith(color, '#') then
val.fg = color
else
val.link = color
end
vim.api.nvim_set_hl(0, name, val)
end

set_hl('PossessionPreviewCwd', config.telescope.previewer.cwd_colors.cwd)
for i, color in ipairs(config.telescope.previewer.cwd_colors.tab_cwd) do
set_hl(string.format('PossessionPreviewTabCwd%d', i), color)
end
end

return {
Expand Down
21 changes: 20 additions & 1 deletion lua/possession/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ local function defaults()
delete_buffers = false,
},
telescope = {
previewer = nil, -- or false to disable previewer
previewer = {
enabled = true,
previewer = 'pretty', -- or 'raw' or fun(opts): Previewer
wrap_lines = true,
include_empty_plugin_data = false,
cwd_colors = {
cwd = 'Comment',
tab_cwd = { '#cc241d', '#b16286', '#d79921', '#689d6a', '#d65d0e', '#458588' }
}
},
list = {
default_action = 'load',
mappings = {
Expand Down Expand Up @@ -128,9 +137,19 @@ local function warn_on_unknown_keys(conf)
end
end

local function fix_compatibility(opts)
if type(vim.tbl_get(opts, 'telescope', 'previewer')) == 'boolean' then
opts.telescope.previewer = {
enable = opts.telescope.previewer,
}
end
end

function M.setup(opts)
warn_on_unknown_keys(opts)

fix_compatibility(opts)

local new_config = vim.tbl_deep_extend('force', {}, defaults(), opts or {})
-- Do _not_ replace the table pointer with `config = ...` because this
-- wouldn't change the tables that have already been `require`d by other
Expand Down
Loading

0 comments on commit a4180c7

Please sign in to comment.