Subject: bug#54702: 29.0.50; ruby-mode indentation: endless methods

From: Dmitry Gutov <[email-masked]>
Date: Wed, 27 Apr 2022 05:44:36 +0300

Hi Aaron,

On 04.04.2022 05:03, Aaron Jensen wrote:
> 
> Ruby 3 and 3.1 bring us different versions of endless methods. They
> currently don't indent correctly in `ruby-mode`:
> 
> Current:
> 
> ```rb
> class Bar
>    def foo = bar
> 
>      def baz
>      end
>    end
> ```
> 
> Expected:
> 
> ```rb
> class Bar
>    def foo = bar
> 
>    def baz
>    end
> end
> ```

Thanks for the report.

I'll work on this further, but here's a quick-and-dirty patch to fix the 
indentation problems.

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index a197724634..3733603fb3 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -528,6 +528,9 @@ ruby-smie--forward-token
                (ruby-smie--forward-token)) ;Fully redundant.
               (t ";")))
             ((equal tok "&.") ".")
+           ((and (equal tok "def")
+                 (looking-at " *[a-zA-Z0-9_]* *\\(([^()]*)\\)? *="))
+            "def=")
             (t tok)))))))))

  (defun ruby-smie--backward-token ()
@@ -575,6 +578,9 @@ ruby-smie--backward-token
              (ruby-smie--backward-token)) ;Fully redundant.
             (t ";")))
           ((equal tok "&.") ".")
+         ((and (equal tok "def")
+               (looking-at "def *[a-zA-Z0-9_]* *\\(([^()]*)\\)? *="))
+          "def=")
           (t tok)))))))

  (defun ruby-smie--indent-to-stmt ()