Commit graph

679 commits

Author SHA1 Message Date
Eric Ludlam
2171199ddd matlab.el:
(matlab-lattr-implied-continuation): comment out.
(matlab-lattr-cont): Replace impl w/ new API and ignore implied continuations.
(matlab-find-convenient-line-break): Replace some fcns w/ new versions.
(matlab-auto-fill): Replace some fcns w/ new versions.
2021-03-20 14:33:03 -04:00
Eric Ludlam
400bafe092 matlab-scan.el:
(matlab--mk-keyword-node): Include end pt of found node.
(matlab--valid-keyword-node): New

matlab-syntax.el:
(matlab-move-simple-sexp-backward-internal)
(matlab-move-simple-sexp-internal):
Make defsubst.

matlab.el:
(matlab-show-paren-or-block):
Re-write how blocks like if ... end are highlighted to use new utils
in matlab-scan.el.
2021-03-20 13:48:52 -04:00
Eric Ludlam
125206e4f0 matlab.el:
Delete random commented out code.
Change fcns that ref renamed variables.
(matlab-mode-version): Update!
(matlab-cont-level): Rename to
(matlab-continuation-indent-level): New name
(matlab-case-level): Rename to
(matlab-case-indent-level): New name
(matlab-mode): Doc string tweaks.
2021-03-20 12:49:10 -04:00
Eric Ludlam
ef7894cea5 matlab-syntax.el:
(matlab--scan-line-for-unterminated-string): When comment found,
disable all quote chars in the comment.
(matlab--scan-line-comment-disable-strings):
Find all syntax " chars and disable as whitespace.

tests/indents.m:
Add tests with ' in comments that impact indent.
2021-03-20 12:11:39 -04:00
Eric Ludlam
12d9cfbfe3 matlab-scan.el:
(matlab--valid-mcos-keyword-point, matlab--valid-arguments-keyword-point):
Require these special keywords to be first on the line.

tests/mclass.m:
Add a bunch of badly named methods.
2021-03-20 12:02:28 -04:00
Eric Ludlam
c9dab6d6cd matlab-scan.el:
(matlab-functions-have-end, matlab-indent-level):
Forward declare to quiet byte compiler.
2021-03-20 08:36:17 -04:00
Eric Ludlam
74a4c1f724 tests/continuations.m:
Clean up mlint warnings.
2021-03-20 08:32:47 -04:00
Eric Ludlam
a3dc83e1dc matlab-scan.el:
(matlab--scan-block-forward): When fcns have no end, and a new fcn
block start is found and popped, also go to beginning of found keyword
so next forward-sexp sees it and jumps over next fcn.

matlab.el:
(matlab-backward-sexp, matlab-forward-sexp):
Change chars skipped over @ beginning to better represent
what regular forward/backwar-sexp does.
2021-03-20 08:13:21 -04:00
Eric Ludlam
b4f10db9b9 matlab.el:
(matlab-next-line-indentation): Add special code for multi-end lines
to find originating line and use that indentation.

tests/continuations.m:
Set the indentation for section previous broken.
2021-03-20 01:27:16 -04:00
Eric Ludlam
099433517c matlab.el:
(matlab-lattr-block-close):
Stop decrementing for else type keywords.
(matlab-calculate-indentation-1):
Allow block comments to be help comments.

tests/continuations.m:
Add suite of previously failing tests.

tests/indents.m:
Block comments can now be help.
2021-03-20 01:15:00 -04:00
Eric Ludlam
b1d720eff5 matlab-scan.el:
(matlab-scan-block-start-context): New

