Nvim-R icon indicating copy to clipboard operation
Nvim-R copied to clipboard

Support for Neovim Float Windows

Open fbearoff opened this issue 2 years ago • 8 comments

Thanks for such a great plugin!

Is there any chance we could direct the output of some of the commands to a floating window in neovim instead of a new tab or split so that one can quickly reference and hide the information? Such applications could be viewing the help documentation (\rh) or viewing a dataframe (\vh).

For RHelp maybe allow a "float" option for "R_nvimpager"

For RViewDF it looks like 'terminal:' is hardcoded in when supplied by "R_csv_app", maybe allow a switch to call another user supplied vim command. For instance, a user could call "TermExec vd" to open the dataframe in visidata in a floating terminal.

Thanks again!

fbearoff avatar Dec 16 '22 20:12 fbearoff

Displaying help pages on float windows would be easy. We would have to decide the float windows' position, width, and height. And, what about the ability to send code from the Examples section to R? If the floating window overlaps the R console, the output might not be visible.

For RViewDF, it might be enough to add another condition:

elseif g:R_csv_app =~# '^:'
  exe g:R_csv_app . ' ' . substitute(tsvnm, ' ', '\\ ', 'g')

jalvesaq avatar Dec 16 '22 23:12 jalvesaq

For floats the default in neovim is to open under the cursor, the buffer of the float window is able to be entered if you issue the command that spawned the float a second time i.e. K opens the float and K again enters it for vim.lsp.buf.hover(). I would imagine if you set the buff type to R_doc the existing autocommands for that filetype would apply allowing code from the Examples section to be sent to the R console.

fbearoff avatar Dec 17 '22 00:12 fbearoff

Perhaps it would be better if we contributed to the development of the languageserver package until we couldn't see any advantage of specific Nvim-R's functionalities. Then, I could drop these features from Nvim-R. In the end, only features depending on R's workspace and features that take advantage of Neovim features would remain in Nvim-R (Object Browser, highlighting of function names, completion of data.frame columns, etc).

It seems that the languageserver team doesn't want to cache information, and we need this for high speed and low CPU usage during automatic omni completion and while updating the Object Browser. However, we only display R documentation under user demand. So, we don't need ultra-high speed. That is, the ability to show R documentation is one of the features that could be dropped in the future in favor of the languageserver.

jalvesaq avatar Dec 17 '22 15:12 jalvesaq

You can now put this in your init.vim:

let R_csv_app = ':TermExec cmd="vd %s"'

%s indicates the position of the tsv file name in the command.

jalvesaq avatar Dec 17 '22 19:12 jalvesaq

Awesome, thanks! I agree on languageserver since it provides the help files already, wish it had better formatting, NVim-R's docs look much nicer.

fbearoff avatar Dec 17 '22 19:12 fbearoff

Nvim-R gets R documentation as text, makes some changes in the document (ftplugin/rdoc.vim) and, then, applies a specific highlighting (syntax/rdoc.vim). This is a solution tailored specifically for Vim/Neovim. The languageserver has to use a more generic approach since it is used by a variety of text editors and IDEs. The Language Server Protocol uses markdown for reach-text contents. So, the languageserver gets R documentation as HTML and converts it to markdown.

You can try the branch rd2md from my fork of the languageserver. R documentation is converted directly to markdown. The result might be better for Neovim, but possibly not for text editors that are capable of displaying HTML.

Another approach would be what you have suggested: request plain text to the language server and treat it as Nvim-R does with R documentation. However, it seems that Neovim's lsp is hard coded to syntax highlight the documents as lsp_markdown.

jalvesaq avatar Dec 18 '22 10:12 jalvesaq

Hey guys thanks a lot for this help. just on question regarding this command.

let R_csv_app = ':TermExec cmd="vd %s"'

This command works great, but the floating window is not that great. (usually I want to keep the df open while working on the r script) is there a way to open vd in a new tab or like horizontal term?

bassamsdata avatar Jan 04 '23 04:01 bassamsdata

I found this command to be working: let R_csv_app = ':terminal vd' thanks a lot

bassamsdata avatar Jan 04 '23 05:01 bassamsdata

Those interested in better use of Neovim features might want to look at this: https://github.com/jalvesaq/Nvim-R/discussions

jalvesaq avatar Jan 23 '24 13:01 jalvesaq

Nvim-R is being superseded by R.nvim, a new project that will be inaugurated in a week at the R-nvim organization. Please, check out tmp-Nvim-R and help us to find the last remaining bugs before R.nvim inauguration. When the project is officially started, you will be able to open issues there and request new features.

Nvim-R will remain alive as a feature-frozen project for Vim users.

jalvesaq avatar Feb 18 '24 16:02 jalvesaq

I started using the new version and it's kinda work differently, so I'm a little bit getting used to it. two quick observations:

  1. the console got so much cleaner and colorful.
  2. it feels so much faster, I'm not sure if this is true though.

bassamsdata avatar Feb 19 '24 04:02 bassamsdata

  1. The option to colorize the output was introduced in 2015 (you can search for "hl_term" in the log of commits), but perhaps it is configured in Nvim-R in such a way that becomes disabled on your system.
  2. Possibly a bit faster at some operations because, without Vim, we are free to use the nvim_ functions which are designed to not disturb the editor.

jalvesaq avatar Feb 19 '24 10:02 jalvesaq

Thank you for the comprehensive response. So, I've been using it without colors all these years. Nice!

I've encountered some issues and have some feedback. I'll probably open an issue in the repo today.

bassamsdata avatar Feb 19 '24 17:02 bassamsdata

  1. The option to colorize the output was introduced in 2015 (you can search for "hl_term" in the log of commits), but perhaps it is configured in Nvim-R in such a way that becomes disabled on your system.

Note: only in Neovim. Vim never implemented syntax highlighting of the terminal.

jalvesaq avatar Feb 19 '24 18:02 jalvesaq