matlab-scan.el:
(mlf-paren-inner-point): New var. Renumbered all the other vars. (matlab-compute-line-context-lvl-1): Add paren inner point into list. (matlab-line-close-paren-inner-point): New matlab.el: (matlab-calculate-indentation-1): Update blockendless to use new apis Update plain code continuations to use new apis when inside parens.
This commit is contained in:
parent
c802dbd8be
commit
d24178e015
3 changed files with 131 additions and 106 deletions
|
@ -165,11 +165,12 @@ return the cache if it finds it."
|
|||
(defconst mlf-paren-depth 5)
|
||||
(defconst mlf-paren-inner-char 6)
|
||||
(defconst mlf-paren-inner-col 7)
|
||||
(defconst mlf-paren-outer-char 8)
|
||||
(defconst mlf-paren-outer-point 9)
|
||||
(defconst mlf-paren-delta 10)
|
||||
(defconst mlf-end-comment-type 11)
|
||||
(defconst mlf-end-comment-pt 12)
|
||||
(defconst mlf-paren-inner-point 8)
|
||||
(defconst mlf-paren-outer-char 9)
|
||||
(defconst mlf-paren-outer-point 10)
|
||||
(defconst mlf-paren-delta 11)
|
||||
(defconst mlf-end-comment-type 12)
|
||||
(defconst mlf-end-comment-pt 13)
|
||||
|
||||
(defun matlab-compute-line-context-lvl-1 ()
|
||||
"Compute and return the level1 context for the current line of MATLAB code.
|
||||
|
@ -189,6 +190,7 @@ in a single call using fastest methods."
|
|||
(paren-depth (nth 0 pps))
|
||||
(paren-inner-char nil)
|
||||
(paren-inner-col nil)
|
||||
(paren-inner-point nil)
|
||||
(paren-outer-char nil)
|
||||
(paren-outer-point nil)
|
||||
(paren-delta (- (car pps) (car ppsend)))
|
||||
|
@ -207,6 +209,7 @@ in a single call using fastest methods."
|
|||
(goto-char (car (last (nth 9 pps))))
|
||||
(setq paren-inner-char (char-after (point))
|
||||
paren-inner-col (current-column)
|
||||
paren-inner-point (point)
|
||||
paren-outer-point (car (nth 9 pps))
|
||||
paren-outer-char (char-after paren-outer-point) )))
|
||||
|
||||
|
@ -290,7 +293,8 @@ in a single call using fastest methods."
|
|||
))
|
||||
|
||||
(list ltype stype pt indent start paren-depth
|
||||
paren-inner-char paren-inner-col paren-outer-char paren-outer-point paren-delta
|
||||
paren-inner-char paren-inner-col paren-inner-point
|
||||
paren-outer-char paren-outer-point paren-delta
|
||||
ec-type ec-col
|
||||
;;cont-from-prev
|
||||
)
|
||||
|
@ -452,6 +456,10 @@ Return nil for empty and comment only lines."
|
|||
"Return the paren column for the prenthetical expression LVL1 is in."
|
||||
(nth mlf-paren-inner-col lvl1))
|
||||
|
||||
(defsubst matlab-line-close-paren-inner-point (lvl1)
|
||||
"Return the paren column for the prenthetical expression LVL1 is in."
|
||||
(nth mlf-paren-inner-point lvl1))
|
||||
|
||||
(defsubst matlab-line-close-paren-outer-char (lvl1)
|
||||
"The paren character for the outermost prenthetical expression LVL1 is in."
|
||||
(nth mlf-paren-outer-char lvl1))
|
||||
|
|
190
matlab.el
190
matlab.el
|
@ -2175,16 +2175,16 @@ LVL2 is a level 2 scan context with info from previous lines."
|
|||
;; CASE/OTHERWISE keywords
|
||||
((matlab-line-block-case-p lvl1)
|
||||
(list 'blockendless
|
||||
(condition-case nil
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(matlab-backward-sexp t)
|
||||
(if (not (looking-at "switch\\>")) (error ""))
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(if (matlab--scan-block-backward-up)
|
||||
(error "Missing switch")
|
||||
(if (not (eq (matlab-on-keyword-p) 'ctrl))
|
||||
(error "Wrong type of start block")
|
||||
(+ (current-column)
|
||||
(if (listp matlab-case-indent-level)
|
||||
(car matlab-case-indent-level)
|
||||
matlab-case-indent-level)))
|
||||
(error (error "Unmatched case/otherwise part")))))
|
||||
matlab-case-indent-level)))))))
|
||||
;; End of a MATRIX
|
||||
((matlab-line-close-paren-p lvl1)
|
||||
(list 'array-end (let* ((fc (matlab-line-close-paren-inner-char lvl1))
|
||||
|
@ -2203,104 +2203,93 @@ LVL2 is a level 2 scan context with info from previous lines."
|
|||
;; Code lines
|
||||
((and (not (matlab-line-close-paren-outer-point lvl1))
|
||||
(not (matlab-scan-previous-line-ellipsis-p)))
|
||||
|
||||
;; Old check for base code line was using
|
||||
;; 'matlab-beginning-of-command' which does a lot of work, like
|
||||
;; checking for block comments and such. We already stripped
|
||||
;; out most options in that cmd and know we are on a code line,
|
||||
;; so only check if the previous line is a continuation line.
|
||||
;; Old code:
|
||||
;;(save-excursion
|
||||
;; (beginning-of-line)
|
||||
;; (back-to-indentation)
|
||||
;; (= (point) (progn (matlab-beginning-of-command) (point))))
|
||||
|
||||
;; This means we are at the beginning of a command structure.
|
||||
;; Always match up against the previous line.
|
||||
;; Code always matches up against the previous line.
|
||||
(list 'code ci))
|
||||
|
||||
;; Lines continued from previous statements.
|
||||
(t
|
||||
(list (if (matlab-line-empty-p lvl1) 'empty
|
||||
(if (matlab-line-close-paren-outer-point lvl1) 'array-cont 'code))
|
||||
;; Record beginning of the command
|
||||
(let* ((ci-local ci) ;; we prob want to change this due to continuation.
|
||||
(boc (save-excursion
|
||||
(matlab-beginning-of-command)
|
||||
(setq ci-local (current-indentation))
|
||||
(point))))
|
||||
(let* (;; TODO = Why does this code need to navigate
|
||||
;; through this stuff? next-line version
|
||||
;; should do this.
|
||||
(boc-lvl1 (save-excursion
|
||||
(matlab-scan-beginning-of-command)
|
||||
(matlab-compute-line-context 1)))
|
||||
(ci-boc (matlab-line-indentation boc-lvl1))
|
||||
(boc (matlab-line-point boc-lvl1))
|
||||
|
||||
;; Scratch vars for paren stuff
|
||||
(parencol (matlab-line-close-paren-inner-col lvl1))
|
||||
(parenchar (matlab-line-close-paren-inner-char lvl1))
|
||||
(parenpt (matlab-line-close-paren-inner-point lvl1))
|
||||
|
||||
;; What shall we use to describe this for debugging?
|
||||
(indent-type (cond ((matlab-line-empty-p lvl1) 'empty)
|
||||
((and parenchar (= parenchar ?\()) 'function-call-cont)
|
||||
((matlab-line-close-paren-outer-point lvl1) 'array-cont)
|
||||
(t 'code-cont)))
|
||||
|
||||
(found-column nil)
|
||||
)
|
||||
|
||||
(list indent-type
|
||||
(condition-case nil
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(matlab-up-list -1)
|
||||
(if (> boc (point)) (error nil))
|
||||
;; Ok, it MIGHT be that we are in a program
|
||||
;; statement, and this particular command is an HG
|
||||
;; statement that would look better if the
|
||||
;; following lines lined up AFTER the first
|
||||
;; argument. Lets look.
|
||||
(let ((parendepth (current-column)))
|
||||
(cond ((and (= (following-char) ?\( )
|
||||
(save-excursion
|
||||
(matlab-navigation-syntax
|
||||
(forward-word -1)
|
||||
(looking-at
|
||||
matlab-indent-past-arg1-functions)))
|
||||
(let ((start-paren (point)))
|
||||
(while
|
||||
(and
|
||||
(re-search-forward
|
||||
"," (matlab-point-at-eol) t)
|
||||
(save-excursion
|
||||
(matlab-up-list -1)
|
||||
(> (point) start-paren))))
|
||||
(if (and
|
||||
(= (preceding-char) ?,)
|
||||
;; Don't bother if we hit the EOL.
|
||||
(not (looking-at
|
||||
(goto-char parenpt) ;; this errs and goes to = alignment. TODO - make w/o errors
|
||||
|
||||
"\\s-*\\(\\.\\.\\.\\|$\\|)\\)")))
|
||||
t
|
||||
(move-to-column parendepth)
|
||||
nil)))
|
||||
(skip-chars-forward " \t")
|
||||
(if (> (- (current-column) parendepth)
|
||||
matlab-arg1-max-indent-length)
|
||||
(+ parendepth matlab-arg1-max-indent-length)
|
||||
(current-column)))
|
||||
(t
|
||||
(let* ((fc (following-char))
|
||||
(mi (assoc fc matlab-maximum-indents))
|
||||
(max (if mi
|
||||
(if (listp (cdr mi))
|
||||
(car (cdr mi)) (cdr mi))
|
||||
nil))
|
||||
(ind (if mi
|
||||
(if (listp (cdr mi))
|
||||
(cdr (cdr mi)) (cdr mi))
|
||||
nil)))
|
||||
(forward-char 1)
|
||||
(skip-chars-forward " \t")
|
||||
;; If we are at the end of a line and
|
||||
;; this open paren is there, then we
|
||||
;; DON'T want to indent to it. Use the
|
||||
;; standard indent.
|
||||
(if (or (not matlab-align-to-paren)
|
||||
(looking-at "\\.\\.\\.\\|$"))
|
||||
;; This could happen in another set
|
||||
;; of matrices. Find a current
|
||||
;; indentation based on the
|
||||
;; previous line.
|
||||
(let ((cci (current-indentation)))
|
||||
(+ cci matlab-continuation-indent-level))
|
||||
;; TODO - this disables indentation MAXs
|
||||
;; if we really want to be rid of this
|
||||
;; we can dump a bunch of logic above too.
|
||||
;; apply the maximum limits.
|
||||
;;(if (and ind (> (- (current-column) ci-local) max))
|
||||
;; (+ ci-local ind)
|
||||
;; (current-column))
|
||||
(current-column)
|
||||
))))))
|
||||
(progn
|
||||
(cond
|
||||
((and
|
||||
;; Special case for FUNCTIONs that indent past arg1
|
||||
(eq indent-type 'function-call-cont)
|
||||
;; This checks for our special set of functions.
|
||||
(save-excursion
|
||||
(goto-char parenpt)
|
||||
(forward-symbol -1)
|
||||
(looking-at
|
||||
matlab-indent-past-arg1-functions))
|
||||
;; We are in a fcn call, AND the fcn wants to
|
||||
;; indent past the first argument. Only do so
|
||||
;; if first arg is a SIMPLE EXPR.
|
||||
(matlab-navigation-syntax
|
||||
(looking-at "(\\s-*\\w+\\s-*,")
|
||||
(setq found-column (match-end 0)))
|
||||
(save-excursion
|
||||
(goto-char found-column) ; move to comma
|
||||
;; Don't bother if we hit the EOL.
|
||||
(not (looking-at "\\s-*\\(\\.\\.\\.\\|$\\|)\\)"))))
|
||||
;; We are in the right kind of place. Lets
|
||||
;; start indenting
|
||||
(goto-char found-column)
|
||||
(skip-chars-forward " \t")
|
||||
(if (> (- (current-column) parencol)
|
||||
matlab-arg1-max-indent-length)
|
||||
(+ parencol matlab-arg1-max-indent-length)
|
||||
(current-column)))
|
||||
|
||||
;; any other case LINE UP WITH THE PAREN FOUND
|
||||
(t
|
||||
(let* ((mi (assoc parenchar matlab-maximum-indents))
|
||||
(max (if mi (if (listp (cdr mi)) (car (cdr mi)) (cdr mi)) nil))
|
||||
(ind (if mi (if (listp (cdr mi)) (cdr (cdr mi)) (cdr mi)) nil)))
|
||||
(goto-char parenpt)
|
||||
(forward-char 1)
|
||||
(skip-chars-forward " \t")
|
||||
;; If we are at the end of a line and this
|
||||
;; open paren is there, then we DON'T want
|
||||
;; to indent to it. Use the standard
|
||||
;; indent.
|
||||
(if (or (not matlab-align-to-paren)
|
||||
(looking-at "\\.\\.\\.\\|$"))
|
||||
(+ ci-boc matlab-continuation-indent-level)
|
||||
(current-column)
|
||||
;; TODO - this disables indentation MAXs
|
||||
;; if we really want to be rid of this
|
||||
;; we can dump a bunch of logic above too.
|
||||
;; apply the maximum limits.
|
||||
;;(if (and ind (> (- (current-column) ci-boc) max))
|
||||
;; (+ ci-boc ind)
|
||||
;; (current-column))
|
||||
))))))
|
||||
(error
|
||||
;; Line up to an equals sign.
|
||||
(save-excursion
|
||||
|
@ -3540,6 +3529,7 @@ desired. Optional argument FAST is not used."
|
|||
"Line Syntax: " lvl1msg
|
||||
" | Preferred Indents: This: " (int-to-string (nth 1 indent))
|
||||
" Next: " (int-to-string nexti)
|
||||
" Indent Style: " (symbol-name (car indent))
|
||||
))
|
||||
|
||||
(if (matlab-line-ellipsis-p lvl1)
|
||||
|
@ -3567,7 +3557,7 @@ desired. Optional argument FAST is not used."
|
|||
;; LocalWords: Unstarted includeelse autostart lattr zerop cellstart
|
||||
;; LocalWords: linebounds bol commtype startmove nomove charvector sregex
|
||||
;; LocalWords: insregex laststart bolp calc ci sem DEPTHNUMBER blockstart
|
||||
;; LocalWords: blockmid blockendless blockend unstarted listp boc parendepth
|
||||
;; LocalWords: blockmid blockendless blockend unstarted listp boc parencol
|
||||
;; LocalWords: cci startpnt hc rc nosemi emacsen afterd befored okpos startlst
|
||||
;; LocalWords: endlst ellipsify noreturn hs tc matchers hideshow func PUSHNEW
|
||||
;; LocalWords: pushnew bn nondirectory un msgpos nexti
|
||||
|
|
|
@ -62,6 +62,33 @@ function continuations(a,b) %!!0
|
|||
|
||||
% !!4 to undo continuation.
|
||||
|
||||
% Indent past 1st arg for special functions
|
||||
set(myhandle, 'Prop1', value, ... %!!4
|
||||
'Prop2', value, ... %!!18
|
||||
'Prop3', value); %!!18
|
||||
|
||||
% Indent past = sign for assignments.
|
||||
A = 1 + ... % !!4
|
||||
2; % !!8
|
||||
|
||||
medvar = 1 + ... % !!4
|
||||
2; % !!13
|
||||
|
||||
alongvariablename = 1 +... % !!4
|
||||
2; % !!8
|
||||
|
||||
|
||||
fancyfunctionname(arg1, ... %!!4
|
||||
innerfcn(arg2, ... %!!22
|
||||
arg3), ... %!!31
|
||||
{ cell1; %!!22
|
||||
cell2; %!!24
|
||||
[ 1 2 ; %!!24
|
||||
3 4 ] ; %!!26
|
||||
cell 4 },... %!!24
|
||||
arg5); %!!22
|
||||
|
||||
|
||||
... % Continuation by itself just before an end.
|
||||
end %!!0
|
||||
|
||||
|
|
Loading…
Reference in a new issue