File Exchange

image thumbnail

Edit .m files in Emacs

version (2.03 KB) by

A major mode for editing .m files under GNU-emacs

40 Ratings



View License

Documentation on downloading a major mode for editing .m files under GNU-Emacs.
This project is managed on SourceForge.

Comments and Ratings (45)


Kevin (view profile)

I like this a lot but here is a bug report:

Emacs locks up when trying to tab in a Matlab file which contains a content with the word 'for' in the comment. Ctrl-g breaks out of the loop.


Jerry (view profile)

Can I fold or imenu section(%%) in .m file by emacs?


David (view profile)


coyboy (view profile)

Can anyone help me? Please send me a copy of file "matlab.el". There is some unknown problem for me to download from sourceforge net. I currently use old version. I want to try new.
Thank you!

Rob Campbell

Rob Campbell (view profile)

Good stuff!! I couldn't manage without this because I'm so much faster in emacs. However, I must agree with those who say that this is currently lacking features compared to the Mathworks editor.

mark p

mark p (view profile)

I got the debugger working somewhat by loading the matlab-shell and calling "dbstop". Emacs shows an arrow at the line of code I'm currently stopped at. I was wondering:
1) Can emacs display where my breakpoints are?
2) Is it possible to set/remove breakpoints from emacs instead of having to type dbstop/dbclear?
3) Is there anyway to step code with a single key in emacs? (like f-10) rather than having to type 'dbstep' every time in the matlab portion of the window?


Scott Otterson

This mode is very good, but I'm afraid it's falling behind the evolution of the Matlab language.

I'm a rabid emacs user so I still use matlab.el, but I'm also experimenting with the emacs keybindings in the Matlab desktop. On the desktop, code highlighting and indenting work correctly, and there's an up-to-date debugger interface. On the other hand, many emacs key combinations are missing -- for just cranking out code, emacs/matlab.el is faster, at least for me.

I haven't yet decided which environment is more productive overall.

huy pham

I need help with this. When i try to launch matlab from emacs, it would not work. I think the load-path was not set up properly. Where can I go to edit it?

x y

Chethan P

i do love this mode and use it every day. it would be wonderful to see support for object oriented programming in the indentation blocks (class, methods, properties, having functions indented inside a class definition, etc). right now as far as i can tell declaring a function resets the overall indentation, so a function inside a class kind of screws everything up.

thanks for this, it's great.

Ike Stoddard

