matlab-scan.el:
(matlab-block-keyword-list): Add more keywords. (matlab-compute-line-context-lvl-1): improve keyword detection to handle the new types of keywords that don't start blocks. Improve end of line detection to distinguish command dual from ellipsis. (matlab-line-commanddual-p): New (matlab-scan-previous-line-ellipsis-p): Improve how ellipsis is found to be more explicit. (matlab-describe-line-indent-context): Show command dual in output. matlab.el: (matlab-lattr-cont): Improve how ellipsis is found to be more explicit. indents.el: Add more keyword styles around to deal with command dual problems.
This commit is contained in:
parent
9d41e46c98
commit
dbb6fc6757
3 changed files with 67 additions and 28 deletions
|
@ -46,11 +46,17 @@
|
|||
("for" . ctrl)
|
||||
("parfor" . ctrl)
|
||||
("while" . ctrl)
|
||||
("spmd" . ctrl)
|
||||
("switch" . ctrl)
|
||||
("case" . case)
|
||||
("otherwise" . case)
|
||||
("try" . ctrl)
|
||||
("catch" . mid)
|
||||
("break" . keyword)
|
||||
("continue" . keyword)
|
||||
("return" . keyword)
|
||||
("global" . vardecl)
|
||||
("persistent" . vardecl)
|
||||
)
|
||||
"List of keywords that are part of code blocks.")
|
||||
|
||||
|
@ -254,16 +260,25 @@ in a single call using fastest methods."
|
|||
;; Look up our various keywords.
|
||||
(let* ((symval (matlab-keyword-p 0)))
|
||||
(if symval
|
||||
(if (eq symval 'end)
|
||||
;; Special end keyword is in a class all it's own
|
||||
(setq ltype 'end)
|
||||
;; If we found this in our keyword table, then it is a start
|
||||
;; of a block with a subtype.
|
||||
(cond
|
||||
;; Special end keyword is in a class all it's own
|
||||
((eq symval 'end)
|
||||
(setq ltype 'end))
|
||||
;; If we found this in our keyword table, then it is a start
|
||||
;; of a block with a subtype.
|
||||
((memq symval '(decl args mcos ctrl mid case))
|
||||
(setq ltype 'block-start
|
||||
stype symval))
|
||||
;; Else - not a sym - just some random code.
|
||||
(setq ltype 'code)
|
||||
))))
|
||||
;; Some keywords aren't related to blocks with indentation
|
||||
;; controls. Those are treated as code, with a type.
|
||||
((memq symval '(keyword vardecl))
|
||||
(setq ltype 'code
|
||||
stype symval))
|
||||
;; Else - not a sym - just some random code.
|
||||
(t
|
||||
(setq ltype 'code)))
|
||||
(setq ltype 'code))
|
||||
)))
|
||||
|
||||
;; Looking at a close paren.
|
||||
((and (< 0 paren-depth) (looking-at "\\s)"))
|
||||
|
@ -288,8 +303,10 @@ in a single call using fastest methods."
|
|||
;; If we have something, record what it is.
|
||||
(when csc
|
||||
(setq ec-col csc
|
||||
ec-type (if (= (char-after csc) ?\%) 'comment 'ellipsis))) ;; type
|
||||
)
|
||||
ec-type (cond ((= (char-after csc) ?\%) 'comment)
|
||||
((= (char-after csc) ?\.) 'ellipsis)
|
||||
(t 'commanddual)))
|
||||
))
|
||||
|
||||
(list ltype stype pt indent start paren-depth
|
||||
paren-inner-char paren-inner-col paren-outer-char paren-outer-point paren-delta
|
||||
|
@ -354,10 +371,13 @@ All lines that start with a comment end with a comment."
|
|||
(current-column))))
|
||||
|
||||
(defsubst matlab-line-ellipsis-p (lvl1)
|
||||
"Return if this line ends with a comment.
|
||||
All lines that start with a comment end with a comment."
|
||||
"Return if this line ends with a comment."
|
||||
(eq (nth mlf-end-comment-type lvl1) 'ellipsis))
|
||||
|
||||
(defsubst matlab-line-commanddual-p (lvl1)
|
||||
"Return if this line ends with command duality string."
|
||||
(eq (nth mlf-end-comment-type lvl1) 'commanddual))
|
||||
|
||||
(defsubst matlab-line-block-comment-start (lvl1)
|
||||
"Return the start of the block comment we are in, or nil."
|
||||
(when (and (matlab-line-comment-p lvl1)
|
||||
|
@ -718,9 +738,9 @@ This is true iff the previous line has an ellipsis."
|
|||
(forward-char -1)
|
||||
(let* ((pps (syntax-ppss (point)))
|
||||
(csc (nth 8 pps)))
|
||||
;; If the comment active on eol does NOT start with %, then it must be
|
||||
;; and ellipsis.
|
||||
(when (and csc (/= (char-after csc) ?\%))
|
||||
;; Ellipsis start has a syntax of 11 (comment-start).
|
||||
;; Other comments have high-bit flags, so don't == 11.
|
||||
(when (and csc (= (car (syntax-after csc)) 11))
|
||||
csc)))))
|
||||
|
||||
(defun matlab-scan-beginning-of-command (&optional lvl1)
|
||||
|
@ -920,6 +940,7 @@ Make sure the cache doesn't exceed max size."
|
|||
extraclose
|
||||
(cond ((eq (nth mlf-end-comment-type lvl1) 'comment) "%")
|
||||
((eq (nth mlf-end-comment-type lvl1) 'ellipsis) "...")
|
||||
((eq (nth mlf-end-comment-type lvl1) 'commanddual) "-command dual")
|
||||
(t ""))
|
||||
(if (matlab-line-end-comment-column lvl1)
|
||||
(format " %d" (matlab-line-end-comment-column lvl1))
|
||||
|
|
|
@ -2202,8 +2202,9 @@ based on what it ends with."
|
|||
(csc (nth 8 pps)))
|
||||
(or
|
||||
;; When the line ends with a comment, it might be an ellipsis.
|
||||
;; Can only be tail comment w/ no % start if it is an ellipsis.
|
||||
(and csc (/= (char-after csc) ?\%))
|
||||
;; Ellipsis start has a syntax of 11 (comment-start).
|
||||
;; Other comments have high-bit flags, so don't == 11.
|
||||
(and csc (= (car (syntax-after csc)) 11))
|
||||
|
||||
;; If the line doesn't end in ..., but we have optional ..., then
|
||||
;; use this annoying heuristic.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function indents(a,b,stuff)
|
||||
function indents(a,b,stuff,cmddual1fake,cmddual2fake)
|
||||
% Help text
|
||||
% !!0
|
||||
% of many lines
|
||||
|
@ -11,18 +11,27 @@ function indents(a,b,stuff)
|
|||
a (1,1) {mustBeNumeric} % !!8
|
||||
b (:,:) double % !!8
|
||||
stuff {mustBeMember(stuff, { 'this' 'that' 'other' })} % !!8
|
||||
cmddual1fake double % !!8
|
||||
cmddual2fake int % !!8
|
||||
end % !!4
|
||||
|
||||
persistent var1 % !!4
|
||||
global var2 % !!4
|
||||
persistent var3 % !!4
|
||||
|
||||
|
||||
locala = a; %#ok
|
||||
localb = b; %#ok
|
||||
localstuff = stuff; %#ok
|
||||
|
||||
ends_in_comments_and_strings(); % !!4 has end in name
|
||||
if isempty(var1) var1=1; end %#ok !!4
|
||||
if isempty(var3) var3=2; end %#ok !!4
|
||||
|
||||
ends_in_comments_and_strings(var1, var2, var3); % !!4 has end in name
|
||||
|
||||
% !!4
|
||||
|
||||
block_starts_in_comments_and_strings();
|
||||
block_starts_in_comments_and_strings(cmddual1fake,cmddual2fake);
|
||||
array_constant_decls();
|
||||
|
||||
% !!4
|
||||
|
@ -98,7 +107,7 @@ function B = ends_in_comments_and_strings()
|
|||
code1() ...
|
||||
|
||||
B = [ B A ]; % !!4
|
||||
|
||||
|
||||
str = 'This is a char array with ... in it';
|
||||
foo(str); % !!4
|
||||
|
||||
|
@ -175,25 +184,31 @@ function out = array_constant_decls()
|
|||
|
||||
end
|
||||
|
||||
function C = block_starts_in_comments_and_strings()
|
||||
function C = block_starts_in_comments_and_strings(varargin)
|
||||
% !!0
|
||||
|
||||
C = 0;
|
||||
|
||||
if true % if true
|
||||
if varargin{1} % if true
|
||||
|
||||
% !!8
|
||||
else % !!4
|
||||
|
||||
% !!8
|
||||
|
||||
% !!8
|
||||
end % if true
|
||||
|
||||
|
||||
% see previous function
|
||||
% !!4
|
||||
for x=1:length(C) % !!4
|
||||
if varargin{2} % !!8
|
||||
continue % !!12
|
||||
end % !!8
|
||||
|
||||
% !!8
|
||||
break % !!8
|
||||
% !!14
|
||||
|
||||
%!!8
|
||||
end
|
||||
|
||||
switch foo() %!!4
|
||||
|
@ -276,10 +291,12 @@ function has_nested_fcn
|
|||
|
||||
plot(1:10); %!!4
|
||||
|
||||
function am_nested_fcn %!!4
|
||||
A = 1;
|
||||
|
||||
function am_nested_fcn() %!!4
|
||||
% help
|
||||
% !!4
|
||||
code();
|
||||
code(A);
|
||||
%!!8
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue