feat: cycle previewers with commit and bcommit already using it (#528)

- new git previewers
- jump to line in bcommit previewer
- vimdiff for bcommits
- dynamic preview window titles
- more previewers documentation

Cycle previewers are not mapped yet. So you need to setup yourself:
```lua
require('telescope').setup {
  defaults = {
    mappings = {
      i = {
        ["<C-s>"] = actions.cycle_previewers_next,
        ["<C-a>"] = actions.cycle_previewers_prev,
      },
    },
  }
}
```

Co-authored-by: Thore Strassburg <thore@weilbier.net>
This commit is contained in:
Simon Hauser
2021-06-14 21:50:46 +02:00
committed by GitHub
parent 0c1bc129da
commit 6ac5ee0854
11 changed files with 566 additions and 76 deletions

View File

@@ -1,5 +1,6 @@
local conf = require('telescope.config').values
local utils = require('telescope.utils')
local path = require('telescope.path')
local putils = require('telescope.previewers.utils')
local from_entry = require('telescope.from_entry')
local Previewer = require('telescope.previewers.previewer')
@@ -112,6 +113,8 @@ previewers.new_termopen_previewer = function(opts)
local opt_setup = opts.setup
local opt_teardown = opts.teardown
local opt_title = opts.title
local opt_dyn_title = opts.dyn_title
local old_bufs = {}
@@ -135,6 +138,24 @@ previewers.new_termopen_previewer = function(opts)
if self.state then self.state.termopen_bufnr = value end
end
function opts.title(self)
if opt_title then
if type(opt_title) == 'function' then
return opt_title(self)
else
return opt_title
end
end
return "Preview"
end
function opts.dyn_title(self, entry)
if opt_dyn_title then
return opt_dyn_title(self, entry)
end
return "Preview"
end
function opts.setup(self)
local state = {}
if opt_setup then vim.tbl_deep_extend("force", state, opt_setup(self)) end
@@ -210,9 +231,17 @@ previewers.new_termopen_previewer = function(opts)
end
previewers.cat = defaulter(function(opts)
opts = opts or {}
local maker = get_maker(opts)
local cwd = opts.cwd or vim.loop.cwd()
return previewers.new_termopen_previewer {
title = "File Preview",
dyn_title = function(_, entry)
return path.normalize(from_entry.path(entry, true), cwd)
end,
get_command = function(entry)
local p = from_entry.path(entry, true)
if p == nil or p == '' then return end
@@ -223,9 +252,17 @@ previewers.cat = defaulter(function(opts)
end, {})
previewers.vimgrep = defaulter(function(opts)
opts = opts or {}
local maker = get_maker(opts)
local cwd = opts.cwd or vim.loop.cwd()
return previewers.new_termopen_previewer {
title = "Grep Preview",
dyn_title = function(_, entry)
return path.normalize(from_entry.path(entry, true), cwd)
end,
get_command = function(entry, status)
local win_id = status.preview_win
local height = vim.api.nvim_win_get_height(win_id)
@@ -251,8 +288,14 @@ previewers.qflist = defaulter(function(opts)
opts = opts or {}
local maker = get_maker(opts)
local cwd = opts.cwd or vim.loop.cwd()
return previewers.new_termopen_previewer {
title = "Grep Preview",
dyn_title = function(_, entry)
return path.normalize(from_entry.path(entry, true), cwd)
end,
get_command = function(entry, status)
local win_id = status.preview_win
local height = vim.api.nvim_win_get_height(win_id)