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

nvim-r does not work with gui MacVim #42

Closed
songcai opened this issue Mar 21, 2016 · 18 comments
Closed

nvim-r does not work with gui MacVim #42

songcai opened this issue Mar 21, 2016 · 18 comments

Comments

@songcai
Copy link

songcai commented Mar 21, 2016

I am using the Nvim-R on Mac OS X El Capitan (10.11.3). It works perfectly if I use Neovim or terminal MacVim to open a .R script and send commands to R from there. However, Neovim does not work with the gui version of MaVim. The problem is described as follows:

After openning a .R file from gui MacVim, I used ",rf" to call R console. R was then opened in a separate terminal window. Now the problem started. When I tried to use any command to send code, eg, ",aa", ",rq", etc, nothing was happening in R and I cannot see any command being sent.

Not sure if this is also happening in other operating systems.

@jalvesaq
Copy link
Owner

Unless you have built MacVim yourself, it should not work. The last MacVim release includes Vim patches up to 1553, and Nvim-R requires 1579. However, you should have seen this error message:

Nvim-R requires either Neovim >= 0.1.2 or Vim >= 7.4.1579.
If using Vim, both +channel and +job features must be enabled.

@songcai
Copy link
Author

songcai commented Mar 21, 2016

Hi Jakson,

Thanks for the prompt reply.

I am using MacVim unstable 7.4.1589 (installed using brew install -HEAD macvim), and both +channel and +job features are enabled (I checked using :version command inside MacVim). I still get the above problem.

-Song

@jalvesaq
Copy link
Owner

Unfortunately, in this case, I don't know what might be wrong because I don't have access to a Mac OS X.

@songcai
Copy link
Author

songcai commented Mar 22, 2016

I tried Vim unstable + Nvim-R on my Debian stable. The gui vim (gvim) can send R commands without any problem. It seems that the problem is specific to gui MacVim. Hope someone with a Mac OS can figure it out. I will try to solve the problem as well.

@songcai
Copy link
Author

songcai commented Mar 23, 2016

Hi Jakson,

Just more information about the same problem. I know that you do not have access to Mac OS, but this information may ring a bell to you or someone else.

(1) With Gui MacVim, after I call a R console using ",rf", I cannot send other commands like ",aa", ",rq" etc. And I also cannot use other plugins that use keyboard shortcuts. For example, I have vim-surround, and typing "yss)" is supposed to put () around a line, but now it does not work after I invoked R. I also have nerdcommenter, and typing ",cc" is supposed to comment the current line; it does not work either now.

(2) I have set the mapping "vmap RDSendSelection", and "nmap RDSendLine" in my .vimrc. Now the magic is that the space bar still works for sending commands to R, and if I send a command using space bar just once, everything goes back to normal: ",aa" works now, and all other plugins work again. This is a mystery.

I think it might be a bug in nvimcom.

Hopefully the above phenomena provide you with some useful information.

Cheers,
-Song

@jalvesaq
Copy link
Owner

It looks like the channel is waiting for input, and somewhat blocking input from the keyboard. When the first command in the R Console is executed successfully, nvimcom sends a message to Vim telling Vim to update the syntax highlight of functions. You can see this if you put in your .Rprofile:

options(nvimcom.verbose = 4)

Then, after starting R, type in the R terminal any valid command, such as the number 1. The output here is:

> 1
[1] 1
nvimcom_nvimclient(FillRLibList()): '10101' (10101)

@songcai
Copy link
Author

songcai commented Mar 24, 2016

I tried that. With gui MacVim, I got

nvimcom 0.9.14 loaded
NVIMR_TMPDIR = /var/folders/mh/v1yyk3sx4nn831fqs_wsynch0000gn/T/Nvim-R-scai
NVIMR_ID = LffBOpXy6Mv8U0R5qZSg
nvimcom port: 10001

nvimcom_eval_expr: 'nvimcom:::nvim.buildomnils('nvimcom')'
nvimcom R: No need to build omnils: nvimcom 0.9-14
... ...
nvimcom_eval_expr: 'nvimcom:::nvim.buildomnils('base')'
nvimcom R: No need to build omnils: base 3.2.4

then it is stuck there. And Vim is using 160% of CPU. If I type 1 in R console, it gives me
1
[1] 1
I think this is not the supposed behaviour.

When using terminal MacVim I got

... ...
nvimcom_eval_expr: 'nvimcom:::nvim.buildomnils('base')'
nvimcom R: No need to build omnils: base 3.2.4
nvimcom Received: [1] 10101

If I type 1 in R console, I get
1
[1] 1
nvimcom_nvimclient(FillRLibList()): '10101' (10101)

This looks like the right behaviour.

@jalvesaq
Copy link
Owner

The terminal MacVim seems to be OK. What is missing in gui MacVim is

nvimcom Received: [1] 10101

which means that the nclientserver (started by Nvim-R with job_start() function) is running, and Nvim-R has sent its port number to nvimcom. The message FillRLibList() is sent from nvimcom to Nvim-R only when nvimcom knows the clientserver port.
That is, it looks like the +channel and +job features are not working properly in the gui MacVim.

What is the output of

:echo rplugin_jobs

after R is started (in both terminal and gui MacVim)?

@songcai
Copy link
Author

songcai commented Mar 24, 2016

The output in terminal MacVim is

{'R': 'no', 'Terminal emulator': channel 0 closed, 'ClientServer': channel 1 open}

The output in gui MacVim is

{'R': 'no', 'Terminal emulator': channel 0 open, 'ClientServer': channel 1 open}

@jalvesaq
Copy link
Owner

The clientserver application is running in both. The problem seems to be the Terminal emulator job. What happens if you put this in your vimrc?:

let R_silent_term = 1

This will switch to the old code that was already used in the Vim-R-plugin, but which I also don't know if works with gui MacVim.

@songcai
Copy link
Author

songcai commented Mar 24, 2016

If I do that, the problem persists and the output of :echo rplugin_jobs is

{'R': 'no', 'Terminal emulator': 'no', 'ClientServer': channel 0 open}

@jalvesaq
Copy link
Owner

Conclusion: the problem is in the nclientserver running as a job. Since the code works on Linux and even on terminal MacVim, I guess the bug is some kind of undue interaction between the +channel feature and gui MacVim. Perhaps you should report the bug to the MacVim developer.

@songcai
Copy link
Author

songcai commented Mar 24, 2016

Many thanks for your help, Jakson. I totally agree with your conclusion, and will bring this to the MacVim developer.

@jalvesaq
Copy link
Owner

It seems the bugs in MacVim were fixed:
macvim-dev/macvim#281
macvim-dev/macvim#283
Can anyone check if Nvim-R is working on MacVim now, please?

@songcai
Copy link
Author

songcai commented May 21, 2016

I confirm that Nvim-R is working on MacVim 7.4.1831. However I sometimes (not always) get the following error message after I send some code to R:
"E119: Not enough arguments for function: ROnJobExit "

Cheers,
-Song

@jalvesaq
Copy link
Owner

I believe it is fixed now: 3c76c67

@songcai
Copy link
Author

songcai commented May 21, 2016

Yes, Jakson. It fixes the issue. Many thanks.
If you need someone to test on a Mac in the future, I would be glad to help

@jalvesaq
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants