branch: externals/matlab-mode
commit e1143dd33e1713a0d61dcbb2ea0bae21b1fd411c
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    matlab-ts-mode: electric indent classdef prop get/set methods
---
 matlab-ts-mode--ei.el                                |  7 ++++++-
 .../electric_indent_classdef_prop_get_set.m          | 20 ++++++++++++++++++++
 .../electric_indent_classdef_prop_get_set_expected.m | 20 ++++++++++++++++++++
 ...tric_indent_classdef_prop_get_set_expected_msgs.m | 20 ++++++++++++++++++++
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index aca379a380..0e70c8da13 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -128,7 +128,8 @@
 
 (defvar matlab-ts-mode--ei-val-re (rx bos (or "identifier" "number") eos))
 
-;; TODO optimize following by grouping together, also improve comments
+;; TODO optimize following by grouping together, also improve comments.  
Perhaps write an optimizer
+;; function so rows can remain.
 (defvar matlab-ts-mode--ei-spacing
   ;; In a given line, we walk across the nodes adjusting spaces between NODE 
and NEXT-NODE to
   ;; have N-SPACES-BETWEEN them.
@@ -148,6 +149,10 @@
     ("."                              ,(rx bos "@-fcn-call" eos)               
                  0)
     (,(rx bos "@-fcn-call" eos)       "."                                      
                  0)
 
+    ;; Case: classdef property get/set
+    ;; TopTester: electric_indent_classdef_prop_get_set.m
+    (,(rx bos (or "get." "set.") eos) "."                                      
                  0)
+
     ;; Case: a.?b, M', M.'
     ("."                              ,(rx bos (or ".?" "'" ".'") eos)         
                  0)
     (,(rx bos ".?" eos)               "."                                      
                  0)
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set.m
new file mode 100644
index 0000000000..5cceaffc47
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*-
+classdef electric_indent_classdef_prop_get_set
+    properties
+      inputMatrix = [1 0;0 1]
+    end
+    
+    methods
+        function obj = set.inputMatrix(obj, val)
+            try chol(val)
+                obj.inputMatrix = val;
+               catch ME
+             error("inputMatrix must be symmetric positive definite."  )
+            end
+        end
+
+     function m = get.inputMatrix(obj)
+         m = obj.inputMatrix;
+      end
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set_expected.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set_expected.m
new file mode 100644
index 0000000000..2abff47976
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set_expected.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*-
+classdef electric_indent_classdef_prop_get_set
+    properties
+        inputMatrix = [1 0; 0 1]
+    end
+
+    methods
+        function obj = set.inputMatrix(obj, val)
+            try chol(val)
+                obj.inputMatrix = val;
+            catch ME
+                error("inputMatrix must be symmetric positive definite.")
+            end
+        end
+
+        function m = get.inputMatrix(obj)
+            m = obj.inputMatrix;
+        end
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set_expected_msgs.m
new file mode 100644
index 0000000000..0066b2dd98
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_classdef_prop_get_set_expected_msgs.m
@@ -0,0 +1,20 @@
+% -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+classdef electric_indent_classdef_prop_get_set %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+    properties %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+        inputMatrix = [1 0; 0 1] %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+    end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+
+    methods %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+        function obj = set.inputMatrix(obj, val) %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+            try chol(val) %  <{Matched rule: ((parent-is 
"\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
+                obj.inputMatrix = val; %  <{Matched rule: ((parent-is 
"\\`block\\'") parent 0)}>
+            catch ME %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+                error("inputMatrix must be symmetric positive definite.") %  
<{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+            end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+        end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+
+        function m = get.inputMatrix(obj) %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+            m = obj.inputMatrix; %  <{Matched rule: ((parent-is 
"\\`function_definition\\'") parent 
matlab-ts-mode--set-function-indent-level-for-gp)}>
+        end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+    end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>
+end %  <{Matched rule: ((node-is 
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'") 
parent 0)}>

Reply via email to