emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/tuareg c1d5aa1 2/2: Tweak indentation of class definition


From: ELPA Syncer
Subject: [nongnu] elpa/tuareg c1d5aa1 2/2: Tweak indentation of class definition with non-hanging `object`
Date: Sun, 27 Jun 2021 18:57:18 -0400 (EDT)

branch: elpa/tuareg
commit c1d5aa12b1abb2a0cc1756ed331182fce64b6cce
Author: Mattias EngdegÄrd <mattiase@acm.org>
Commit: Mattias EngdegÄrd <mattiase@acm.org>

    Tweak indentation of class definition with non-hanging `object`
    
    Indent non-hanging `object` instead of aligning with their preceding
    `class` token. Previously:
    
    class c =
    object
      method m = 1
    end
    
    Now:
    
    class c =
      object
        method m = 1
      end
    
    which agrees with default ocp-indent and seems to be the more modern
    usage. Also indent `initialize` clauses correctly. (#239)
---
 indent-test.ml | 29 ++++++++++++++++++++++++++++-
 tuareg.el      |  5 +++--
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/indent-test.ml b/indent-test.ml
index 3fa56e6..6a63a09 100644
--- a/indent-test.ml
+++ b/indent-test.ml
@@ -852,11 +852,38 @@ let () =
       >>= fun () -> step2)
 
 class c (a : b) =
-object
+  object
+    inherit d
+    method m = 1
+  end
+
+class c (a : b) =
+  object(self)
+    inherit d
+    method m = 1
+  end
+
+class c (a : b) = object
   inherit d
   method m = 1
 end
 
+class c (a : b) = object(self)
+  inherit d
+  method m = 1
+end
+
+class type restricted_point_type =
+  object
+    method get_x : int
+    method bump : unit
+  end
+
+class type restricted_point_type = object
+  method get_x : int
+  method bump : unit
+end
+
 let f = {
     a = 1;
   }
diff --git a/tuareg.el b/tuareg.el
index 700808d..d977962 100644
--- a/tuareg.el
+++ b/tuareg.el
@@ -2221,7 +2221,7 @@ Return values can be
    ;; An important role of this first condition is to call smie-indent-virtual
    ;; so that we get called back to compute the (virtual) indentation of
    ;; "object", thus making sure we get called back to apply the second rule.
-   ((and (member token '("inherit" "val" "method" "constraint"))
+   ((and (member token '("inherit" "val" "method" "constraint" "initializer"))
          (smie-rule-parent-p "object"))
     (save-excursion
       (forward-word 1)
@@ -2229,7 +2229,8 @@ Return values can be
       (let ((col (smie-indent-virtual)))
         `(column . ,(+ tuareg-default-indent col)))))
    ;; For "class foo = object(type)...end", align object...end with class.
-   ((and (equal token "object") (smie-rule-parent-p "class"))
+   ((and (equal token "object") (smie-rule-parent-p "class")
+         (not (smie-rule-bolp)))
     (smie-rule-parent))))
 
 (defun tuareg-smie--if-then-hack (token)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]