GNU ELPA - matlab-mode

matlab-mode Atom Feed

Description
major mode for MATLAB(R) dot-m files
Latest
matlab-mode-6.3.tar (.sig), 2024-Dec-08, 780 KiB
Maintainer
Eric M. Ludlam <eludlam@mathworks.com>, Uwe Brauer <oub@mat.ucm.es>
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 for editing *.m files.
    • Edit MATLAB code with syntax highlighting and smart indentation.
    • Lint MATLAB code with fix-it's using the MATLAB Code Analyzer.
  2. M-x matlab-shell for running and debugging MATLAB within Emacs (Unix-only).
    • matlab-shell uses company-mode for completions.
  3. MATLAB and http://orgmode.org for creation of scientific papers, theses, and documents.
    • 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.
  4. tlc-mode for editing *.tlc files. The Target Language Compiler (TLC) is part of Simulink® Coder™.

2. Installation

2.1. Install via MELPA

Installing via MELPA is recommended because MELPA will contain the latest validated release.

Add to your ~/.emacs:

(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)

then run

M-x RET package-list-packages RET

2.2. Install from this repository

Build:

cd /path/to/Emacs-MATLAB-mode

# Build lisp and run tests (requires MATLAB executable):
make
# Alternatively, build lisp and run tests using a specific MATLAB executable:
make MATLAB_EXE=/path/to/matlab

# If desired, you can separate the building of lisp and running tests using:
make lisp
make tests
make tests MATLAB_EXE=/path/to/matlab # if using a specific MATLAB executable

Add the following to your ~/.emacs file:

(add-to-list 'load-path "/path/to/Emacs-MATLAB-mode")
(load-library "matlab-autoload")

3. 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. Community Support

6. FAQ

6.1. How do I customize matlab-mode?

You can configure matlab-emacs using the "matlab" or "matlab-shell" customization groups:

Emacs -> Options -> Customize Emacs -> Specific Group

6.2. How do I customize "edit file.m" behavior?

By default when you run

M-x matlab-shell

>> edit file.m

file.m will open in emacs using 'emacsclient -n'. matlab-shell achieve this behavior by instructing MATLAB to use 'emacsclient -n' as the external text editor.

You can customize this by setting `matlab-shell-emacsclient-command' in the matlab-shell customization group. You can change this command to what's appropriate. If you set it to the empty string, 'edit file.m' will use the default MATLAB editor setting.

The default MATLAB editor setting is controlled in the MATLAB preferences, (e.g. R2018a Home tab, Environment section, Preferences) where you can select which editor you want to edit a text file. MATLAB Editor or an external text editor. If you always want to use Emacs as your matlab editor even when running MATLAB outside of emacs, select Text editor and set it to the appropriate 'emacsclient -n' command.

6.3. The code-sections are not highlighted properly. What do I do?

There can be several reasons for this. One reason would be if you are using syntax highlighting from a different package (such as tree-sitter) which is over-riding the font-lock provided by matlab-mode.

In this case, add the following hook to your config:

(add-hook 'matlab-sections-mode-hook
	(lambda () (interactive)
	    (font-lock-add-keywords
	   nil
	   `((,matlab-sections-section-break-regexp
		1 'matlab-sections-section-break-face prepend)))
	    (font-lock-flush)))

Ensure that this is included after matlab-mode as well as your syntax highlighter are initialized in your config.

7. History

matlab-mode has a history dating back many years. Older contributions can be found in https://sourceforge.net/projects/matlab-emacs/.

News

1. Changes and New Features in matlab-emacs

1.1. New in 5.0

1.1.1. Syntax tables / Strings and Comments / Font lock

Command and String syntax handling is now managed using syntax-table customization

This results in:

  • More flavors of syntax highlighting around commands and strings, including all of:
    • strings, unterminated strings, commanddual strings
    • comments, cellbreak comments, pragma comments, ignored comments, ellipssis
  • Accurate differentiation between 'char arrays' and "strings" and quoted charts.
  • Performance improvements for comment/string parsing.

There is a new shorter 'ignore' comment type that starts with: %^

In addition, font lock of keywords is now more robust, with keywords not being highlighted when they are not being used in the correct scope.

1.1.2. Syntactic block navigation

With proper syntax table support now available, built-in emacs commands that depend on sexp now work, such as:

  • up-list
  • forward-sexp
  • kill-sexp
  • mark-sexp

In addition, commands that work with defuns now all work correctly, such as:

  • mark-defun
  • narrow-to-defun

All custom commands that used to implement these syntax behaviors have been removed, or had their bindings removed, including:

  • matlab-beginning-of-command
  • matlab-end-of-command
  • matlab-forward-sexp
  • matlab-backward-sexp
  • matlab-indent-sexp
  • matlab-beginning-of-defun
  • matlab-end-of-defn

In addition syntactic block navigation is faster, where very large files can now be navigated in fractions of a second that used to take a few minutes.

1.1.3. Support for block validation

Block navigation now does validation, for example, 'property' keywords should only occur inside a classdef, and 'arguments' keywords should only occur inside a function.

This means that you can now have variables and functions named 'property' and 'arguments' of those words occur outside valid locations.

1.1.4. Indentation

Indentation performance is greatly improved. Based on our tests, large files that used to take 10 minutes to indent will now complete in just 1 or 2 seconds.

Several new indentation features exist, such as:

  • correct indentation of arguemnts blocks
  • improved indentation of function argument lists that span multiple lines.
  • improved indentation around block comments
  • improved indentation accuracy in classdef, property, method blocks.
  • more accurate indentation of continuations

Some indentation features were removed, such as:

  • Max indent distance support inside function call args
  • Max indent distance support inside switch statements
  • Line-up rules inside ( ), [ ], and { } have changed subtly dependeing on context after the opening (, [, or {.

Specialty indentation commands have been removed:

  • matlab-indent-sexp

Electric indentation has been added to block keywords such as end, else, case, etc.

Lots of bug fixes and general improvements for handling edge cases.

1.1.5. matlab-return & friends removed

The 'matlab-return' and related functions have all been removed. Features of these commands are now part of Emacs' built in handling for RETURN and no longer need to be part of matlab mode.

1.1.6. File type detection

File type detection has been improved. Previously matlab mode detected if functions had ends, and if functions were indented. It now detects more cases, and displays results in the status line.

The list of detectable features are:

  • function (with no end)
  • function .. end
  • classdef .. end
  • scripts
  • empty files

Functions with ends also detect if function bodies are indented. Other kinds of functions will always indent.

The check for the type of file is also auto-re-detected on save, so if you change the type of file while editing, it will automatically adjust.

1.1.7. Auto verify changes

Auto verify on save has been updated.

  1. verify classname added - this will fix class names for you

… …