Commit graph

548 commits

Author SHA1 Message Date
Eric Ludlam
a5449ab375 matlab.el:
(matlab-indent-region): Add arg to supress progress indicator.
(matlab--change-indentation-override): New feature.
(matlab--indent-line): Extract bit that changes buffer to...
(matlab--change-indentation): New from above.
This fcn is set on the indentation override.
(matlab-calculate-indentation-1, matlab-next-line-indentation):
Pass lvl2 into help scan.
2021-03-13 20:42:53 -05:00
Eric Ludlam
bd55c5a5ec matlab-scan.el:
(matlab-compute-line-context-lvl-2): Add cache stats capture.
(matlab-previous-code-line): New fcn.
(matlab-scan-comment-help-p):
first arg can now be lvl1 or 2.  If lvl2, use it's cached
lines to compute.
2021-03-13 20:38:32 -05:00
Eric Ludlam
7321ab5c83 matlab.el:
(matlab-mode): Specify indent-region-function.
(matlab-lattr-array-cont): Accept lvl2 input and use it when avail.
(matlab-indent-region): New.
Computes a lvl2 context and maintains it line-to-line.
(matlab-indent-line): Compute a lvl2 context.
Move original contents to matlab--indent-line.
(matlab--indent-line): New per-line indenter.
Takes lvl2 context and passes it through.
(matlab-calculate-indentation): Accept lvl2 context, pass through.
(matlab-calculate-indentation-1): Accept lvl2 context.
Derive lvl1 context from lvl2.
(matlab-next-line-indentation): Accept lvl2 context, and use it.
(matlab-comment-indent): Use renamed matlab--calc-indent.
(matlab-show-line-info): compute lvl2 and use it with above changed apis

