matlab-mode 
- Description
- Major mode for MATLAB(R) dot-m files
- Latest
- matlab-mode-8.0.1.tar (.sig), 2026-Jan-30, 11.8 MiB
- Maintainer
- Eric M. Ludlam <eludlam@mathworks.com>, Uwe Brauer <oub@mat.ucm.es>, John Ciolfi <john.ciolfi.32@gmail.com>
- Website
- https://github.com/mathworks/Emacs-MATLAB-Mode
- Browse ELPA's repository
- CGit or Gitweb
- Badge
To install this package from Emacs, use package-install or list-packages.
Full description
1. Emacs MATLAB-mode
MathWorks MATLAB® and GNU Emacs integration:
MATLAB mode, matlab-ts-mode or matlab-mode, for editing
*.mfiles.- Edit MATLAB code with syntax highlighting, indentation (code formatting), and semantic movement.
- Lint MATLAB code with fix-it's using the MATLAB Code Analyzer.
The matlab-ts-mode is a more capable, performant, and accurate than matlab-mode.
- Code navigation and more
- The MATLAB Language Server with Emacs, matlabls, provides code navigation, code completion, go to definition, find references, and more.
- Imenu support for quickly jumping to function declarations in the current
*.mor*.tlcfile. See doc/matlab-imenu.org.
M-x matlab-shell for running and debugging MATLAB within Emacs (Unix only).
- MATLAB command window errors are hyper-linked and files open in Emacs
- Debugging support is available from the MATLAB menu.
- matlab-shell uses company-mode for completions.
M-x matlab-shell to run remote Unix MATLAB within your local Emacs session.
+----------------+ +-----------------+ | Local Computer | | Remote Computer | | |<===============>| | | Emacs | ssh | MATLAB | +----------------+ +-----------------+
You use Emacs on your local computer to edit files on the remote computer, run and debug remote MATLAB in a matlab-shell in your local Emacs. See doc/remote-matlab-shell.org.
M-x matlab-netshell for running MATLAB code on Microsoft Windows within Emacs using an attached MATLAB.
+--------------- Emacs ----------------+ +------------ MATLAB ------------+ | | | | | (1) M-x matlab-netshell-server-start | | (2) connect to Emacs | | |<=======>| >> addpath <matlab-mode>/toolbox | | (3) Visit script *.m files and use | | >> emacsinit | | "MATLAB -> Code Sections" menu | | >> | | or the key bindings | | | +--------------------------------------+ +----------------------------------+
- Code sections support for MATLAB script files. See doc/matlab-code-sections.org.
- After visiting a MATLAB script, you have a "MATLAB -> Code Sections" menu and key bindings which lets you navigate, run, and move code sections.
- Try out code sections using: ./examples/matlab-sections/tryoutmatlabsection.m.
- Creation of scientific papers, theses, and documents using MATLAB and http://orgmode.org.
- Org enables literate programming which directly supports reproducible research by allowing scientists and engineers to write code along with detailed explanations in natural language.
- You author code plus natural language descriptive text in
*.orgfiles. When you evaluate MATLAB or other language code blocks within the*.orgfiles, org inserts the results back into the*.orgfile. - You can combine multiple
*.orgfiles into one final document, thus enabling larger scientific documents. - See ./examples/matlab-and-org-mode/ to get started. This directory contains a PDF generated from ./examples/matlab-and-org-mode/matlab-and-org-mode.org.
- tlc-mode for editing
*.tlcfiles. The Target Language Compiler (TLC) is part of Simulink® Coder™.
2. MATLAB Indent (Code Formatting)
With the optional matlab-ts-mode, you have MATLAB code indentation that
- Adjusts the indent-level (the whitespace to the left of the code), and
- Standardizes language element spacing, aligns consecutive statements, aligns matrices and structs, adds missing commas to matrices.
Example:
function out= indent_example( in1, ...
input2)
% INDENT_EXAMPLE - an indent example
% This illustrates some of the capabilities of the matlab-ts-mode indent engine.
arguments
in1 = 10
input2= 20;
end
mat = [100,2 300.2
3 400,4];
s = struct( 'f1',1, ...
'otherField', in1+input2);
a = 10; % comment for a
bLongVariable = [1.3 2,3 1 - 1 -1] ;% comment for b
cVar = a+bLongVariable * 2;
if abs(sum(in1)) > 0
out=s.f1/input2+ in1 -cVar;
else
out = mat+in1 * 2 -cVar;
end
end
Is indented to the following using C-x h and then C-M-\ (or Edit -> Select All, then M-x
indent-region). Notice that in addition to adjusting the indent-level (whitespace to the left),
language element spacing has been standardized, statements have been aligned, trailing comments have
been aligned matrices have been aligned, missing comma's are added to arrays, struct fields are
aligned, etc.
function out = indent_example(in1, ...
input2)
% INDENT_EXAMPLE - an indent example
% This illustrates some of the capabilities of the matlab-ts-mode indent engine.
arguments
in1 = 10
input2 = 20;
end
mat = [100, 2, 300.2
3, 400, 4];
s = struct('f1' , 1, ...
'otherField', in1 + input2);
a = 10; % comment for a
bLongVariable = [1.3, 2, 3, 1 - 1, -1]; % comment for b
cVar = a + bLongVariable * 2;
if abs(sum(in1)) > 0
out = s.f1 / input2 + in1 - cVar;
else
out = mat + in1 * 2 - cVar;
end
end
3. Installation
Install the MATLAB package via MELPA or ELPA. MELPA contains the latest version. To install from MELPA, add to your
~/.emacs(require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)Restart Emacs and then
M-x package-install RET matlab-mode RET
Note: to see all available packages,
M-x RET list-packages RET[Optional] Install the
companypackage which is used for TAB completions.M-x package-install RET company RET
[Optional] Install MATLAB tree-sitter for matlab-ts-mode, which provides improved editing capabilities and improved performance.
After installing
matlab-modeM-x matlab-ts-grammar-install
The MATLAB tree-sitter leverages Tree-sitter to create a parse tree for MATLAB code. The parse tree is updated incrementally and is robust to syntax errors. It is highly performant and achieves this by being implemented in C to create a shared object that is loaded into the Emacs process. matlab-ts-mode leverages the MATLAB tree-sitter to give an improved MATLAB editing experience when compared with matlab-mode.
- [Optional] Install lsp-mode and the MATLAB Language Server for an improved editing experience.
[Optional] Check your installation setup.
If you are using matlab-ts-mode, visit a
*.mMATLAB file and select the menu item:MATLAB -> Check setup
3.1. Install from this repository
If you are contributing to the Emacs MATLAB Mode package, see contributing/install-emacs-matlab-from-git.org
4. MathWorks Products (https://www.mathworks.com)
Emacs MATLAB-mode is designed to be compatible with the last six years of MathWorks products and may support even older versions of MathWorks products.
5. License
6. Community Support
7. FAQ
See doc/faq.org
8. Mailing list
9. Releases
See NEWS.org
Old versions
| matlab-mode-8.0.0.tar.lz | 2026-Jan-29 | 1.14 MiB |
| matlab-mode-8.0.0.tar | 2026-Jan-29 | 11.8 MiB |
| matlab-mode-7.4.2.tar.lz | 2025-Dec-29 | 1.14 MiB |
| matlab-mode-7.4.2.tar | 2025-Dec-29 | 11.7 MiB |
| matlab-mode-7.4.1.tar.lz | 2025-Nov-26 | 1.14 MiB |
| matlab-mode-7.4.0.tar.lz | 2025-Nov-26 | 1.13 MiB |
| matlab-mode-7.3.4.tar.lz | 2025-Nov-25 | 1.13 MiB |
| matlab-mode-7.3.3.tar.lz | 2025-Nov-23 | 1.13 MiB |
| matlab-mode-7.3.2.tar.lz | 2025-Nov-22 | 1.13 MiB |
| matlab-mode-7.3.1.tar.lz | 2025-Nov-14 | 1.13 MiB |
| matlab-mode-7.3.0.tar.lz | 2025-Nov-12 | 1.13 MiB |
| matlab-mode-7.2.1.tar.lz | 2025-Oct-30 | 1.13 MiB |
| matlab-mode-7.2.0.tar.lz | 2025-Oct-30 | 1.13 MiB |
| matlab-mode-7.1.2.tar.lz | 2025-Oct-17 | 1.13 MiB |
| matlab-mode-7.1.1.tar.lz | 2025-Oct-01 | 1.13 MiB |
| matlab-mode-7.1.0.tar.lz | 2025-Sep-29 | 1.13 MiB |
| matlab-mode-6.3.tar.lz | 2024-Dec-08 | 160 KiB |
News
1. Release 8.0.1 Jan-30-2026
Minor electric indent fix to correct comma placement in struct field alignment and also to fix non-positional name = value arguments and attributes.
2. Release 8.0.0 Jan-29-2026
This release updates matlab-ts-mode indent to electric indent code. This is sometimes called pretty printing code or formatting code.
To indent a MATLAB *.m file,
C-x h or M-: (mark-whole-buffer) C-M-\ or M-x indent-region
See doc/matlab-code-indent.org - MATLAB Indent (Code Format)
3. Release 7.4.2 Dec 29, 2025
Fix bug in tramp (remote) matlab-shell when matlab is installed in a custom location.
4. Release 7.4.1 Nov 26, 2025
Fix indent bug. In following typing RET after the argument end statement, the indent now goes to the 4th column and not the 8th column:
function test(A) arguments A end end
5. Release 7.4.0 Nov 26, 2025
- Place the
matlab-*-facedefinitions in customize matlab-ts-faces group. Add
M-x matlab-ts-describe-facesalong with menu itemMATLAB -> Describe faces
that will bring up a help buffer containing the faces used by matlab-ts-mode. From there you can customize them. This differs from viewing the matlab-ts-faces group in that it contains both matlab-*-faces plus other built-in faces such as font-lock-type-face. This help buffer also contain more information on when the faces are used.
6. Release 7.3.4 Nov 25, 2025
- Add the source and build instructions for the libtree-sitter-matlab.SLIBEXT binaries
found in ./matlab-ts-bin and used by
M-x matlab-ts-grammar-install.
7. Release 7.3.3 Nov 23, 2025
- Update to latest https://github.com/acristoffers/tree-sitter-matlab which improves matlab-ts-mode: matlab-ts-abi14-20251122-90ce9da
8. Release 7.3.2 Nov 21, 2025
- Update to latest https://github.com/acristoffers/tree-sitter-matlab which improves matlab-ts-mode. The changes fix parsing errors up through issues 141 in matlab tree-sitter.
9. Release 7.3.1 Nov 14, 2025
- Fixed M-q (fill-paragraph) in comments when there no space after the '%' character.
- Improved t-utils-view-parse-tree
- Made matlab-ts-mode show-paren-mode robust to extra
\nnodes
10. Release 7.3.0 Nov 12, 2025
- Updated matlab-ts-mode to work with tree-sitter-matlab commit 9d16fcf. This fixes many known issues in matlab-ts-mode.
- Simplified the install of the matlab tree-sitter grammar shared libraries. To enable matlab-ts-mode
you install
matlab-modeand thenM-x matlab-ts-grammar-install.
11. Release 7.2.1 Oct 30, 2025
- In matlab-ts-mode, fix indent involving catch clause with a comment.
12. Release 7.2.0 Oct 29, 2025
- Updated matlab-ts-mode to use latest matlab tree-sitter v1.2.3 branch abi/14 at 9a4e65d. This fixes parse on a number of MATLAB language constructs, which is visible behavior improvements, so bumping revision to 7.2.0.
- In matlab-ts-mode, don't offer to fix function/classdef names when there are syntax errors because this can lead to changing the name of other identifiers and not the function/classdef name.
13. Release 7.1.2 Oct 16, 2025
- matlab-is-matlab-file: This function identifies when the content of a *.m file is MATLAB code, if it's not MATLAB code, Emacs defaults to Objective-C. This fixes a case where a *.m contains MATLAB code and the first line is a @functionhandle.
14. Release 7.1.1 Oct 1, 2025
- matlab-ts-mode: fix semantic movement in strings. Now C-M-f, C-M-b, C-M-SPC work when point is within strings.
15. Release 7.1.0 Sep 29, 2025
- Improved matlab-ts-mode imenu. The imenu index now creates indices for code sections defined by
… …