unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Aaron Jensen <aaronjensen@gmail.com>
Cc: 60186@debbugs.gnu.org
Subject: bug#60186: 29.0.60; ruby-mode indentation of multi-line expressions
Date: Tue, 20 Dec 2022 19:31:31 +0200	[thread overview]
Message-ID: <e99e5ae0-df10-920d-cc3a-6564fefa5f75@yandex.ru> (raw)
In-Reply-To: <358bbd65-9375-04c8-f0a2-24a4383f142e@yandex.ru>

[-- Attachment #1: Type: text/plain, Size: 367 bytes --]

On 20/12/2022 18:19, Dmitry Gutov wrote:
> Okay, so there should be two basic cases:
> 
> - Indent to the beginning of the statement,
> - If there was a line continuation (no matter how many), indent 1 extra 
> level?

Here's another quick attempt to make this work without rewriting the 
rest of the logic.

Cases 1 and 2 seem to work now, but not the block example.

[-- Attachment #2: ruby-simplified-indent-v2.diff --]
[-- Type: text/x-patch, Size: 2777 bytes --]

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 1f3e9b6ae7b..02d2e0a2a75 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -285,6 +285,11 @@ ruby-method-params-indent
   :safe (lambda (val) (or (memq val '(t nil)) (numberp val)))
   :version "29.1")
 
+(defcustom ruby-indent-simplified t
+  "Foo bar."
+  :type 'boolean
+  :safe 'booleanp)
+
 (defcustom ruby-deep-arglist t
   "Deep indent lists in parenthesis when non-nil.
 Also ignores spaces after parenthesis when `space'.
@@ -608,15 +613,20 @@ ruby-smie--backward-token
           "def=")
          (t tok)))))))
 
-(defun ruby-smie--indent-to-stmt ()
+(defun ruby-smie--indent-to-stmt (&optional offset)
   (save-excursion
     (smie-backward-sexp ";")
-    (cons 'column (smie-indent-virtual))))
+    (cons 'column (+ (smie-indent-virtual) (or offset 0)))))
 
 (defun ruby-smie--indent-to-stmt-p (keyword)
   (or (eq t ruby-align-to-stmt-keywords)
       (memq (intern keyword) ruby-align-to-stmt-keywords)))
 
+(defconst ruby-smie--operators '("=" "+" "-" "*" "/" "&&" "||" "%" "**" "^" "&"
+                                 "<=>" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>"
+                                 "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" "|"
+                                 "<<=" ">>=" "&&=" "||=" "and" "or"))
+
 (defun ruby-smie-rules (kind token)
   (pcase (cons kind token)
     ('(:elem . basic) ruby-indent-level)
@@ -684,6 +694,14 @@ ruby-smie-rules
            (cons 'column (current-column)))
        (smie-rule-parent (or ruby-method-params-indent 0))))
     ('(:before . "do") (ruby-smie--indent-to-stmt))
+    (`(:after . ,(pred (lambda (token)
+                         (and ruby-indent-simplified
+                              (or
+                               (equal token ".")
+                               (member token ruby-smie--operators))))))
+     (if (smie-indent--hanging-p)
+         (ruby-smie--indent-to-stmt ruby-indent-level)
+       (ruby-smie--indent-to-stmt)))
     ('(:before . ".")
      (if (smie-rule-sibling-p)
          (when ruby-align-chained-calls
@@ -695,9 +713,11 @@ ruby-smie-rules
                    (goto-char (nth 1 parent))
                    (not (smie-rule-bolp)))))
            (cons 'column (current-column)))
-       (smie-backward-sexp ".")
-       (cons 'column (+ (current-column)
-                        ruby-indent-level))))
+       (if ruby-indent-simplified
+           (ruby-smie--indent-to-stmt ruby-indent-level)
+         (smie-backward-sexp ".")
+         (cons 'column (+ (current-column)
+                          ruby-indent-level)))))
     (`(:before . ,(or "else" "then" "elsif" "rescue" "ensure"))
      (smie-rule-parent))
     (`(:before . ,(or "when" "in"))

  reply	other threads:[~2022-12-20 17:31 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19  2:54 bug#60186: 29.0.60; ruby-mode indentation of multi-line expressions Aaron Jensen
2022-12-20  2:12 ` Dmitry Gutov
2022-12-20  2:17   ` Dmitry Gutov
2022-12-20  4:48   ` Aaron Jensen
2022-12-20  5:56     ` Aaron Jensen
2022-12-20 15:53       ` Dmitry Gutov
2022-12-20 16:19     ` Dmitry Gutov
2022-12-20 17:31       ` Dmitry Gutov [this message]
2022-12-21  1:34         ` Aaron Jensen
2022-12-20 20:05       ` Aaron Jensen
2022-12-21 22:48         ` Dmitry Gutov
2022-12-22  2:31           ` Aaron Jensen
2022-12-22 21:21             ` Dmitry Gutov
2022-12-23  4:12               ` Aaron Jensen
2022-12-23 22:26                 ` Dmitry Gutov
2022-12-24  0:17                   ` Aaron Jensen
2022-12-24 22:47                     ` Dmitry Gutov
2022-12-25  0:12                       ` Aaron Jensen
2022-12-25 21:23                         ` Dmitry Gutov
2022-12-25 21:29                         ` bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call Dmitry Gutov
2022-12-25 23:46                           ` Aaron Jensen
2022-12-27  1:16                             ` Dmitry Gutov
2022-12-27  1:38                               ` Aaron Jensen
2022-12-25  0:14                       ` bug#60186: 29.0.60; ruby-mode indentation of multi-line expressions Aaron Jensen
2022-12-25 21:29                         ` Dmitry Gutov
2022-12-27  1:28                         ` Dmitry Gutov
2022-12-27  1:47                           ` Aaron Jensen
2022-12-27 15:56                             ` Dmitry Gutov
2022-12-27 16:34                               ` Aaron Jensen
2022-12-27 23:04                                 ` Dmitry Gutov
2022-12-28  0:38                                   ` Aaron Jensen
2022-12-28  1:02                                     ` Dmitry Gutov
2022-12-28  3:47                                       ` Aaron Jensen
2022-12-28 12:47                                         ` Dmitry Gutov
2022-12-28 21:24                                           ` Dmitry Gutov
2022-12-29 22:59                                             ` Aaron Jensen
2022-12-30 15:02                                               ` Dmitry Gutov
2022-12-30 18:00                                                 ` Aaron Jensen
2022-12-30 18:16                                                   ` Aaron Jensen
2022-12-30 22:07                                                     ` Dmitry Gutov
2022-12-31  1:11                                                       ` Aaron Jensen
2023-01-22  3:02                                                         ` Dmitry Gutov
2023-01-22  5:15                                                           ` Aaron Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e99e5ae0-df10-920d-cc3a-6564fefa5f75@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=60186@debbugs.gnu.org \
    --cc=aaronjensen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).