davidgranstrom/scnvim

[FR]: Help doc source link open in nvim.

Closed this issue · 4 comments

paum3 commented

I am using a 'standart' Qt GUI Help system. Often working on documentation. I was wandering if it will be hard to implement a feature:
when click on link on bottom of helpfile page, in ScIDE it opens the source for page, it will be useful if scnvim could do the same thing in neovim.

Thank you.
Fero

Hi @paum3

I take it that you are editing the help file (source) in nvim?

It is a bit complicated I'm afraid since the Qt HelpBrowser is not known to nvim.. and I don't think it's possible to achieve what you want just using javascript, probably some modifications to the low level implementation of the HelpBrowser/Qt layer is needed.

But if you would consider using the scnvim help system (let g:scnvim_scdoc = 1) then all you would need to do is type gf on the help source path rendered at the bottom of the file to go to the source.

paum3 commented

Dear @davidgranstrom ,
your reply was really fast :)
yes, I am using nvim as my only editor for everything, I think nothing obvious in this community.
I understand, it seems as not an easy task.

I am not comfortable with pandoc style, that is reason why I am using an old good HelpBrowser. Actually I have implemented vim keys inside it (PR requests in SC community take really long time, its one year I suppose) so it is keyboard friendly and more transparent, at least for me.

I am still thinking how to find some way for this. What about this:

K - opens helpfile for a word cursor is on. Could there be a way to implement a keyboard shortcut to open helpfile source such a way with some other keystroke ?

Yes, you could use the scnvim lua API for this. Save this content in a file somewhere where it will be picked up in your runtime path (e.g. ~/.config/nvim/lua/find_help_source.lua), or put it inside your init.vim

local scnvim = require'scnvim'

-- Get the help source URI for "subject"
-- @param subject The subject to find
-- @param cb A callback which gets the URI as its first argument
local function get_help_uri(subject, cb)
  local cmd = [[SCDoc.helpSourceDir +/+ \"Classes\" +/+ \"%s\" ++ \".schelp\"]]
  cmd = string.format(cmd, subject)
  scnvim.eval(cmd, cb)
end

-- Open the help source file for the word under the cursor
return function()
  local subject = vim.fn.expand('<cword>')
  get_help_uri(subject, function(result)
    result = string.format('edit %s', result)
    vim.cmd(result)
  end)
end

Then map a key sequence to execute the exported lua function

nnoremap <F5> <cmd>lua require'path.to.file'()<cr>

If you put the code snippet directly in your init.vim you will not be able to require it in the mapping as in the example above. You would need to put the (exported) function in global scope instead and simply call it.

Hope that helps!

paum3 commented

Great! Thats is exacty what I need.
Thank you very much David.
best