Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add a wiki for repo #70

Closed
jrwrigh opened this issue Jul 8, 2022 · 4 comments
Closed

[FEATURE] Add a wiki for repo #70

jrwrigh opened this issue Jul 8, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@jrwrigh
Copy link
Contributor

jrwrigh commented Jul 8, 2022

Basically as an option to add some config examples/advanced configurations. For example, I have now setup goto-preview to behave similarly to telescope in regards to "expanding" preview windows into full windows. You can press <CR>, <C-v>, <C-x>, <C-t> to expand the preview into the current (main) window, vertical split, horizontal split, and a new tab, respectively.

local gtp = require('goto-preview')
local select_to_edit_map = {
  default    = "edit",
  horizontal = "new",
  vertical   = "vnew",
  tab        = "tabedit",
}

local function open_file(orig_window, filename, cursor_position, command)
  if orig_window ~= 0 and orig_window ~= nil then
    vim.api.nvim_set_current_win(orig_window)
  end
  pcall(vim.cmd, string.format('%s %s', command, filename))
  vim.api.nvim_win_set_cursor(0, cursor_position)
end

local function open_preview(preview_win, type)
  return function()
    local command         = select_to_edit_map[type]
    local orig_window     = vim.api.nvim_win_get_config(preview_win).win
    local cursor_position = vim.api.nvim_win_get_cursor(preview_win)
    local filename        = vim.api.nvim_buf_get_name(0)

    vim.api.nvim_win_close(preview_win, gtp.conf.force_close)
    open_file(orig_window, filename, cursor_position, command)

    local buffer = vim.api.nvim_get_current_buf()
    vim.api.nvim_buf_del_keymap(buffer, 'n', '<C-v>')
    vim.api.nvim_buf_del_keymap(buffer, 'n', '<CR>')
    vim.api.nvim_buf_del_keymap(buffer, 'n', '<C-x>')
    vim.api.nvim_buf_del_keymap(buffer, 'n', '<C-t>')
  end
end

local function post_open_hook(buf, win)
  vim.keymap.set('n', '<C-v>', open_preview(win, "vertical"),   { buffer = buf })
  vim.keymap.set('n', '<CR>',  open_preview(win, "default"),    { buffer = buf })
  vim.keymap.set('n', '<C-x>', open_preview(win, "horizontal"), { buffer = buf })
  vim.keymap.set('n', '<C-t>', open_preview(win, "tab"),        { buffer = buf })
end

require('goto-preview').setup {
  post_open_hook = post_open_hook,
}

I don't see any particular reason for this to be "officially" incorporated into the plugin, but I think it'd be nice to share with others as an option.

@jrwrigh jrwrigh added the enhancement New feature or request label Jul 8, 2022
@rmagatti
Copy link
Owner

rmagatti commented Jul 9, 2022

Hey, yeah this is good stuff. I've created the wiki with just the main page (no info for now). After your PR is merged you'll be able to edit the Wiki as well!

@jrwrigh
Copy link
Contributor Author

jrwrigh commented Jul 18, 2022

The PR was merged, but I'm still unable to edit the wiki.

@rmagatti
Copy link
Owner

@jrwrigh I misinformed you before. I have edited permissions so wiki editing is public now.

@jrwrigh
Copy link
Contributor Author

jrwrigh commented Jul 19, 2022

No worries! I now have write access to the wiki. I'll go ahead and add my stuff.

@jrwrigh jrwrigh closed this as completed Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants