daeyun / vim-matlab

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

Use pexpect to manage the MATLAB console #13

Closed tdy closed 8 years ago

tdy commented 8 years ago

Now calls pexpect.spawn.interact() for full command window functionality (properly handles arrow keys, tab completion, backspace, clc, etc.). Falls back to the original sys.stdin code if pexpect isn't available.

Note a couple side effects before deciding whether to merge:

Example

tdy commented 8 years ago

Same as #12. Not sure what happened there. I must've messed up some commits accidentally.

daeyun commented 8 years ago

Thanks, this is definitely a very nice feature to add. The raw code being echoed probably has to do with send simulating actual keyboard input, and that causing the matlab console to print them out as if those keys were being pressed.

daeyun commented 8 years ago

I will accept the pull request. I think there might be a way to use pexpect.spawn.interact()'s output_filter to filter out any strings that match the ones sent to pexpect.spawn.send(). I guess that can be addressed in a different patch. (I'll try to update if I find a way).

daeyun commented 8 years ago

0f8a799 was my attempt. Hopefully this works, but there might be edge cases that I haven't checked.

tdy commented 8 years ago

Ah nice, it works for the most part.

Something weird happens with certain code though. I haven't had a chance to debug the cause, but one example is this dummy cell:

%%
magic(5)

2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;
2987.293487298 + 84.7928748123 + 234 + 234.293847293 + 39847 - 29384798 - 234.1239871;

It not only prints the raw code, but also truncates it:

>> NMITNNQHQSXI=tic;magic(5),2987.293487298 + 84.7928748123 + 234 + 234.293847293 +
39847 - 29384798 - 234.1239871;,2987.293487298 + 84.7928748123 + 234 + 234.293847293 +
39847 - 29384798 - 234.1239871;,2987.293487298 + 84.7928748123 + 234 + 234.293847293 +
39847 - 29384798 - 234.1239871;,2987.293487298 + 84.7928748123 + 234 + 234.293847293 +
39847 - 29384798 - 234.1239871;,2987.293487298 + 84.7928748123 + 234 + 234.293847293 +
39847 - 29384798 - 23

ans =

    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9

Elapsed time is 0.003924 seconds.
daeyun commented 8 years ago

Good catch, I think there was a race condition. I'm not seeing this anymore after e7ca8a44f. Let me know if you see other issues, thanks 👍 👍 looking forward to using this feature