From 5e2e68a0c2d7d4e06747ea9fc6112dae8d5e32b6 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Wed, 18 Jan 2023 00:41:14 +0200 Subject: [PATCH] ruby-ts-mode: Fix indent inside parenthesized_expr and else/end after unless * lisp/progmodes/ruby-ts-mode.el (ruby-ts--indent-rules): Fix indentation for parenthesized_expression and else/end after 'unless'. * test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb: New examples. --- lisp/progmodes/ruby-ts-mode.el | 7 +++++-- test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index 19b766ceadb..853c869a319 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -587,11 +587,11 @@ i.e. expr of def foo(args) = expr is returned." ;; ;; I'm using very restrictive patterns hoping to reduce rules ;; triggering unintentionally. - ((match "else" "if") + ((match "else" "if\\|unless") (ruby-ts--align-keywords ruby-ts--parent-node) 0) ((match "elsif" "if") (ruby-ts--align-keywords ruby-ts--parent-node) 0) - ((match "end" "if") + ((match "end" "if\\|unless") (ruby-ts--align-keywords ruby-ts--parent-node) 0) ((n-p-gp nil "then\\|else\\|elsif" "if\\|unless") (ruby-ts--align-keywords ruby-ts--grand-parent-node) ruby-indent-level) @@ -754,6 +754,9 @@ i.e. expr of def foo(args) = expr is returned." ((match "]" "array") parent-bol 0) ((parent-is "array") parent-bol ruby-indent-level) + ((match ")" "parenthesized_statements") parent-bol 0) + ((parent-is "parenthesized_statements") parent-bol ruby-indent-level) + ;; If the previous method isn't finished yet, this will get ;; the next method indented properly. ((n-p-gp ,ruby-ts--method-regex "body_statement" ,ruby-ts--class-or-module-regex) diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb b/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb index 6b4107ef97b..7de94ceadec 100644 --- a/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb +++ b/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb @@ -18,6 +18,16 @@ qux = [1, att = {a: 1, b: 2} +a = 1 ? 2 :( + 2 + 3 +) + +unless bismark + sink += 12 +else + dog = 99 +end + # Local Variables: # mode: ruby-ts # End: -- 2.39.5