emacs-devel
[Top][All Lists]
Advanced

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

Re: [ruby-mode] dot-alignment support for multi-line method chaining


From: Dmitry Gutov
Subject: Re: [ruby-mode] dot-alignment support for multi-line method chaining
Date: Wed, 22 Jan 2014 15:41:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi!

Bozhidar Batsov <address@hidden> writes:

> Currently when doing method chaining on multiple lines we get the
> following indentation: 
>
> something.ala
> .one
> .two
> .three
>
> An alternative style that seems to be popular is:
>
> something.ala
> .one
> .two
> .three

Good suggestion, but it looks harder than the previous ones, and it'll
require modifying (or maybe "fixing") the SMIE grammar. At the moment,
the parent of a "." token is never the previous ".".

I have an experimental patch, included at the end, but it throws up some
grammar priority warnings, and it changes the indentation in the
following example:

zoo.keep.bar!(
   {x: y,
    z: t})

If I modify the code a little, the indentation here will be like this:

zoo.keep.bar!(
     {x: y,
      z: t})

which corresponds to

zoo.keep.bar!(
     {x: y,
      z: t}
   )

which, in turn, is a small modification of

zoo.keep
   .bar!(
     {x: y,
      z: t}
   )

Would you consider this appropriate, for the "fluent interface"
indentation? Or how would you indent it instead?

By the way, do you think it'd be good if the same variable toggled between

foo = foobar
      .baz

and

foo = foobar
  .baz

? Or would that be a different variable?

P.S. Could you use the bug tracker for feature requests next time? Bugs
are easier to keep track of and to get back to later.


=== modified file 'lisp/progmodes/ruby-mode.el'
--- lisp/progmodes/ruby-mode.el 2014-01-17 03:15:02 +0000
+++ lisp/progmodes/ruby-mode.el 2014-01-22 13:25:38 +0000
@@ -351,7 +351,7 @@
              (exp "and" exp) (exp "or" exp))
        (exp  (exp1) (exp "," exp) (exp "=" exp)
              (id " @ " exp)
-             (exp "." id))
+             (id "." exp))
        (exp1 (exp2) (exp2 "?" exp1 ":" exp1))
        (exp2 ("def" insts "end")
              ("begin" insts-rescue-insts "end")
@@ -380,7 +380,7 @@
        (ielsei (itheni) (itheni "else" insts))
        (if-body (ielsei) (if-body "elsif" if-body)))
      '((nonassoc "in") (assoc ";") (right " @ ")
-       (assoc ",") (right "=") (assoc "."))
+       (assoc ",") (right "="))
      '((assoc "when"))
      '((assoc "elsif"))
      '((assoc "rescue" "ensure"))
@@ -399,7 +399,8 @@
        (nonassoc ">" ">=" "<" "<=")
        (nonassoc "==" "===" "!=")
        (nonassoc "=~" "!~")
-       (left "<<" ">>"))))))
+       (left "<<" ">>")
+       (assoc "."))))))
 
 (defun ruby-smie--bosp ()
   (save-excursion (skip-chars-backward " \t")
@@ -622,7 +623,10 @@
        (unless (or (eolp) (forward-comment 1))
          (cons 'column (current-column)))))
     (`(:before . "do") (ruby-smie--indent-to-stmt))
-    (`(:before . ".") ruby-indent-level)
+    (`(:before . ".")
+     (if (smie-rule-sibling-p)
+         0
+       ruby-indent-level))
     (`(:after . "=>") ruby-indent-level)
     (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure"))
      (smie-rule-parent))




reply via email to

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