GNU-devel ELPA - matlab-mode

matlab-mode Atom Feed

Description
Major mode for MATLAB(R) dot-m files
Latest
matlab-mode-8.1.2.0.20260315.82315.tar (.sig), 2026-Mar-17, 11.9 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:

  1. MATLAB mode, matlab-ts-mode or matlab-mode, for editing *.m files.

    • 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.

  2. Code navigation and more
  3. 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.

    See doc/matlab-shell-for-unix.org

  4. 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.

  5. 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              |         |                                  |
    +--------------------------------------+         +----------------------------------+
    
  6. Code sections support for MATLAB script files. See doc/matlab-code-sections.org.
  7. 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 *.org files. When you evaluate MATLAB or other language code blocks within the *.org files, org inserts the results back into the *.org file.
    • You can combine multiple *.org files 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.
  8. tlc-mode for editing *.tlc files. 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

  1. 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

  2. [Optional] Install the company package which is used for TAB completions.

    M-x package-install RET company RET
    
  3. [Optional] Install MATLAB tree-sitter for matlab-ts-mode, which provides improved editing capabilities and improved performance.

    After installing matlab-mode

    M-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.

    See doc/install-matlab-tree-sitter-grammar.org

  4. [Optional] Install lsp-mode and the MATLAB Language Server for an improved editing capabilities. Code navigation: jump to definition and back, find references, and rename symbols. Also provides improved MATLAB code analyzer (mlint) message interaction.
  5. [Optional] Check your installation setup.

    If you are using matlab-ts-mode, visit a *.m MATLAB 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.

6. Community Support

7. FAQ

9. Releases

See NEWS.org

Old versions

matlab-mode-8.1.1.0.20260304.181347.tar.lz2026-Mar-041.16 MiB
matlab-mode-8.1.1.0.20260301.212548.tar.lz2026-Mar-021.16 MiB
matlab-mode-8.1.1.0.20260228.124833.tar.lz2026-Feb-281.16 MiB
matlab-mode-8.1.1.0.20260224.73923.tar.lz2026-Feb-241.16 MiB
matlab-mode-8.1.1.0.20260223.151811.tar.lz2026-Feb-231.16 MiB
matlab-mode-8.1.1.0.20260222.163125.tar.lz2026-Feb-231.16 MiB
matlab-mode-8.1.1.0.20260222.105350.tar.lz2026-Feb-221.16 MiB
matlab-mode-8.1.0.0.20260219.101835.tar.lz2026-Feb-191.15 MiB
matlab-mode-8.0.5.0.20260214.160329.tar.lz2026-Feb-151.15 MiB
matlab-mode-8.0.4.0.20260214.155353.tar.lz2026-Feb-141.15 MiB
matlab-mode-8.0.4.0.20260208.80458.tar.lz2026-Feb-081.15 MiB
matlab-mode-8.0.3.0.20260204.141939.tar.lz2026-Feb-041.15 MiB
matlab-mode-8.0.2.0.20260201.144945.tar.lz2026-Feb-031.15 MiB
matlab-mode-8.0.1.0.20260130.94305.tar.lz2026-Jan-301.15 MiB
matlab-mode-8.0.0.0.20260129.101144.tar.lz2026-Jan-291.15 MiB
matlab-mode-7.4.2.0.20251229.125049.tar.lz2025-Dec-291.14 MiB
matlab-mode-6.3.0.20250607.211810.tar.lz2025-Jun-08 155 KiB

News

1. Release 8.1.2 Mar-15-2026

  1. matlab-ts-mode: improved performance of electric indent.

    Previously we were using (treesit-node-at (point)) to obtain the language elements to indent. Now we use treesit-capture-query which is faster.

    This is the first step in speeding up electric indent. Future possible optimizations include using symbols from the treesit-capture for language element identification rather than treesit-node-type, simplification of matrix alignment and the other alignments, additional removal of treesit-node-at, etc.

  2. matlab-ts-mode: fixed trailing comment alignment problems.

    Now we only align consecutive statements when in same scope. For example, first comment below is in a different scope so not aligned with the last two comments:

    fooBarGooToo = [something, ...
                    [otherThing(wIndex) : theEndIndex(wIndex) - 1, ...
                     otherThing(wIndex) + 1 : theEndIndex(wIndex); ...
                     otherThing(wIndex) + 1 : theEndIndex(wIndex), ...
                     otherThing(wIndex) : theEndIndex(wIndex) - 1]]; %#ok<AGROW>
    P0 = [P0, foo.blah{wIndex}.foobarGooOrig(:, 1 : end - 1)]; %#ok<AGROW>
    P1 = [P1, foo.blah{wIndex}.foobarGooOrig(:, 2 : end)];     %#ok<AGROW>
    
  3. matlab-ts-mode: when using keywords (end, arguments, etc.) as variables or functions, they now indent correctly. Note, MATLAB allows end.m, arguments = 10, etc.
  4. matlab-ts-mode: An ellipsis at start of file no longer causes a hang
  5. matlab-shell: add matlab-shell-before-start-hook
  6. matlab-shell: hyperlink syntax error

2. Release 8.1.1 Feb-22-2026

  1. Enable matlab-ts-mode with Emacs 30.2 which is using tree-sitter ABI 15 (or 14). Note, Emacs 30.1 is using tree-sitter ABI 14 which continues to work.
  2. Update installation instructions for the MATLAB Language Server
  3. Fix mlint.el issue ("Do not permit multiple groups with the same name")

3. Release 8.1.0 Feb-16-2026

  1. The behavior of TAB and RET in matlab-ts-mode to electric indent/code-format adjacent lines of code. There is no change in the indent/code-format rules. The goal of this change is to improve editing interactions with the MATLAB indent/code-format engine.
  • TAB behavior example. Given

    a = 1;
    foo = 2;
    foobar = 3;
    

    A TAB on any these code lines results in:

    a      = 1;
    foo    = 2;
    foobar = 3;
    
  • RET behavior example. Given

    v1=1;
    var2= [1,1];
    

    Typing the 4 characters, x=3;, on the 3rd line (without typing RET) gives us:

    v1=1;
    var2= [1,1];
    x=3;
    

    When we type the RET, we get:

    v1   = 1;
    var2 = [1, 1];
    x    = 3;
    
    

    Now, if we type a RET at the end of the 2nd line, we get the following. Notice that the alignment of x assignment has changed.

    v1   = 1;
    var2 = [1, 1];
    
    x = 3;
    
    
  1. An "electric ends" edge case issues in matlab-ts-mode has been fixed. When typing a statement that is terminated by an end, e.g. "if", "function", "classdef", etc. the "end" keyword is automatically added for you. For example, given:

    if a
    

    typing RET at the end of the "if a" line results in:

    if a
    
    end
    

    where the point is left on the 2nd line, indented to 4 spaces.

    There were some edge cases where an end-statement was being incorrectly inserted. This primarily occurred with continued (ellipsis) conditions following the "if" and similar statements. For example, given the following, typing RET at the end of the first line will not add an end-statement

… …