matlab-syntax.el:

(matlab-syntax-support-command-dual): Default to t
(matlab-syntax-commanddual-functions): List of functions
commonly used with command line dual.
(matlab--scan-line-for-command-dual): Use above lists
instead of anti-keyword detection.

tests/fontlock.m, tests/indents.m:
Add tests for command dual.

tests/stringtest.m:
Command dual test updated to use 'disp'
This commit is contained in:
Eric Ludlam 2021-03-24 22:08:52 -04:00
parent 5c6ef4b9c5
commit 7b49b6f447
4 changed files with 39 additions and 13 deletions

View file

@ -30,7 +30,7 @@
(require 'matlab-compat)
;;; Code:
(defvar matlab-syntax-support-command-dual nil
(defvar matlab-syntax-support-command-dual t
"Non-nil means to support command dual for indenting and syntax highlight.
Does not work well in classes with properties with datatypes.")
(make-variable-buffer-local 'matlab-syntax-support-command-dual)
@ -208,16 +208,24 @@ and `matlab--scan-line-for-unterminated-string' for specific details."
(forward-line 1))
)))
(declare-function matlab-keyword-p "matlab-scan")
(defconst matlab-syntax-commanddual-functions
'("warning" "disp"
;; debug
"dbstop" "dbclear"
;; Graphics
"print" "xlim" "ylim" "zlim" "grid" "hold" "box")
"Functions that are commonly used with commandline dual")
(defconst matlab-cds-regex (regexp-opt matlab-syntax-commanddual-functions 'symbols))
(defun matlab--scan-line-for-command-dual (&optional debug)
"Scan this line for command line duality strings."
;; Note - add \s$ b/c we'll add that syntax to the first letter, and it
;; might still be there during an edit!
(when (looking-at "^\\s-*\\([a-zA-Z_]\\(?:\\w\\|\\s_\\)*\\)\\s-+\\(\\s$\\|\\w\\|\\s_\\)")
;; This is likely command line dual for a function.
(when (not (matlab-keyword-p 1))
(goto-char (match-beginning 2)))))
(when (looking-at
(concat "^\\s-*"
matlab-cds-regex
"\\s-+\\(\\s$\\|\\w\\|\\s_\\)"))
(goto-char (match-beginning 2))))
(matlab--syntax-symbol matlab--transpose-syntax '(3 . nil) ;; 3 = symbol
"Treat ' as non-string when used as transpose.")

View file

@ -112,9 +112,9 @@ function dographics(value)
end
function dodebug()
dbstop on dodebug
%^ ^bo
dbstop in dodebug
%^ ^bo ^cd
dbclear
%^ ^bo

View file

@ -304,7 +304,7 @@ function B = continuations_and_block_comments
if condition1 || ... % !!4
fcn_call(arg1, ... % !!12
arg2); % !!21
arg2) % !!21
line_in_if();
end % !!4
@ -336,4 +336,22 @@ function b=function_end_same_line(a), b=a; end %!!0
function function_after_end_same_line()%!!0
%!!0
disp('foo');%!!4
end%!!0
debug_cmd_dual();
end%!!0
function debug_cmd_dual ()
% These dbstop command dual content have 'if' blocks in them.
% The command dual detection needs to block these from being
% detected as block initiators which would cause indentaiton.
dbstop in hRandomFile at 14 if func() % !!4
dbstop in hRandomFile at 30@1 if x==1 % !!4
dbstop in hPFile % !!4
dbstop in hSimpleFile at 2 % !!4
dbstop if error % !!4
%!!4
end

View file

@ -170,8 +170,8 @@ not_commented();
%% Command line dual #C#
% Note: stuff after a symbol<space> treated as string
funcall _this is string input to function #d#_
fun_call _this is also string input to a function #d#_
disp _this is string input to function #d#_
disp _this is also string input to a function #d#_
%{
% Local Variables: