branch: externals/matlab-mode
commit 33673b5b7caf56f064108af5a39b9fadba02ac31
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-is-matlab-file: fix minor error in objective-c code identification
---
NEWS.org | 6 +++
matlab-is-matlab-file.el | 18 +++++++--
matlab-mode.el | 2 +-
matlab-ts-mode.el | 2 +-
matlab.el | 2 +-
tests/test-matlab-is-matlab-file-files/archive.zip | Bin 526 -> 1464 bytes
tests/test-matlab-is-matlab-file.el | 41 ++++++++++++++-------
7 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index b8236ed2ae..b72a0e513d 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -3,6 +3,12 @@
# Copyright (C) 2025 Free Software Foundation, Inc.
+* Release 7.1.2 Oct 16, 2025
+
+1. 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
@function_handle.
+
* Release 7.1.1 Oct 1, 2025
1. matlab-ts-mode: fix semantic movement in strings. Now C-M-f, C-M-b, C-M-SPC
work when point is
diff --git a/matlab-is-matlab-file.el b/matlab-is-matlab-file.el
index 9059bd5229..e1c4656f23 100644
--- a/matlab-is-matlab-file.el
+++ b/matlab-is-matlab-file.el
@@ -89,13 +89,25 @@ This will also enter MATLAB mode for empty files *.m files
when
;; Objective-c is identified by
;; - comment start chars: // or /*,
;; - # char (as in #import)
- ;; - @ char (as in @interface)
+ ;; - @ char (as in @interface compiler directive)
+ ;; Scope check to a list of all compiler directives that start
with an @
+ ;; character (at-directives) that can be on the first line in an
Objective-C
+ ;; file to prevent confusion with '@' syntax in matlab files. For
example,
+ ;; this is a valid MATLAB file:
+ ;; @foo;
+ ;; where @foo is a function handle.
;; MATLAB scripts are identified by the start of a valid identifier,
i.e. a letter or
;; some math operation, e.g. [1,2,3]*[1,2,3]', thus all we really need
to look for
;; is a non-whitespace character which could be a MATLAB comment,
generic MATLAB commands,
;; function/classdef, etc.
- (and (not (looking-at "^[[:space:]\n]*\\(//\\|/\\*\\|#\\|@\\)"))
- (looking-at "^[[:space:]\n]*[^[:space:]\n]"))
+ (and
+ ;; Have non-whitespace content in the buffer
+ (looking-at (rx bos (zero-or-more (any " \t\n\r")) (not (any "
\t\n\r"))))
+ ;; which is not Objective-C content
+ (not (looking-at (rx bos (zero-or-more (any " \t\n\r"))
+ (or "//" "/*" "#"
+ "@class" "@compatibility_alias"
"@implementation" "@import"
+ "@interface" "@protocol")))))
;; Empty file - enter matlab-mode based on
`matlab-mode-for-new-mfiles' setting
(and (= (buffer-size) 0)
(or (equal matlab-mode-for-new-mfiles t)
diff --git a/matlab-mode.el b/matlab-mode.el
index ac654e9485..c85bffde6b 100644
--- a/matlab-mode.el
+++ b/matlab-mode.el
@@ -1,6 +1,6 @@
;;; matlab-mode.el --- Major mode for MATLAB(R) dot-m files -*-
lexical-binding: t -*-
-;; Version: 7.1.1
+;; Version: 7.1.2
;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
;; SPDX-License-Identifier: GPL-3.0-or-later
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 03ce351c13..97d340e66e 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -1,6 +1,6 @@
;;; matlab-ts-mode.el --- MATLAB(R) Tree-Sitter Mode -*- lexical-binding: t -*-
-;; Version: 7.1.1
+;; Version: 7.1.2
;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
diff --git a/matlab.el b/matlab.el
index bf54dd24d2..944ce5c207 100644
--- a/matlab.el
+++ b/matlab.el
@@ -1,6 +1,6 @@
;;; matlab.el --- major mode for MATLAB(R) dot-m files -*- lexical-binding: t
-*-
-;; Version: 7.1.1
+;; Version: 7.1.2
;; URL: https://github.com/mathworks/Emacs-MATLAB-Mode
;; SPDX-License-Identifier: GPL-3.0-or-later
diff --git a/tests/test-matlab-is-matlab-file-files/archive.zip
b/tests/test-matlab-is-matlab-file-files/archive.zip
index 11ef8207c6..12a4d3c863 100644
Binary files a/tests/test-matlab-is-matlab-file-files/archive.zip and
b/tests/test-matlab-is-matlab-file-files/archive.zip differ
diff --git a/tests/test-matlab-is-matlab-file.el
b/tests/test-matlab-is-matlab-file.el
index 56ef1efb65..05e80b5474 100644
--- a/tests/test-matlab-is-matlab-file.el
+++ b/tests/test-matlab-is-matlab-file.el
@@ -28,12 +28,15 @@
(ert-deftest test-matlab-is-matlab-file ()
"Test `matlab-is-matlab-file'.
Using ./test-matlab-is-matlab-file-files/archive.zip,
-extract the first *.m file in it and validate it enters a MATLAB mode.
-Also, validate `matlab-is-matlab-file' returns t."
+extract the *.m files and validate they enter Objective-C mode
+if the file starts with objc, else they should enter MATLAB mode.
+When the file starts with objc, the content must be Objective-C
+content in archive.zip.
+
+Also, validate `matlab-is-matlab-file' returns t or nil."
(let* ((m-file "test-matlab-is-matlab-file-files/archive.zip")
(zip-buf (get-file-buffer m-file))
- (all-entered-a-matlab-mode 'unknown)
- (all-are-matlab-file 'unknown))
+ (all-good t))
(when zip-buf
(kill-buffer zip-buf))
(setq zip-buf (find-file-noselect m-file))
@@ -42,23 +45,33 @@ Also, validate `matlab-is-matlab-file' returns t."
(goto-char (point-min))
(while (re-search-forward "\\.m$" nil t)
(let ((m-buf (archive-extract))
- (is-a-matlab-mode (or (eq major-mode 'matlab-ts-mode)
- (eq major-mode 'matlab-mode)))
(is-matlab-file (matlab-is-matlab-file)))
(message "test-matlab-is-matlab-file: checking %s"
(buffer-file-name))
- (when (or (eq all-entered-a-matlab-mode 'unknown)
- (not is-a-matlab-mode))
- (setq all-entered-a-matlab-mode is-a-matlab-mode))
- (when (or (eq all-are-matlab-file 'unknown)
- (not is-matlab-file))
- (setq all-are-matlab-file is-matlab-file))
+ (cond
+
+ ((string-match-p "^objc" (buffer-name))
+ ;; should be objective-c
+ (when (not (eq major-mode 'objc-mode))
+ (message "error: %s did not enter objc-mode" (buffer-file-name))
+ (setq all-good nil))
+ (when is-matlab-file
+ (message "error: %s says its a MATLAB file" (buffer-file-name))))
+
+ (t
+ ;; should be a MATLAB mode
+ (when (not (or (eq major-mode 'matlab-ts-mode)
+ (eq major-mode 'matlab-mode)))
+ (message "error: %s did not enter a MATLAB mode"
(buffer-file-name))
+ (setq all-good nil))
+ (when (not is-matlab-file)
+ (message "error: %s says its NOT a MATLAB file"
(buffer-file-name)))))
+
(kill-buffer m-buf)
(set-buffer zip-buf))))
(kill-buffer zip-buf)
- (should (eq all-entered-a-matlab-mode t))
- (should (eq all-are-matlab-file t))))
+ (should (eq all-good t))))
(provide 'test-matlab-is-matlab-file)
;;; test-matlab-is-matlab-file.el ends here