From: Dmitry Gutov <dgutov@yandex.ru>
To: Bozhidar Batsov <bozhidar@batsov.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: [ruby-mode] dot-alignment support for multi-line method chaining
Date: Wed, 22 Jan 2014 15:41:24 +0200 [thread overview]
Message-ID: <871u009lrv.fsf@yandex.ru> (raw)
In-Reply-To: <56435202F0F648A3A47605BAE6F847CB@gmail.com> (Bozhidar Batsov's message of "Tue, 21 Jan 2014 14:25:54 +0200")
Hi!
Bozhidar Batsov <bozhidar@batsov.com> 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))
next prev parent reply other threads:[~2014-01-22 13:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-21 12:25 [ruby-mode] dot-alignment support for multi-line method chaining Bozhidar Batsov
2014-01-22 13:41 ` Dmitry Gutov [this message]
2014-01-22 17:28 ` Bozhidar Batsov
2014-01-30 4:31 ` Dmitry Gutov
2014-01-30 8:51 ` Andreas Schwab
2014-01-30 14:45 ` Dmitry Gutov
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871u009lrv.fsf@yandex.ru \
--to=dgutov@yandex.ru \
--cc=bozhidar@batsov.com \
--cc=emacs-devel@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.