branch: externals/matlab-mode
commit 641201f76ad3d3552da155b76c25981df7352ef2
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: don't offer to fix function name if it's good
---
matlab-ts-mode.el | 2 +-
.../on_save_no_fix_fcn.m | 27 ++++++++++++++++++++++
.../on_save_no_fix_fcn_expected.org | 15 ++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index c942513ea5..83ac1c5aa9 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -918,7 +918,7 @@ If optional NO-PROMPT is t, fix the name if needed without
prompting."
((string-match-p (rx bol (or "function_definition"
"class_definition") eol)
child-type)
(let* ((def-name-node (treesit-node-child-by-field-name
child "name"))
- (def-name (treesit-node-type def-name-node))
+ (def-name (treesit-node-text def-name-node))
(file-name (file-name-nondirectory (or
(buffer-file-name) (buffer-name))))
(base-name-no-ext (replace-regexp-in-string
"\\.[^.]+\\'" "" file-name)))
;; When base-name-no-ext is a valid name, MATLAB will use
that.
diff --git a/tests/test-matlab-ts-mode-on-save-fixes-files/on_save_no_fix_fcn.m
b/tests/test-matlab-ts-mode-on-save-fixes-files/on_save_no_fix_fcn.m
new file mode 100644
index 0000000000..47d021d126
--- /dev/null
+++ b/tests/test-matlab-ts-mode-on-save-fixes-files/on_save_no_fix_fcn.m
@@ -0,0 +1,27 @@
+% -*- matlab-ts -*-
+
+% (t-utils-xr (rename-buffer "tmp__on_save_no_fix_fcn.m")
(matlab-ts-mode-on-save-fix-name t))
+
+% comment 2
+function tmp__on_save_no_fix_fcn(a)
+% c
+
+ %% heading 1
+ x = {'a', 'c()' 'b'};
+
+ %% heading 2
+ if a
+ disp('foo');
+ else
+ disp('bar');
+ end
+end
+
+function two
+ disp('one')
+
+ function goo
+ disp('goo')
+ end
+end
+
diff --git
a/tests/test-matlab-ts-mode-on-save-fixes-files/on_save_no_fix_fcn_expected.org
b/tests/test-matlab-ts-mode-on-save-fixes-files/on_save_no_fix_fcn_expected.org
new file mode 100644
index 0000000000..900b7fb2b4
--- /dev/null
+++
b/tests/test-matlab-ts-mode-on-save-fixes-files/on_save_no_fix_fcn_expected.org
@@ -0,0 +1,15 @@
+#+startup: showall
+
+* Executing commands from on_save_no_fix_fcn.m:3:2:
+
+ (t-utils-xr (rename-buffer "tmp__on_save_no_fix_fcn.m")
(matlab-ts-mode-on-save-fix-name t))
+
+- Invoking : (rename-buffer "tmp__on_save_no_fix_fcn.m")
+ Start point : 116
+ No point movement
+ No buffer modifications
+
+- Invoking : (matlab-ts-mode-on-save-fix-name t)
+ Start point : 116
+ No point movement
+ No buffer modifications