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

    matlab-ts-mode--ei: fix spacing for method attributes
---
 matlab-ts-mode--ei.el                              | 12 ++++++++---
 .../electric_indent_method_attributes.m            |  9 +++++++++
 .../electric_indent_method_attributes_expected.m   |  9 +++++++++
 ...ectric_indent_method_attributes_expected_msgs.m |  9 +++++++++
 .../electric_indent_method_attributes.m            |  9 +++++++++
 .../electric_indent_method_attributes_expected.txt | 23 ++++++++++++++++++++++
 6 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/matlab-ts-mode--ei.el b/matlab-ts-mode--ei.el
index 84b5a636ad..4d51f1580c 100644
--- a/matlab-ts-mode--ei.el
+++ b/matlab-ts-mode--ei.el
@@ -133,6 +133,9 @@
 
     (,(rx bos (or "," ";" "command_argument" "command_name" "enum-id") eos)  
"."                 1)
 
+    (,(rx bos "attribute-id" eos)    "="                                       
                  0)
+    ("="                             ,(rx bos "attribute-id" eos)              
                  0)
+
     (,matlab-ts-mode--ei-0-after-re   "."                                      
                  0)
 
     (,(rx bos "]" eos)                ,(rx bos (or "," ";") eos)               
                  0)
@@ -234,7 +237,7 @@ be unary-op even though the node type is \"+\"."
       ;; arguments name=value
       (setq node-type "n=v"))
 
-     ;; (1) property identifier => property-id, (2) enum identifier => enum-id
+     ;; property-id, enum-id, attribute-id
      ((string= node-type "identifier")
       (cond ((or
               (and (string= parent-type "property") ;; propertyWithOutDot?
@@ -242,8 +245,11 @@ be unary-op even though the node type is \"+\"."
               (and (string= parent-type "property_name") ;; 
property.nameWithDot?
                    (equal (treesit-node-child (treesit-node-parent parent) 0) 
parent)))
              (setq node-type "property-id"))
-            ((and (string= node-type "identifier") (string= parent-type 
"enum"))
-             (setq node-type "enum-id"))))
+            ((string= parent-type "enum")
+             (setq node-type "enum-id"))
+            ((string= parent-type "attribute")
+             (setq node-type "attribute-id"))
+            ))
 
      ;; Unary operator sign, + or -, e.g. [0 -e] or g = - e
      ((and (string= parent-type "unary_operator")
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes.m
new file mode 100644
index 0000000000..fc13955f65
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes.m
@@ -0,0 +1,9 @@
+% -*- matlab-ts -*-
+
+classdef electric_indent_method_attributes
+    methods (Access =   private, Static)
+        function b = foo(a)
+b = 2 * a;
+        end
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected.m
new file mode 100644
index 0000000000..a97b57b9d2
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected.m
@@ -0,0 +1,9 @@
+% -*- matlab-ts -*-
+
+classdef electric_indent_method_attributes
+    methods (Access=private, Static)
+        function b = foo(a)
+            b = 2 * a;
+        end
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected_msgs.m
 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected_msgs.m
new file mode 100644
index 0000000000..f9db916fb6
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected_msgs.m
@@ -0,0 +1,9 @@
+% -*- matlab-ts -*- %  <{Matched rule: (matlab-ts-mode--i-top-level 
matlab-ts-mode--column-0 0)}>
+
+classdef electric_indent_method_attributes %  <{Matched rule: 
(matlab-ts-mode--i-top-level matlab-ts-mode--column-0 0)}>
+    methods (Access=private, Static) %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+        function b = foo(a) %  <{Matched rule: ((node-is 
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
 parent 4)}>
+            b = 2 * a; %  <{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)}>
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes.m
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes.m
new file mode 100644
index 0000000000..fc13955f65
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes.m
@@ -0,0 +1,9 @@
+% -*- matlab-ts -*-
+
+classdef electric_indent_method_attributes
+    methods (Access =   private, Static)
+        function b = foo(a)
+b = 2 * a;
+        end
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected.txt
 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected.txt
new file mode 100644
index 0000000000..d207d0b0e3
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-parser-files/copy-of-test-matlab-ts-mode-electric-indent-files/electric_indent_method_attributes_expected.txt
@@ -0,0 +1,23 @@
+# -*- t-utils-ts-parse-tree -*-
+(source_file<1,169> (comment[1,20]@{% -*- matlab-ts -*-}@) \n[20,22]
+ (class_definition<22,168> classdef[22,30] name: 
(identifier[31,64]@{electric_indent_method_attributes}@) \n[64,65]
+  (methods<69,164> methods[69,76]
+   (attributes<77,105> ([77,78]
+    (attribute<78,96> (identifier[78,84]@{Access}@) =[85,86] 
(identifier[89,96]@{private}@))
+    ,[96,97]
+    (attribute<98,104> (identifier[98,104]@{Static}@))
+    )[104,105])
+   \n[105,106]
+   (function_definition<114,156> function[114,122]
+    (function_output<123,126> (identifier[123,124]@{b}@) =[125,126])
+    name: (identifier[127,130]@{foo}@)
+    (function_arguments<130,133> ([130,131] arguments: 
(identifier[131,132]@{a}@) )[132,133])
+    \n[133,134]
+    (block<134,145>
+     (assignment<134,143> left: (identifier[134,135]@{b}@) =[136,137]
+      right: (binary_operator<138,143> left: (number[138,139]@{2}@) *[140,141] 
right: (identifier[142,143]@{a}@)))
+     ;[143,144] \n[144,145])
+    end[153,156])
+   \n[156,157] end[161,164])
+  \n[164,165] end[165,168])
+ \n[168,169])

Reply via email to