matlab-scan.el:
(matlab-line-point, matlab-line-indentation): New
(mlf-* for lvl-2 context): Rename for consistency with what they do.
(matlab-compute-linecontext-lvl-2):
Revampe computing of lvl1 (if not passed in), internal names.
Delete old comment stuff (wasn't used.)
Implement cascading lvl2 maintenance from lvl1-prev, or bobp as nil.
(matlab-line-in-array): New helper.

(matlab-scan-cache-get): Log hits to stats.
(matlab-scan-cache-stats): New var
(matlab-scan-stat-reset): New cmd
(matlab-scan-stat-inc): New
(matlab-scan-stats-print): New
2021-03-13 19:46:05 -05:00
Eric Ludlam
5413e93efa matlab.el:
(matlab-last-script-type-guess): New cache.
(matlab-last-guess-decl-p): New fcn, non-nil if fcn or class.
(matlab-guess-script-type): Cache result.
(matlab-beginning-of-command):
Don't ask about help txt if not in a function or class.
(matlab-ltype-code): Fix bug.
(matlab-lattr-block-cont, matlab-lattr-block-close):
Short circuit if not on a code line.
Don't scan into end line comments.
(matlab-calculate-indentation-1)
(matlab-next-line-indentation):
Don't ask about help text if not in function or class script.
2021-03-13 13:21:01 -05:00
Eric Ludlam
dc0bafae3a matlab-scan.el:
(matlab-compute-line-context): Add lvl2 support.
(mlf-indent): New slot
(mlf-end-comment-pt): Rename to match what it is.
(matlab-compute-line-context-lvl-1): Add mlf-indent to output.
(matlab-with-context-line): Macro to just jump to a context.
(matlab-line-comment-ignore-p): Doc fix.
(matlab-line-end-comment-column): Deal with rename of mlf-end-comment-pt.
(matlab-line-end-of-code): New fcn.
(mlf-level1 & others): New
(matlab-compute-line-context-lvl-2): New
(matlab-describe-line-indent-context): Also capture lvl2.
2021-03-13 13:17:15 -05:00
Eric Ludlam
b2d29358e4 matlab.el:
(matlab-valid-end-construct-p):
Replaced old impl with simple call to syntax-ppss.  Seems to pass tests.
2021-03-13 11:33:52 -05:00
Eric Ludlam
40c40e77a1 matlab.el:
(matlab-find-prev-line):
If 'ignorecomments' specified, use fast `forward-comment'.
Otherwise, convert recursive find into iterative loop.
(matlab-find-code-line):
Replace with faster `forward-comment'.
2021-03-13 11:05:36 -05:00
Eric Ludlam
3f239aaefb matlab-syntax.el:
(matlab--put-char-category): If at end of buffer, don't
put the text property there.
2021-03-13 10:45:54 -05:00
Eric Ludlam
bc6b550961 matlab.el:
(matlab-beginning-of-command)
(matlab-ltype-continued-comm):
Replace some calls to use new calls from matlab-scan.
(matlab-ltype-empty, matlab-ltype-comm-noblok)
(matlab-ltype-comm, matlab-ltype-comm-ignore)
(matlab-ltype-code, matlab-lattr-comm)
(matlab-lattr-array-cont):
Swap out old impl with new from matlab-scan.
Replace some calls to use new calls from matlab-scan.
(matlab-calculate-indentation-1):
Replace old call with one from matlab-scan.
2021-03-12 22:17:00 -05:00
Eric Ludlam
7d5a73fb49 matlab-scan.el:
(matlab-block-keyword-list): Add elseif.
(matlab-compute-line-context): Change how cache is called.
(mlf-indent renamed to mlf-point):
(matlab-compute-line-context-lvl-1):
Use above renamed.
(matlab-line-code-p): New predicate.
(matlab-scan-previous-line-ellipsis-p): Fix bug, return column instead.
(matlab-scan-cache-max): New
(matlab-scan-cache-get, matlab-scan-cache-put):
Implement.
2021-03-12 22:12:24 -05:00
Eric Ludlam
6fecb01874 tests/blocks.m:
Indented blank lines.
tests/indents.m:
Indent blank lines.
Added sample for fcn with very long name that
uses array continuation in the argument list.
2021-03-12 22:09:44 -05:00
Eric Ludlam
cf945dedd1 tests/metest.el:
Improve control of debugging output by enabling for test script code,
but disabling while running individual tests.
Tests will catch the error, and show the line in the file where
the test failed.
2021-03-12 22:08:41 -05:00
Eric Ludlam
023bbcf9f0 matlab-syntax.el:
(matlab--scan-line-bad-blockcomment)
(matlab--scan-line-for-ellipsis):
Remove narrowing to region and use search bound instead.
This should be faster.
(matlab--font-lock-syntactic-face):
Quote in all the faces to avoid compiler warning.
2021-03-12 20:07:33 -05:00
Eric Ludlam
71fe525308 matlab-scan.el:
(matlab-describe-line-indent-context):
Improve output by using new slots in lvl1 scan data.
2021-03-12 20:06:00 -05:00
Eric Ludlam
ba7df01197 tests/metest.el:
Revise to move all message output outside what is being timed.
Move looping over files outside the test functions.
Combine timings from one test point to one number to be recorded.
Reduce # of lines output during test running.
2021-03-12 19:43:05 -05:00
Eric Ludlam
52775e4af3 matlab.el:
matlab-scan.el:
(mlf-entity-start, mlf-paren-outer-char, mlf-paren-outer-point):
New const, renumber the others.
(mlf-paren-inner-char, mlf-paren-inner-col):
Renamed fro versions w/out -inner in the name.
(matlab-compute-line-context-lvl-1):
Fill in entity start, and outer char/point.
(matlab-line-block-comment-start): New
(matlab-line-close-paren-inner-col, -char):
Renamed to include -inner
(matlab-line-close-paren-outer-char, -point): New
(matlab-line-comment-help-p): Renamed to
(matlab-scan-comment-help-p): Option PT
now specifies if a point is returned instead of a column.
(matlab-scan-previous-line-ellipsis-p): New
(matlab-scan-beginning-of-command): New
(matlab-describe-line-indent-context): Fixup names, etc.
2021-03-12 08:00:34 -05:00
Eric Ludlam
06c26b19e7 matlab.el:
(matlab-beginning-of-command): In comment skip part,
also look for help comments.
(matlab-next-line-indentation): Replace several -lattr-
type commands with new predicates from matlab-scan.el.
matlab-scan.el:
(matlab-line-regular-comment-p): New
2021-03-10 22:15:01 -05:00
Eric Ludlam
0fb21cfebf matlab.el:
(matlab-calculate-indentation-1):
Replace old -ltype- API calls with new API from matlab-scan.el.
Delete chunks of block comment handlers, replaced with simpler
code using matlab-scan stuff.

matlab-scan.el:
(matlab-compute-line-context-lvl-1):
Rename block comment stype values.
When a keyword is found, only enable iff not in parens.
Trailing comment section, if line starts with a comment,
assume it ends with a comment, and compute key values.
(matlab-line-comment-style, matlab-line-end-comment-column)
(matlab-line-ellipsis-p):
New
(matlab-line-end-p, matlab-line-block-middle-p)
(matlab-line-block-case-p):
New
(matlab-line-close-paren-p, matlab-line-close-paren-char)
(matlab-line-close-paren-col):
New
(matlab-describe-line-indent-context):
Fixup for various changes.
2021-03-10 21:37:51 -05:00
Eric Ludlam
d0cda9be1d .gitignore:
Add .dat files (as generated by test build now.)
2021-03-10 21:33:17 -05:00
Eric Ludlam
a948c123fe matlab-scan.el:
New algorithms for scanning MATLAB files for context.
2021-03-10 19:57:46 -05:00
Eric Ludlam
174f749e1f matlab-scan.el:
New algorithms for scanning MATLAB files for context.
matlab.el:
(matlab-mode-leave): Disable scanner in this buffer.
(matlab-mode): Enable scanner in this buffer.
(matlab-calculate-indentation-1):
Use `matlab-compute-line-context'.  Use output for comment detection.
Move block comment stuff first to maintain consistency with old behavior.

Project.ede, Makefile: Add matlab-scan.el
2021-03-10 19:57:23 -05:00
Eric Ludlam
e57ff3e005 metest.el:
(metest-error): Convert back to error.
2021-03-10 19:54:04 -05:00
Eric Ludlam
27e654c9c0 tests/metest.el:
(metest-all-syntax-tests): Add timing instrumentation.
(metest-condition-case-error-msg): New utility.
(metest-indents-test): Wrap indent computation
in `metest-condition-case-error-msg'.
(metest-log-file): New cofig
(metest-log-init, metest-shorten, metest-log-write)
(metest-log-report, metest-timeint): New.
2021-03-10 19:50:50 -05:00
Eric Ludlam
d96cb11f2f matlab.el:
(matlab-beginning-of-command):
Add hack to skip over multiple continued comments very fast.
This is a very specific optimization for many lines of comments.
2021-03-09 19:21:03 -05:00
Eric Ludlam
7f6f729fd3 matlab.el:
(matlab-calc-indent):
If current line detects we are in an array continuation, then
it is not necessary to compute next-line indentation from it's context
since you can't have if/end type code in there.
Also, array continuation detection is now very fast.
tests/indents.m:
Added a bunch of misc indenttion tests around nested arrays, cell arrays, etc.
2021-03-09 12:50:59 -05:00
Eric Ludlam
81f2cc0fd7 matlab.el:
(matlab-show-paren-or-block):
Use `syntax-class' instead of `car' for output of `syntax-after' to get the class.
This strips out high order bits to return the actual syntax #.
2021-03-09 12:06:03 -05:00
Eric Ludlam
7f9c905238 matlab.el:
(matlab-lattr-cont):
Replace old regexp based searching for ... with use of syntax-ppss,
and using it to find the char that starts the comment, and use to
verify an ellipsis.
2021-03-08 22:34:25 -05:00
Eric Ludlam
7a3e1e872b matlab-syntax.el:
(matlab-up-list): Remove restrict option

matlab.el:
(matlab-lattr-array-cont): Remove restrict option.
2021-03-08 22:08:38 -05:00
Eric Ludlam
a8229c28e0 matlab.el:
(matlab-beginning-of-command): Remove searching for function/block to
restrict motion to.  The search and restrict just slowed down ppss.
(matlab-end-of-command): Remove optional input.
Stop restriting array-cont query.
(matlab-semicolon-on-return, matlab-mode-vf-quiesce-buffer):
Don't pass input to `matlab-end-of-command'.

matlab-syntax.el:
(matlab-up-list): Use `matlab-beginning-of-string-or-comment'
instead of asking for the string or commment bounds.
The beginning is part of ppss, but full bounds includes the end.
2021-03-08 21:58:25 -05:00
Eric Ludlam
e9b66d32ab matlab.el:
(matlab-end-of-command):
In first check, swap order looking for array-cont first since it is faster.
(matlab-property-function, matlab-lattr-semantics): Deleted
(matlab-show-cursor-context): Deleted.

matlab-complete.el:
(matlab-lattr-semantics): Moved here from matlab.el
2021-03-08 18:50:01 -05:00
Eric Ludlam
cc1a00548d matlab.el:
(beginning-of-command): Optimization for very long arrays
where user put ... inside the array.
ie - compute beginning of array bounds first, then look for
continuations.
2021-03-08 16:50:16 -05:00
Eric Ludlam
b450fe1685 matlab.el:
(matlab-ltype-comm): Make robust to block comment start,
where bounds returns false when on start.  Need to also check
for the start of a block comment.
(matlab--maybe-yes-or-no-p): New
(matlab-calcuate-indentation-1):
Use above instead of yes-or-no-p.

metest.el:
(met-end-detect-files): Add mfuncnoendblock.m
mfuncends.m:
Fix expected indentation numbers for continued arrays.
mfuncnoendblock.m:
New.
2021-03-08 08:09:06 -05:00
Eric Ludlam
83db249b97 matlab.el:
(matlab-uniquify-list): Move to matlab-complete.el
matlab-syntax.el:
(matlb-beginning-of-string-or-comment): New nav function
matlab-complete.el:
(matlab-uniquify-list): Moved here from matlab.el
(matlab-find-block-comments): Delete
(matlab-file-basic-font-lock-keywords): Remove ref to above.
(matlab-up-string-or-comment, matlab-backward-up-string-or-comment):
Delete.
(matlab-lattr-block-close):
Replace use of matlab-backward-up-string-or-comment with
matlab-beginning-of-string-or-comment.
2021-03-07 14:09:41 -05:00
Eric Ludlam
17cda9d9af matlab-cgen.el:
Found usage of font-lock function that has been deleted.
Mark this function as needing to be reimplemented.
2021-03-07 14:06:01 -05:00
Eric Ludlam
6126f39548 tests/indents.m:
(array_constant-decls): Add a bunch of ways to have arrays be indented.
2021-03-07 11:55:13 -05:00
Eric Ludlam
04ae9b1249 tests/metest.el:
(metest-error): New function
Adds file / lineno to test errors so you can jump to the right location quickly.
(metest-*-test): Update all functions to use `metest-error'.
2021-03-07 11:54:38 -05:00
Eric Ludlam
8dafb13337 matlab-syntax.el
(matlab-up-list):
Replaced use of `up-list' when travelling backward.
Instead use `syntax-ppss' and the list of paren positions
to navigate upward while ignoring comments.
When travelling forward, use plain up-list with no
looping.
2021-03-07 11:20:51 -05:00
Eric Ludlam
baa7c1210e tests/blocks.m:
Remove mlint warnings.
Full indent so blank-lines don't change on buffer indent.
2021-03-07 10:58:19 -05:00
Eric Ludlam
134800317a matlab.el:
(matlab-lattr-block-close): After narrowing buffer,
got to eol, not max - as we had to expand the narrowed region
to handle special syntax chars on eol.

metest.el:
(metest-all-syntax-tests): Add ...
(metest-end-detect-test): New test
(met-end-dect-files): New Var
(metest-comment-string-syntax-test)
(metest-sexp-counting-test, metest-sexp-traversal-test)
(metest-indents-test, metest-parse-test):
Use new `metest-find-file' for loading in files.
(met-indents-files): Add mfuncends.m

tests/empty.m:
tests/mfuncends.m:
tests/mfuncnoend.m:
New test files

tests/stringtest.m:
tests/mclass.m:
Add end-detect expected value cookies.
2021-03-07 10:56:52 -05:00
Eric Ludlam
6fe7a322d6 matlab-syntax.el:
(matlab-cursor-in-string-or-comment)
(matlab-cursor-in-comment, matlab-cursor-in-string):
Convert to use syntax-ppss directly.
2021-03-07 10:50:16 -05:00
Eric Ludlam
f0457f228b matlab.el:
Delete large swaths of code related to syntax tables which
has moved to matlab-syntax.el.
(matlab-syntax): New require.
(matlab-mode-syntax-table, matlab-mode-special-syntax-table):
Moved to matlab-syntax.el
(matlab-font-lock-string-start-regexp)
(matlab-font-lock-string-and-comment-start-regexp)
(matlab-test-allstring-comment-match)
(matlab-font-lock-allstring-comment-match-normal):
No longer needed.  Deleted.
(matlab-font-lock-extend-region):
Switch to use matlab-block-comment-bounds.
(matlab-block-comment-*-re, matlab-ltype-block-comment-*):
Moved to matlab-syntax.el
(matlab-basic-font-lock-keywords):
Delete comment and string highlighting.
(matlab-basic-file-font-lock-keywords):
Delete block comment highlighting.
(matlab-mode): Delete all code related to syntax stuff.
Add call to `matlab-syntax-setup'.
Remove `after-change-functions' - no longer needed to handle block comments.
Enable syntax table font-locking comments/strings.
Remove special forward-sexp-function.
(matlab-navigation-syntax, matlab-up-list):
Moved to matlab-syntax.el
(matlab-with-current-command): Extend restricted region 1 char
past eol to include newline - needed for end-of-comment.
(matlab-backward-up-string-or-comment): Fix ellipsis spelling.
Only backup 1 char, reverse scan goes to beginning, not end of ...
(matlab-move-list-sexp-internal)
(matlab-move-simple-sexp-backward-internal)
(matlab-move-simple-sexp-internal)
Deleted.
(matlab-backward-sexp, matlab-forward-sexp)
(matlab-beginning-of-command, matlab-ltype-comm)
(matlab-debug-block-comm)
(matlab-electric-block-comment)
(matlab-show-paren-or-block)
(matlab-mode-vf-block-matches-forward):
Rename matlab-ltype-block-comm to matlab-block-comment-bounds.
(matlab-ltype-block-comm-bounds, matlab-ltype-block-comm-lastcompute)
(matlab-change-funtion, matlab-ltype-block-comm, matlab-ltype-block-comm-1):
Deleted.
(matlab-ltype-block-comm-at-*)
(matlab-cursor-comment-string-context)
(matlab-cursor-in-string-or-comment)
(matlab-cursor-in-comment)
(matlab-cursor-in-string):
Moved to matlab-syntax.el
(matlab-calculate-indentation-1):
Replace old block comment stuff with new `matlab-block-comment-bounds'.
Stop using old cache, just compute bounds once and use it.

tests/mtest.el:
Rename matlab-ltype-block-comm to matlab-block-comment-bounds.
Fix spelling of ellipsis
Add a little more debugging output.

Makefile, Project.ede:
Add matlab-syntax.el

tests/stringtest.m:
Add some blank lines to protect against indentation.
Fix indentation.
2021-03-07 00:14:21 -05:00
Eric Ludlam
4baad2b86c matlab-syntax.el:
New file - manage syntax table, and utilities that use the
syntax table for parsing strings, comments, and lists.
2021-03-06 23:56:15 -05:00
Eric Ludlam
1b0340b26b matlab.el:
(matlab-lattr-block-close): Account for commend imediately after
the end keyword.
tests/blocks.m:
(tightcomments): Add sample with comments tight to end
of every statement with indentation test cookies.
2021-03-06 13:05:29 -05:00
Eric Ludlam
66721488d9 tests/stringtest.m
Added ellipsis test marks in some places where they were missing.
2021-03-05 20:09:22 -05:00
Eric Ludlam
204fd79f1b matlab.el:
(matlab-valid-end-construct-p): an 'end' after a . is a field,
and not a valid block end.
(matlab-cursor-on-valid-block-start): any block after a . is a field,
and not a valid block start.

mlint.el:
(mlint-lm-missing-end::mlint-fix-entry): Fix too many close )

tests/blocks.m:
Add struct_stuff method to verify not indenting anything after a .

tests/stringtest.m:
Add an invalid block comment (all on one line) with test markers in it.
2021-03-05 16:59:06 -05:00
Eric Ludlam
a8a7b7e73c mlint.el:
(mlint-error-id-fix-alist): Add ENDCT support.
(mlint-lm-missing-end::mlint-fix-entry):
Add support for adding end to functions without ends.
2021-03-05 16:42:43 -05:00
Eric Ludlam
02e9ea0a71 mlint.el:
Add autofix routines for missing ends, and missmatched file/class names.
(mlint-error-id-fix-alist): Add ENDCT2, FNDEF, and MCFIL support.
(mlint-lm-entry::mlint-fix-entry, mlint-lm-*::initialize-instance):
Fix all occurances of :AFTER with :after.
(mlint-lm-function-name): New class.
(mlint-lm-function-name::initialize-instance): New.
(mlint-lm-missing-end): New class.
(mlint-lm-missing-end::mlint-fix-entry): New.
2021-03-04 20:13:31 -05:00
Eric Ludlam
26875b9517 matlab.el:
(matlab-block-end-pre): Reverse choice of regex used if functions have end.
This appears to have been backwards for a very long time.
(tests/blocks.m, tests/indents/m, tests/mclass.m):
Save with correct indentation for blank lines.
Add tests with function ... end on the same line.
2021-03-04 15:28:46 -05:00
Eric Ludlam
44e19af23d matlab.el:
(matlab-cursor-on-valid-block-start):
Replaced previous fix by only looking at the previous end
and verifying it is indented by the standard level.
This (of course) assumes that the whole file is indented correctly.
2021-03-01 19:09:38 -05:00
Eric Ludlam
9872d929ec matlab.el:
Speed up checking for valid class block keywords.
(matlab-find-prev-code-line): New.
Looks for a previous line of code and navs to the beginning of it.
(matlab-cursor-on-valid-block-start):
Stop navigating for full syntactic block check, just look at
prev command and verify it belongs to a class and assume it is correct.
(matlab-previous-line-belongs-to-classdef-p):
New.  Verify previous thing is a class based keyword.
(matlab-calculate-indentation-1):
When indenting `end' ask matlab-backward-sexp to not throw errors.
2021-02-28 12:21:27 -05:00