I love it, and am grateful. In the spirit of cooperative improvement, I submit:
Bug Report, v2.3.1 in Unix (OSF1 V5.1 2650 alpha; XEmacs 21.1; May 1999) or Linux(GNU Emacs 21.3.1 (i386-redhat-linux-gnu, X toolkit, Xaw3d scroll bars) of 2003-05-22 on
Strings of '%' (e.g., used as boxes or separators) cause CPU looping. ^G terminates. Need to avoid the looping in the first place.
Also: fails to indent properly after comment lines as previously reported.

John Murphy

I have been using this for some time now and think that it is great. It is too bad that the native matlab editor cannot do a better job with its emacs emulation, as switching between the two for debug can be tiresome. Thank you for making this available.

Bjørn-Helge Mevik

I have the same problem as reported by Alexey Koloydenko. The script that starts matlab (for me: /opt/matlab/bin/matlab), uses exec when starting the binary, and Emacs' start-process (which is used by comint, which is used by matlab-shell) doesn't seem to like that. Creating a script that runs
/opt/matlab/bin/matlab "$@"
works perfectly, while
exec /opt/matlab/bin/matlab "$@"
gives the "hangup"-message. (The "$@" is just so matlab-shell can pass arguments (e.g. -nodesktop) to the program.)

(I have no idea whether this is a problem with Emacs' start-process or the Matlab binary.)

Alexey Koloydenko

Versions 2.3.1 and 3.0.1:
For some reason, I can only get the shell to work if I create an executable file containing the appropriate command (e.g. on my machine: /usr/local/bin/matlab -nodesktop -nojvm) and refer the matlab-shell-command variable to that file. Going directly fails with either '' M-Shell hangup'' (with the default matlab-shell-command variable provided by matlab.el) or with ''Can't exec program: /usr/local/bin/matlab -nodesktop -nojvm'' with '(matlab-shell-command "/usr/local/bin/matlab -nodesktop -nojvm"). Otherwise, I have been happily using this resource for several years.

Dai Stevei

Maybe I have the problem
I went through the source code of matlab.el version 2.3.1 with 2.2.3, and found the difference between two:
>in matlab.el v2.2.3 line 3659, the code is : comint-prompt-regexp "^K?>> *"
>but in v2.3.1 or higher ,the code is :comint-prompt-regexp "^\\(K\\|EDU\\)?>> *"
>I guess it maybe the problem, so I revised the source code of the version 2.3.1,and it works! then I tried the version 2.3.2 and version 3.0.1, It works in v2.3.2,but failed in 3.0.1.

Dai Stevei

There are bugs in matlab.el version higher than 2.3.1, because it can't not work correctly in windows xp, but works correctly in linux

the problem is:when lauch matlab-shell(the matlab-shell works correctly on cmd.ext),there are infinitly "<<",then the matlabshell cann't stop,always display "<<", so the whole screen is "<<<<<<<<<<<<<<<<<<<<<<<<<<...",and the buffer size is grow larger and larger, I don't kown why, but the matlab.el verson 2.2.3 works correctly

Jani Lahtinen

The matlab-shell fails to work with (R14) Service Pack 3 and GNU Emacs 21.3.1. When starting with M-x matlab-shell the result is "M-Shell hangup"! The variable in the line 82 from matlab-shell-command-swithes should be matlab-shell-command-switches -Add the notable 'c'!

Tom Toth

Hangs after multiple comment lines if they're at the beginning of the .m file.
I like the many configuration options.

Ted Catchpole

Yeah Right

Matthias Habl

When having two or more consecutive comment lines, pressing <enter> causes Emacs to hang. Fortunately C-g can break this infinite loop.

Yossi Farjoun

Better than the Matlab editor IMHO.

One (tiny) bug I found: if you have a variable named 'end_something' and you have a block like so:

if a>b
   end_something =0;

the indentation doesn't work properly.


Matyas Sustik

Indentation does not work after a comment line.
The default indentation is 2 while in the GUI it is 4. Otherwise it is of great help! Thank you very much!

Zhiheng Cao

Emacs gives me an error when I try byte-compile-file:

Compiling file /home/polaris/cao/matlab/matlab.el at Mon Jan 3 17:45:47 2005
  ** reference to free variable matlab-eei-process
While compiling matlab-mode:
  ** assignment to free variable add-log-current-defun-function
While compiling toplevel forms:
  !! Invalid read syntax ((")"))

Ben J

Very nice!

Max Lin

Steve Badelt

For more "modern" implementations of matlab, with the Java interface, you may want to modify the following in the .el file:

(defcustom matlab-shell-command-switches ""


(defcustom matlab-shell-command-switches "-nodesktop"

the same can be directly edited in the .elc file if you have it.

Stephen L.

First off, thanks for making this available. One fix that I think is needed: When you insert a function from the menu, the name of the function (in caps), should be right next to the percent sign. There should not be a space.

Other then that, thank you for making this available.

Hirak Parikh

Make sure that you put the .el file in the
 /lisp folder wherever EMACS is stored or atleast add the path in the .emacs file

Dave Lin

Thanks so much for making this available. I've always found MATLAB's built-in editor somewhat annoying, and you've liberated us from that.

Masahiko Mizuno

It is good for me to program on UNIX.

Jerry Chen

good work....with a little typo in the comment:
it should be :
(setq matlab-shell-command-switches '("-nojvm"))
instead of
(setq matlab-shell-command-swithes '("-nojvm"))

Josiah Yoder

Thanks... for those addicted to the many tools in emacs like me, this is great! It was easy to get working, too!

Damiano Cozza

Only can say: "...thanks!"

Stephan Weiss

Many thanks - this is really great help!

Satya Mishra

Matlab-mode brings the power of emacs and the power of matlab-engine together to build a great software. Matlab's own GUI is a pale attempt at making something useful.

Edward Grace

Far better than the Matlab editor!

Wolfgang Brandhuber

Thanks for that emacs-mode.
It really helps a lot.

Kaoru Amano

Pete Watkins

Awesome: The emacs mode is a very convenient way to use matlab

Bjorn Gustavsson

.....but I still have to come up with the

Shai Ayal

Jody Klymak

Excellent mode - works well in Gnu/X Emacs. Prompt support via mailing list.


Updated license


Remove file under GPL, replace with documentation under BSD license.

Fix some bugs

Fix some bugs

Version 2.3 of matlab.el

Need to have this link

MATLAB Release
MATLAB 5.2 (R10)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video