matlab.el:
(matlab-lattr-block-cont): Rename to
(matlab-lattr-block-open): New name, return 0 not nil.
(matlab--calc-indent, matlab-show-line-info): Call matlab-next-line-indent w/ new inputs.
(matlab-calculate-indentation-1):
Replace old END indent logic with call to `matlab-scan-block-start-context'
and then stabilize dedent to match block start.
(matlab-next-line-indentation): Better inputs based on what's used.
Delete dead code and commented out code.

tests/continuations.m:
Enabled test that now 'works'.
2021-03-20 00:41:42 -04:00
Eric Ludlam
81cc7718eb matlab-scane.el:
(matlab--buffer-block-tree): Delete
(matlab--scan-block-forward):
Handle case when `matlab-functions-have-end' is false.
(matlab-re-search-keyword-forward,matlab-re-search-keyword-backward):
Handle bounds correctly before restarting a scan.
(matlab-scan-before-change-fcn):
Only clear cached items AFTER the change.

matlab.el:
(matlab-in-command-restriction, matlab-with-current-command)
(matlab-lattr-local-end): DELETE
(matlab-backward-sexp, matlab-forward-sexp):
Reimplement using matlab--scan-block-forward/backward.
(matlab-lattr-block-cont, matlab-lattr-block-close):
Remove narrowing to current command, and use new search utils with bounds.
(matlab-lattr-middle-block-cont): Comment out

tests/metest.m:
(metest-sexp-traversal-test variable): better name.
(metest-sexp-traversal-test): Use new `matlab--scan-block-forward' / backward
instead of orig fcns.

tests/blocks.m:
Tweak a few test points to make them more challenging.
tests/continuations.m:
Added test with continuation, but disabled the problem.
tests/indents.m:
Brought in problem lines that break array sexp w/ ' in continuation
tests/mfuncnoend.m:
Fix whitespace.
tests/mfuncnoendblock.m:
Fix mlint warnings.
2021-03-19 23:28:51 -04:00
Eric Ludlam
ec7421cb58 matlab-scan.el:
Add support for block navigation.

(matlab-on-keyword-p): New
(matlab-kwt-indent, mtlab-kwt-blocks): New regex caches
(matlab-keyword-regex): Update interface to be simpler.
Support more caches for regex.
(matlab-compute-line-context-lvl-1):
Update to use new `matlab-on-keyword-p' feature.

(matlab--buffer-block-tree): New (but not yet used)
(matlab--mk-keyword-node, matlab--known-parent-block): New
(matlab--valid-keyword-point, matlab--valid-arguments-keyword-point): New
(matlab--scan-derive-block-state): New
(matlab--scan-block-forward, matlab--scan-block-forward-up): New
(matlab--scan-block-backward, matlab--scan-block-backward-up): New

(matlab--re-search-keyword-forward, -backward): Moved.

matlab-syntax.el:
(matlab-beginning-of-string-or-comment): Add all-comments optional input.
(matlab-end-of-string-or-comment): Add all-comments optional input.
(matlab-syntax-keyword-as-variable-p): New
(matlab-valid-keyword-syntax): New
2021-03-19 20:02:58 -04:00
Eric Ludlam
e0a7d52385 matlab-scan.el:
(matlab-compute-line-context): Don't change the match data.
(matlab-scan-end-of-command): New

matlab-syntax.el:
Doc string fixes.

matalb.el:
(matlab-find-prev-code-line): Now uses matlab-scan-beginning-of-command
instead of old version.
(matlab-with-current-command): Now uses matlab-scan-beginning-of-command AND
matlab-scan-end-of-command to build the narrowed region.
(matlab-cursor-on-valid-block-start): Make this immune to changes in
match-data from various conditions in the cond statement.
Use new matlab-scan-beginning-of-command instead of old version.
(matlab-beginning-of-command): Now use matlab-scan-beginning-of-command
as default impl.  Delete this fcn later.
(matlab-lattr-block-close):
Track original starting pos better, grab line context  after moving to start.

tests/metest.el:
Include new continuations.m test file.

tests/continuations.m:
New test file

tests/indents.m:
Move a couple tests into continuations.m
2021-03-18 21:48:16 -04:00
Eric Ludlam
3730fb360e matlab-syntax.el:
(matlab-syntax-support-command-dual): New way to control
handling command dual syntax in the syntax table.
(matlab--syntax-propertize): Obey above config by
skipping command dual scanning if nil.

tests/stringtest.m:
Add local variables to enable matlab-syntax-support-command-dual for
this file
2021-03-16 19:09:58 -04:00
Eric Ludlam
dbb6fc6757 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.
2021-03-15 23:31:17 -04:00
Eric Ludlam
9d41e46c98 matlab-scan.el:
Make accessing keywords easier.
(matlab-keyword-p): New
(matlab-compute-line-context-lvl-1): Use above.

matlab-syntax.el:
Support command dual as a string in the syntax tabe.
(matlab--command-dual-syntax): New syntax type
(matlab--syntax-propertize): Call scanner for command-dual.
(matlab--scan-line-for-command-dual): New.
(matlab--font-lock-syntactic-face):
Detect command dual and provide that face.
Detect cellbreak comments and provide that face.
(matlab-cursor-comment-string-context):
Also detect commanddual strings, and return that status.

matlab.el:
Revamp font lock keywords to take advantage of updates in
`matlab--font-lock-syntactic-face' updates, and to just
lean into use of defface.
(matlab-show-mlint-warnings, matlab-highlight-cross-function-variables):
Make safe local variables.
(matlab-commanddual-string-face): New variable.
(matlab-font-lock-adjustments): Delete as a function and hook setup.
Replace with just the classic defface calls, but cleaned up to
also :inherit from base faces.
(matlab-file-basic-font-lock-keywords): Remove cell break code.

tests/metest.el:
Add tests for commanddual strings.
(metest-comment-string-syntax-test):
Add ability to test for commanddual strings.

tests/stringtest.m:
Add some command dual examples.
2021-03-15 21:52:54 -04:00
Eric Ludlam
39f1178516 metest.el:
(metest-indents-randomize-files):
Force matlab-mode to re-run so script type is recomputed after
extra indent added.

mfunspacey.m:
New file for script type detection tests.
2021-03-15 13:52:16 -04:00
Eric Ludlam
cf18bc07fc matlab.el:
(matlab-guess-script-type): After finding code line
goto bol so declaration regex works.
2021-03-15 13:44:11 -04:00
Eric Ludlam
123e38e4a9 matlab-scan.el:
(matlab-kwt-*): New keyword regex caches.
(matlab-keyword-regex, matlab--keyword-regex): New
Create regex for keywords from the keyword table.
(matlab-re-search-keyword-forward, matlab-re-search-keyword-backward):
New search routines that scan for regex outside of strings, comments, and parens.
2021-03-14 22:11:13 -04:00
Eric Ludlam
99d4f7e625 matlab-syntax.el:
(matlab-cursor-in-string-or-comment)
(matlab-cursor-in-comment matlab-cursor-in-string)
(matlab-beginning-of-string-or-comment):
Convert to a single line impl.
Convert to defsubst.
(matlab-end-of-string-or-comment)
(matlab-beginning-of-outer-list)
(matlab-end-of-outer-list): New
2021-03-14 22:09:41 -04:00
Eric Ludlam
880e1837b1 matlab.el:
(matlab-calculate-indentation-1):
when inside parentheticals; capture indentation
of start as our previous indentation.
Later, ignore all that and just use paren column.
Left notes about what else to fix.

tests/indents.m:
Updated to match new indentation logic.
2021-03-14 19:54:46 -04:00
Eric Ludlam
50552dab81 matlab-scan.el:
(matlab-scan-previous-line-ellipsis-p):
Return position, not the column.
(matlab-scan-beginning-of-command):
Recompute the line cache as we search backward.
(matlab-scan-after-change-fcn) ->> rename to
(matlab-scan-before-change-fcn)
(matlab-scan-setup, matlab-scan-disable): Use rename.

matlab.el:
(matlab-lattr-block-close): We can sometimes find
a function for files with endless functions.
Prevent this from acting like an end.
(matlab-indent-region): Disable line-to-line caching
of lvl2.  It isn't stable.
Move refreshing of lvl2 here, but comment out.
(matlab--indent-line): Stop refreshing lvl2 here.
(matlab--change-indentation):
Prevent indentation of less than 0.
(matlab--calc-indent): Accept a debug sym.
(matlab-show-line-info): Use new matlab--calc-indent api.
2021-03-14 19:35:09 -04:00
Eric Ludlam
6fe7da0a62 tests/metest.el
(metest-all-syntax-tests): Force files used for intenting to be
pre-spaced incorrectly.
(metest-condition-case-error-msg): Fix how caught errors are thrown.
(met-indents-files): Add mfuncnoendblock.m
(metest-indents-randomize-files): New
Not really random.
(metest-error): Add a buffer excerpt before throwing an error.

tests/indents.m, tests/mfuncends:
Added more indent tests.
tests/mfuncnoendblock.m:
Add more content.
Enable for use in indentation test.
2021-03-14 19:28:48 -04:00
Eric Ludlam
e30091db8e matlab.el:
(matlab-next-line-indentation):
Remove navigation syntax, and save excursion, not needed anymore.
Stop computing rc, as that didn't seem to be used anymore.
2021-03-14 00:52:49 -05:00
Eric Ludlam
24059939dd matlab.el:
(matlab--indent-line): refresh the context if the line was indented.
(matlab--change-indentation): Fix bug when diff==0
(matlab--calc-indent): Revamp how we compute stuff before matlab-next-line-indentation.
(matlab-next-line-indentation): Use more of the contexts passed in.
Removed `matlab-with-current-command' use.  Replaced with direct call.
This shows we no longer need to narrow the region.
Remove help comment computation - it seemed unused.
(matlab-show-line-info): Update for changed apis.

