daeyun / vim-matlab

Neovim plugin for MATLAB
Mozilla Public License 2.0
104 stars 19 forks source link

Functions inside script causing crash #26

Closed LimmaPaulus closed 6 years ago

LimmaPaulus commented 6 years ago

Hi! Thanks for this wonderful plugin, I have been seeking exactly this.

My problem is that if I write following script

hello()

function hello()
    fprintf('Hello\n');
end

and try to run it with :MatlabCliRunCell, I get error message 'Error: Illegal use of reserved keyword "end"'

However, script works well when I run it from gui or when I call it by file name on command window.

Shouldn't it save functions in separate files? It seems for me that this feature is not working. Would it be maybe more robust to create temporary file from lines to execute, and then execute this file as command?

daeyun commented 6 years ago

Hi @LimmaPaulus,

This feature requires having the following line on top of the script:

%%! vim-matlab: split(hello-world)

This will tell the plugin to save the sub-functions as separate files inside a directory named "hello-world" (or whatever you specify inside the parenthesis). And then you can use the addpath command to add that folder to matlab's exec path.

This is one of the features that I haven't tested thoroughly, so there may be some bugs.

Another way I can think of is using the run command, e.g. "run filename.m" in the console or through another script; if you simply wanted to run the entire file.

LimmaPaulus commented 6 years ago

OK, thanks. It would be nice to have command for saving and running whole script with run command, too :)