branch: externals/matlab-mode
commit 9c02b20a140a1bfea4b62b5736bf0dbe8f6b8eb9
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    matlab-ts-mode: initial support for mlint flycheck
---
 flycheck-matlab-mlint.el | 44 --------------------------------------------
 matlab-ts-mode.el        | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 45 deletions(-)

diff --git a/flycheck-matlab-mlint.el b/flycheck-matlab-mlint.el
deleted file mode 100644
index aa75f94d35..0000000000
--- a/flycheck-matlab-mlint.el
+++ /dev/null
@@ -1,44 +0,0 @@
-;;; flycheck-matlab-mlint.el --- Flycheck: MATLAB support -*- lexical-binding: 
t -*-
-
-;;; Commentary:
-
-;; Provides support for MATLAB code checking with mlint and flycheck
-;; that integrates with matlab-mode
-;;
-;; Usage:
-;;
-;;     (eval-after-load 'flycheck
-;;       '(add-hook 'flycheck-mode-hook #'flycheck-matlab-mlint-setup))
-
-;;; Code:
-
-(defvar flycheck-checkers) ;; incase flycheck is not on the path
-
-(eval-and-compile
-  (when (not (require 'flycheck nil 'noerror))
-    (defmacro flycheck-define-checker (symbol _docstring &rest _properties)
-      "To use flycheck SYMBOL, they need to install flycheck."
-      (message "To use %S flycheck, you need to install flycheck." symbol))))
-
-(flycheck-define-checker matlab-mlint
-  "A MATLAB checker using MATLAB mlint code analyzer."
-  ;; xxx command
-  :command ("mlint" "-id" "-all" source-original)
-  ;; Example mlint messages.
-  ;; L 588 (C 46-49): LOAD: To avoid conflicts with functions on the path, 
specify variables to load from file.
-  ((warning line-start "L " line " (C " column "-" column "): " (id (* alnum)) 
":" (message))
-   (warning line-start "L " line " (C " column "): " (id (* alnum)) ":" 
(message)))
-  :modes (matlab-mode)
-  :predicate (lambda () (flycheck-buffer-saved-p)))
-
-;;;###autoload
-(defun flycheck-matlab-mlint-setup ()
-  "Set up Flycheck MATLAB mlint.
-
-Adds `matlab-mlint' to `flycheck-checkers'."
-  (interactive)
-  (add-to-list 'flycheck-checkers 'matlab-mlint))
-
-
-(provide 'flycheck-matlab-mlint)
-;;; flycheck-matlab-mlint.el ends here
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 97c9ecfc52..e2bbc07e34 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -118,7 +118,7 @@ Guidelines:
 
 (defcustom matlab-ts-mode-on-save-fixes
   '(matlab-ts-mode-on-save-fix-name)
-  "List of function symbols which offer to fix *.m files on save.
+  "*List of function symbols which offer to fix *.m files on save.
 During save these functions are called and will prompt to fix issues in
 *.m files.  Each function gets no arguments, and returns nothing.  They
 can move point, but it will be restored for them."
@@ -130,6 +130,19 @@ can move point, but it will be restored for them."
 See \\[matlab-ts-mode-comment-marker-help]."
   :type 'boolean)
 
+(defcustom matlab-ts-mode-enable-mlint-flycheck t
+  "*Enable MLint code analyzer via flycheck.
+This requires that you install the flycheck package
+https://www.flycheck.org can be installed by adding
+to your ~/.emacs
+  (require \\='package)
+  (add-to-list \\='package-archives
+               \\='(\"MELPA Stable\" . \"https://stable.melpa.org/packages/\";) 
t)
+Then restart Emacs and run
+  \\[package-install] RET flycheck RET
+You can also install via use-package or other methods."
+  :type 'boolean)
+
 ;;; Global variables used in multiple code ";;; sections"
 
 (defvar matlab-ts-mode--comment-heading-re
@@ -2013,6 +2026,35 @@ 
https://github.com/acristoffers/tree-sitter-matlab/issues/34";
 
 ;;; matlab-ts-mode
 
+;;; MLint Flycheck
+
+(defvar flycheck-checkers) ;; incase flycheck is not on the path
+
+(eval-and-compile
+  (when (not (require 'flycheck nil 'noerror))
+    (defmacro flycheck-define-checker (symbol _docstring &rest _properties)
+      "To use flycheck SYMBOL, they need to install flycheck."
+      (message "To use %S flycheck, you need to install flycheck." symbol))))
+
+(flycheck-define-checker matlab-mlint
+  "A MATLAB checker using MATLAB mlint code analyzer."
+  ;; TODO use matlab--get-mlint-exe instead of assuming mlint is on path
+  :command ("mlint" "-id" "-all" source-original)
+  ;; Example mlint messages.
+  ;; L 588 (C 46-49): LOAD: To avoid conflicts with functions ....
+  :error-patterns
+  ((warning line-start "L " line " (C " column "-" column "): " (id (* alnum)) 
":" (message))
+   (warning line-start "L " line " (C " column "): " (id (* alnum)) ":" 
(message)))
+  :modes (matlab-ts-mode)
+  :predicate (lambda () (flycheck-buffer-saved-p)))
+
+;; Register flycheck
+(when matlab-ts-mode-enable-mlint-flycheck
+  (if (require 'flycheck nil 'noerror)
+      (add-to-list 'flycheck-checkers 'matlab-mlint)
+    (message "matlab-ts-mode: no flycheck, unable to activate mlint - \
+to fix install https://www.flycheck.org";)))
+
 ;;;###autoload
 (define-derived-mode matlab-ts-mode prog-mode "MATLAB:ts"
   "Major mode for editing MATLAB files with tree-sitter.

Reply via email to