Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For all it's shortcomings, I usually prefer to work inside the Matlab IDE, rather than in an external editor (due to ease of debugging, running and so on).

However sometimes I want to open the current file in an external text editor. I can do: r-click file tab; show in Finder; open file in editor, but that is really too much for most occasions.

What I want is to assign an external editor that could be launched with the currently selected file.

Is there a built-in way to accomplish this?

If not, is the Matlab IDE itself scriptable, so I could write a script that could then be assigned a shortcut?

(discalimer: I have googled - didn't find anything)

share|improve this question

3 Answers 3

up vote 1 down vote accepted

Thanks to Vincent for putting me on to system. My solution is mostly for me (so no fancyness), but feel free to adapt to your editor of choice.

Edit: Note that this solution incorporates undocumented functionality. If I recall correctly, matlab.desktop.editor.getActive().Filename; works from about 2009 and at least works in 2013a on OSX

function subl(varargin)
% Opens the currently active tab of the matlab editor in sublime text
% (assuming OSX, and that subl is found on the system $PATH).
% Adam Andersen Læssøe; Feb. 2014.
%
% Input: 
%    varagin{1} (if supplied) is passed directly to the subl call as a string 
%    for a list of args see eg. www.sublimetext.com/docs/3/osx_command_line.html
% Result: 
%    (). subl is called with the args followed by the path to the currently
%    active file in the matlab editor. 
% Example usage: (opens the currently active editor tab in sublime text in
%                 a new window)
%    subl -n

file = matlab.desktop.editor.getActive().Filename;
if nargin 
    args = varargin{1};
else 
    args = '';
end
%args = '';
system(['subl ', args, ' ', file]);
share|improve this answer

You could open the file from matlab with the macopen function (or if you are on windows: winopen):

function macopen(file)
% Opens a file or directory, as if executing at the Terminal
% Manu Raghavan
% August 19, 2009

if(nargin==0 || nargin>1 || ~ischar(file))
    error('Please specify at one input argument, file or directory, to be opened');
end

if(~ismac)
    if(ispc)
        error('macopen does not work on Windows, use winopen instead');
    else
        error('macopen does not work on other operating systems');
    end
end

system(['open ',file]);

source: http://www.mathworks.com/matlabcentral/fileexchange/25080-macopen/content/macopen.m author: http://www.mathworks.com/matlabcentral/fileexchange/authors/31269

share|improve this answer
    
Thank you Vincent, but that would require me to type out the whole filename. Thank you for the macopen, though. That could be part of a viable solution. Is there a command to get the (file of the) currently active tab? That could be easily combined with macopen in, say, exto. –  AdamAL Feb 1 '14 at 22:31
    
Not that easy to find, but here it is (gets full path): matlab.desktop.editor.getActive().Filename –  AdamAL Feb 1 '14 at 22:47

You could run a editor in the operating system from the matlab command line.

Something like

     !emacs filename.m
share|improve this answer
    
The filename should autocomplete. –  Chogg Mar 13 '14 at 8:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.