matlab-scan.el:
(matlab-with-context-line): Fix bug computing pt to move to.
Setup edebug to debug into this macro.
(mlf-previous-line1 & 2): Renamed & new slot.
(mlf-previous-command-beginning): New slot
(matlab-compute-line-context-lvl-2): If avail, store a lvl2 context for
the previous line too.
Transfer the previous command into new lvl2 context.
Add stats logging.
(matlab-refresh-line-context-lvl2): New hook to refresh after an indent.
(matlab-previous-line-lvl2): New accessor that fills in if empty.
(matlab-previous-code-line): Protect against bobp.
(matlab-previous-command-begin): New accessor that fills in if empty.
2021-03-14 00:21:33 -05:00
Eric Ludlam
fb136a19f2 tests/metest.el:
(matlab-all-syntax-tests):
Reset the scanner cache hit stats and print when done.
(metest-test-error): Var flag.
(mecondition-case-error-msg):
When test flag set, forward the error along.
(metest-error): Set metest-test-error flag to pass errors through.

(metest-indent-counts): New
(metest-indents-test): Remove core test into new fcn.
Now set matlab--change-indentation-override to our fcn for tracking.
Now call matlab-indent-region with flags for testing.
(metest-indents-test-hook-fcn): New fcn that does the test
on each line from indent-region after indentation is compuated.
2021-03-14 00:12:36 -05:00
Eric Ludlam
0fa632d8ae matlab.el:
(matlab--change-indentation):
Protect against trying to indent past beginning of the line.
2021-03-13 21:59:32 -05:00
Eric Ludlam
3542ef0150 matlab-scan.el:
(make-keyword-table, matlab-scan-stat-reset):
Use matlab-obarray-make compat layer.
(matlab-scan-stats-print):
Use mapatoms instead of obarray-map for compat.
2021-03-13 21:00:24 -05:00
Eric Ludlam
fd9d7b7088 matlab-compat.el:
(matlab-obarray-make): New compat layer.
2021-03-13 20:59:21 -05:00
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