branch: externals/matlab-mode
commit 2237ab1818cb3b463ed1a7b356f02b35cc888946
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: handle endless functions with electric ends
---
matlab-ts-mode.el | 10 +--
.../electric_ends_function_with_no_end.m | 7 ++
...electric_ends_function_with_no_end_expected.org | 81 ++++++++++++++++++++++
3 files changed, 94 insertions(+), 4 deletions(-)
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 5e190383ca..d259959332 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -3068,12 +3068,14 @@ THERE-END MISMATCH) or nil."
(cond
;; Case: Was a statement entered that requires and end?
- ((string-match-p (rx bos (or "function" "arguments" "if" "switch"
"while" "for" "parfor"
- "spmd" "try" "classdef"
"enumeration" "properties" "methods"
- "events")
+ ((string-match-p (rx bos (or "function" "arguments" "if" "switch"
"while" "for"
+ "parfor" "spmd" "try" "classdef"
"enumeration"
+ "properties" "methods" "events")
eos)
node-type)
- (when (matlab-ts-mode--is-electric-end-missing node) ;; Is the
statement missing an end?
+ (when (and (or (> matlab-ts-mode--function-indent-level 0)
+ (not (string= node-type "function")))
+ (matlab-ts-mode--is-electric-end-missing node)) ;;
Missing an end?
;; Statement for the RET doesn't have an end, so add one at
end-indent-level
(setq end-indent-level (current-indentation))
(setq pre-insert "\n")
diff --git
a/tests/test-matlab-ts-mode-electric-ends-files/electric_ends_function_with_no_end.m
b/tests/test-matlab-ts-mode-electric-ends-files/electric_ends_function_with_no_end.m
new file mode 100644
index 0000000000..1fadd1c965
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-ends-files/electric_ends_function_with_no_end.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*-
+
+function electric_ends_function_with_no_end
+disp('in electric_ends_function_with_no_end')
+foo1();
+
+% Case1: (t-utils-xr "C-n" (insert "function foo1") "C-m" (insert
"disp('foo1')") (t-utils-xr-print-code (point-min) (point-max)))
diff --git
a/tests/test-matlab-ts-mode-electric-ends-files/electric_ends_function_with_no_end_expected.org
b/tests/test-matlab-ts-mode-electric-ends-files/electric_ends_function_with_no_end_expected.org
new file mode 100644
index 0000000000..2913cc6eba
--- /dev/null
+++
b/tests/test-matlab-ts-mode-electric-ends-files/electric_ends_function_with_no_end_expected.org
@@ -0,0 +1,81 @@
+#+startup: showall
+
+* Executing commands from electric_ends_function_with_no_end.m:7:9:
+
+ Case1: (t-utils-xr "C-n" (insert "function foo1") "C-m" (insert
"disp('foo1')") (t-utils-xr-print-code (point-min) (point-max)))
+
+- Invoking : "C-n" = next-line
+ Start point : 251
+ Moved to point: 252
+ : 8:0:
+ : ^
+ No buffer modifications
+
+- Invoking : (insert "function foo1")
+ Start point : 252
+ Moved to point: 265
+ : 8:13: function foo1
+ : ^
+ Buffer modified:
+ #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -5,3 +5,4 @@
+ foo1();
+
+ % Case1: (t-utils-xr "C-n" (insert "function foo1") "C-m" (insert
"disp('foo1')") (t-utils-xr-print-code (point-min) (point-max)))
++function foo1
+\ No newline at end of file
+ #+end_src diff
+
+- Invoking : "C-m" = newline
+ Start point : 265
+ Moved to point: 266
+ : 9:0:
+ : ^
+ Buffer modified:
+ #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -5,4 +5,4 @@
+ foo1();
+
+ % Case1: (t-utils-xr "C-n" (insert "function foo1") "C-m" (insert
"disp('foo1')") (t-utils-xr-print-code (point-min) (point-max)))
+-function foo1
+\ No newline at end of file
++function foo1
+ #+end_src diff
+
+- Invoking : (insert "disp('foo1')")
+ Start point : 266
+ Moved to point: 278
+ : 9:12: disp('foo1')
+ : ^
+ Buffer modified:
+ #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -6,3 +6,4 @@
+
+ % Case1: (t-utils-xr "C-n" (insert "function foo1") "C-m" (insert
"disp('foo1')") (t-utils-xr-print-code (point-min) (point-max)))
+ function foo1
++disp('foo1')
+\ No newline at end of file
+ #+end_src diff
+
+- Invoking : (t-utils-xr-print-code (point-min) (point-max))
+ Start point : 278
+ No point movement
+ standard-output:
+ #+begin_src matlab-ts
+% -*- matlab-ts -*-
+
+function electric_ends_function_with_no_end
+disp('in electric_ends_function_with_no_end')
+foo1();
+
+% Case1: (t-utils-xr \"C-n\" (insert \"function foo1\") \"C-m\" (insert
\"disp('foo1')\") (t-utils-xr-print-code (point-min) (point-max)))
+function foo1
+disp('foo1')
+ #+end_src
+ No buffer modifications