luckasRanarison / nvim-devdocs

Neovim DevDocs integration
MIT License
269 stars 19 forks source link

Use custom commands to render markdown #4

Closed luckasRanarison closed 1 year ago

luckasRanarison commented 1 year ago

Use tools like glow to render documentations inside a terminal buffer

gipo355 commented 1 year ago

Exactly the first thing i did! fetching the doc and immediately using glow on it

mvaldes14 commented 1 year ago

was gonna create an issue for this, so yeah something like glow works perfectly for this cause seeing raw markdown in a buffer isn't exactly functional... id rather just use the browser

I-Own-You commented 1 year ago

was gonna create an issue for this, so yeah something like glow works perfectly for this cause seeing raw markdown in a buffer isn't exactly functional... id rather just use the browser

As a workaround you could use the same command you open DevDocsOpenFloat and :Glow, and closing the DevDocsOpenFloat markdown but not the :Glow variant, closing it with q also. init.lua:

vim.cmd[[
augroup AutoCloseMarkdownGlow
  autocmd!
  autocmd FileType markdown,glowpreview nnoremap <buffer> q :q<CR>
augroup END
]]

vim.cmd[[
augroup MarkdownKeymaps
  autocmd!
  autocmd FileType markdown nnoremap <buffer> <leader>dd :lua MyGlow()<CR>
  autocmd FileType glowpreview nnoremap <buffer> <leader>dd :<CR>
augroup END
]]

function MyGlow()
  vim.cmd('Glow')
  for _, winid in ipairs(vim.fn.getwininfo()) do
    local bufnr = winid.bufnr
    local filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype')
    if filetype == 'markdown' then
      vim.cmd('bw ' .. bufnr)
      return
    end
  end
end

-- Keymap for DevdocsOpenFloat
vim.api.nvim_set_keymap("n", "<leader>dd", ":DevdocsOpenFloat<CR>", {noremap = true, silent = true})

The only downside is that the first time you will try to do it, it will close the floating buffer because of plugin loading. But after the first one, it will always work. But you can adjust i guess with some time.sleep from lua

Screencast from 2023-08-12 16-32-04.webm

A better approach would be changing the operations.lua file, M.open function, and add this code at the end of it:

  vim.cmd('Glow')
  vim.defer_fn(function()
    vim.cmd('bdelete ' .. buf)
  end, 2000) -- you can adjust the timing
luckasRanarison commented 1 year ago

New in 5b6ba3c Good news guys... You can now use custom cmds for previewing docs! Checkout the new config options for more details. It's still not available for the telescope previewer however, I'm still thinking on how to improve the performance...

image

emmanueltouzery commented 1 year ago

I tried the glow support by adding previewer_cmd = 'glow',.

At first I was getting nothing at all displayed. But I was using glow 1.4.1. I upgraded it to 1.5.1 and now I'm getting something displayed, and it's the glow output, for instance links are handled differently.. However I'm getting no syntax highlighting at all. Not sure why for now.

I'm using linux.

EDIT: fixed, see next comment

emmanueltouzery commented 1 year ago

ok, with the --s flags you give in the documentation i get syntax highlighting :+1:

I-Own-You commented 1 year ago

ok, with the --s flags you give in the documentation i get syntax highlighting 👍

could you show me your setup options ? i cant make it work for me

I-Own-You commented 1 year ago

New in 5b6ba3c Good news guys... You can now use custom cmds for previewing docs! Checkout the new config options for more details. It's still not available for the telescope previewer however, I'm still thinking on how to improve the performance...

image

would you mind sharing your colorscheme theme and wallpaper background ? 🍾

emmanueltouzery commented 1 year ago

@I-Own-You I just used the settings from the readme, namely:

  previewer_cmd = 'glow',
  cmd_args = { "-s", "dark", "-w", "80" },
luckasRanarison commented 1 year ago

All pickers have previews now and support custom commands so I think I can close this.