GNU bug report logs -
#16182
24.3.50; ruby-mode: Indentation style of multiline literals with hanging open paren inside other parens
Previous Next
Reported by: Dmitry Gutov <dgutov <at> yandex.ru>
Date: Wed, 18 Dec 2013 03:56:02 UTC
Severity: minor
Found in version 24.3.50
Done: Dmitry Gutov <dgutov <at> yandex.ru>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16182 in the body.
You can then email your comments to 16182 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Wed, 18 Dec 2013 03:56:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Dmitry Gutov <dgutov <at> yandex.ru>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 18 Dec 2013 03:56:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Judging by the open source code, it's not overly popular, but there's a
definite tendency to align literals in these kind of examples to the
beginning of the statement, not to the opening paren that contains them
(which is what ruby-mode does now, as long as there is any text after
the opening round paren):
https://github.com/intridea/grape/blob/master/README.md#basic-usage
Status.create!({
user: current_user,
text: params[:status]
})
https://github.com/intridea/grape/blob/master/lib/grape/endpoint.rb#L79
methods.each do |method|
route_set.add_route(self, {
path_info: route.route_compiled,
request_method: method,
}, route_info: route)
end
The code is the trunk indents the second example like this:
methods.each do |method|
route_set.add_route(self, {
path_info: route.route_compiled,
request_method: method,
}, route_info: route)
end
Which is the preferred style? Should ruby-mode support both?
The former style looks more compact, but it can also make the arguments
following the "de-indented" literal look a bit out of place.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Wed, 18 Dec 2013 04:06:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 16182 <at> debbugs.gnu.org (full text, mbox):
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16182
Comments welcome.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Wed, 18 Dec 2013 10:32:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Personally I dislike this style, because you’re basically it obscures the semantics of the method arguments, but I acknowledge that I’ve seen it the wild. For me it would be more beneficial if we supported a variant of the style:
methods.each do |method| route_set.add_route( self, { path_info: route.route_compiled, request_method: method, }, route_info: route ) end
The current trunk indents this all wrong:
methods.each do |method| route_set.add_route( self, { path_info: route.route_compiled, request_method: method, }, route_info: route ) end
Something that’s not mentioned here, but it’s a bigger problem for the users is probably the fact that we don’t support the following indentation style:
x = if something
do_something
end
Even if I don’t use and (and the majority of Ruby hackers AFAIK) it’s still fairly popular. Currently this is the only supported option (which is arguably the most popular):
x = if something
do_something
end
--
Cheers,
Bozhidar
On Wednesday, December 18, 2013 at 6:05 AM, Dmitry Gutov wrote:
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16182
>
> Comments welcome.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Wed, 18 Dec 2013 12:43:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 16182 <at> debbugs.gnu.org (full text, mbox):
> Status.create!({
> user: current_user,
> text: params[:status]
> })
This looks fine.
> https://github.com/intridea/grape/blob/master/lib/grape/endpoint.rb#L79
> methods.each do |method|
> route_set.add_route(self, {
> path_info: route.route_compiled,
> request_method: method,
> }, route_info: route)
> end
But this looks confusing to me. If (as a coder) I wanted to keep the
code "not too deeply indented", I'd use something like:
methods.each do |method|
route_set.add_route(
self,
{ path_info: route.route_compiled,
request_method: method, },
route_info: route)
end
But that's just me (and I haven't checked to see if the current
indenter would get this right).
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Wed, 18 Dec 2013 17:58:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Personally I like the alignment to the beginning of the statement rather to
the open paren. When I'm breaking line on argument list it's because the
line is too long. With indentation to the opened paren the line stays long
despite breaking the line.
I think this is how vim indents ruby code by default.
I you ask me emacs can only support the indentation to the beginning of the
statement.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 04:36:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 16182 <at> debbugs.gnu.org (full text, mbox):
Bozhidar Batsov <bozhidar <at> batsov.com> writes:
> Personally I dislike this style, because you’re basically it obscures
> the semantics of the method arguments, but I acknowledge that I’ve
> seen it the wild.
Ok, that's a -1, then.
> For me it would be more beneficial if we supported a
> variant of the style:
>
> methods.each do |method|
> route_set.add_route(
> self, {
> path_info: route.route_compiled,
> request_method: method,
> }, route_info: route
> )
> end
Should work now, with revision 115602.
> Something that’s not mentioned here, but it’s a bigger problem for the
> users is probably the fact that we don’t support the following
> indentation style:
>
> x = if something
> do_something
> end
>
> Even if I don’t use and (and the majority of Ruby hackers AFAIK) it’s
> still fairly popular.
It's actually easy to do now, but the old engine doesn't support that
either. That should be takes as evidence that Emacs Rubyists don't care
about this variant much (I didn't see it in feature requests either).
So I'd rather wait for a request from someone who actually would use it.
If you'd like to add it now, please propose the name of the user option.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 04:50:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 16182 <at> debbugs.gnu.org (full text, mbox):
Adam Sokolnicki <adam.sokolnicki <at> gmail.com> writes:
> Personally I like the alignment to the beginning of the statement
> rather to the open paren.
Let's count this as +1.
> When I'm breaking line on argument list it's
> because the line is too long. With indentation to the opened paren the
> line stays long despite breaking the line.
Like Stefan suggests, if the opened paren is immediately followed by a
newline, the arguments will be indented less (but still indented by
additional two columns, compared to the beginning of the statement).
> I think this is how vim indents ruby code by default.
If that's true, could you point to:
* Some other open source project or two using this style.
* Some tutorial or step-by-step instruction for me to test this
indentation in Vim. Do I need to install anything apart from the base
distribution?
Suppose I have the snippet of code typed out. What do I press next?
> I you ask me emacs can only support the indentation to the beginning
> of the statement.
I don't think it's sufficient, by itself.
Take this example:
current_user.statuses.find(params[:id]).update({
user: current_user,
text: params[:status]
})
Suppose `update' accepted a second argument, and we wanted to pass it
here, on the next line after the hash. Which column would it be indented
to? 0?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 04:58:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 16182 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:
>> Status.create!({
>> user: current_user,
>> text: params[:status]
>> })
>
> This looks fine.
This is not hard to support (add some `skip-syntax-forward' before the
relevant `smie-indent--hanging-p' call), but does it make sense to
indent this call one way, and when the first argument does not start
with a hanging paren (like `self', in the example below), do it
differently?
>> methods.each do |method|
>> route_set.add_route(self, {
>> path_info: route.route_compiled,
>> request_method: method,
>> }, route_info: route)
>> end
> But this looks confusing to me. If (as a coder) I wanted to keep the
> code "not too deeply indented", I'd use something like:
>
> methods.each do |method|
> route_set.add_route(
> self,
> { path_info: route.route_compiled,
> request_method: method, },
> route_info: route)
> end
I agree it makes sense, but this change could be not entirely obvious to
users not familiar with Emacs indentation engines.
> But that's just me (and I haven't checked to see if the current
> indenter would get this right).
It does now.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 09:09:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Thursday, December 19, 2013 at 6:35 AM, Dmitry Gutov wrote:
> Bozhidar Batsov <bozhidar <at> batsov.com (mailto:bozhidar <at> batsov.com)> writes:
>
> > Personally I dislike this style, because you’re basically it obscures
> > the semantics of the method arguments, but I acknowledge that I’ve
> > seen it the wild.
> >
>
>
> Ok, that's a -1, then.
>
> > For me it would be more beneficial if we supported a
> > variant of the style:
> >
> > methods.each do |method|
> > route_set.add_route(
> > self, {
> > path_info: route.route_compiled,
> > request_method: method,
> > }, route_info: route
> > )
> > end
> >
>
>
> Should work now, with revision 115602.
>
> > Something that’s not mentioned here, but it’s a bigger problem for the
> > users is probably the fact that we don’t support the following
> > indentation style:
> >
> > x = if something
> > do_something
> > end
> >
> > Even if I don’t use and (and the majority of Ruby hackers AFAIK) it’s
> > still fairly popular.
> >
>
>
> It's actually easy to do now, but the old engine doesn't support that
> either. That should be takes as evidence that Emacs Rubyists don't care
> about this variant much (I didn't see it in feature requests either).
>
> So I'd rather wait for a request from someone who actually would use it.
> If you'd like to add it now, please propose the name of the user option.
>
>
I recall seeing StackOverflow questions about this in Emacs, but as I neither practice nor promote this style I’m indifferent to supporting it in Emacs. I do, however, support it in RuboCop (https://github.com/bbatsov/rubocop/issues/661). If we decide to have it in Emacs we might use a similar name for the config variable - `ruby-end-alignment’ with two options - ‘keword and ‘assignment.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 12:56:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
I can confirm that your method args indentation fix is working. I did, however, notice the following problem after I mentioned the if/unless/case with assignment indentation. Consider the following:
res = method do |x, y|
something
end
Might make sense to indent those like:
res = method do |x, y|
something
end
for consistency with the if/unless/case indentation by default. Also:
res =
method do |x, y|
something
end
is actually indented like this:
res =
method do |x, y|
something
end
--
Cheers,
Bozhidar
On Thursday, December 19, 2013 at 11:08 AM, Bozhidar Batsov wrote:
> On Thursday, December 19, 2013 at 6:35 AM, Dmitry Gutov wrote:
> > Bozhidar Batsov <bozhidar <at> batsov.com (mailto:bozhidar <at> batsov.com)> writes:
> >
> > > Personally I dislike this style, because you’re basically it obscures
> > > the semantics of the method arguments, but I acknowledge that I’ve
> > > seen it the wild.
> > >
> >
> >
> > Ok, that's a -1, then.
> >
> > > For me it would be more beneficial if we supported a
> > > variant of the style:
> > >
> > > methods.each do |method|
> > > route_set.add_route(
> > > self, {
> > > path_info: route.route_compiled,
> > > request_method: method,
> > > }, route_info: route
> > > )
> > > end
> > >
> >
> >
> > Should work now, with revision 115602.
> >
> > > Something that’s not mentioned here, but it’s a bigger problem for the
> > > users is probably the fact that we don’t support the following
> > > indentation style:
> > >
> > > x = if something
> > > do_something
> > > end
> > >
> > > Even if I don’t use and (and the majority of Ruby hackers AFAIK) it’s
> > > still fairly popular.
> > >
> >
> >
> > It's actually easy to do now, but the old engine doesn't support that
> > either. That should be takes as evidence that Emacs Rubyists don't care
> > about this variant much (I didn't see it in feature requests either).
> >
> > So I'd rather wait for a request from someone who actually would use it.
> > If you'd like to add it now, please propose the name of the user option.
> >
> >
> >
>
> I recall seeing StackOverflow questions about this in Emacs, but as I neither practice nor promote this style I’m indifferent to supporting it in Emacs. I do, however, support it in RuboCop (https://github.com/bbatsov/rubocop/issues/661). If we decide to have it in Emacs we might use a similar name for the config variable - `ruby-end-alignment’ with two options - ‘keword and ‘assignment.
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 13:48:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 16182 <at> debbugs.gnu.org (full text, mbox):
> I agree it makes sense, but this change could be not entirely obvious to
> users not familiar with Emacs indentation engines.
I didn't get this indentation from SMIE. I wrote SMIE to understand
this style of indentation. AFAIK this style of indentation is 100%
standard, especially for open braces in C/C++/...
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 13:48:03 GMT)
Full text and
rfc822 format available.
Message #38 received at 16182 <at> debbugs.gnu.org (full text, mbox):
Bozhidar Batsov <bozhidar <at> batsov.com> writes:
> I recall seeing StackOverflow questions about this in Emacs, but as I
> neither practice nor promote this style I’m indifferent to supporting
> it in Emacs. I do, however, support it in RuboCop
> (https://github.com/bbatsov/rubocop/issues/661). If we decide to have
> it in Emacs we might use a similar name for the config variable -
> `ruby-end-alignment’ with two options - ‘keword and ‘assignment.
I like this direction, but since there are only two choices, it should
probably be a boolean variable.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 17:16:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 16182 <at> debbugs.gnu.org (full text, mbox):
On 19.12.2013 14:54, Bozhidar Batsov wrote:
> I can confirm that your method args indentation fix is working. I did,
> however, notice the following problem after I mentioned the
> if/unless/case with assignment indentation. Consider the following:
>
> res = method do |x, y|
> something
> end
>
> Might make sense to indent those like:
>
> res = method do |x, y|
> something
> end
>
> for consistency with the if/unless/case indentation by default.
It might be more consistent, but I don't see any projects doing that.
For example, ActiveRecord, Grape, Goliath and Rack don't.
Check out the examples at the top:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/base.rb
https://github.com/rack/rack/blob/master/lib/rack/builder.rb
It can be an option, though.
---
Come to think of it, do you see the "align end to the keyword" style
much? I did a grep on my gems directory, and the other style seems to be
prevalent, especially among the non-core gems:
Pry, RDoc, Minitest, Rubygems, EventMachine, Nokogiri align to keyword.
ActiveRecord, ActiveSupport, other Active* gems, Cucumber, Thor, Grape,
Excon, WebMock, Faraday align to the beginning of the statement.
RSpec uses both. Yard aligns to keyword after "=", but to statement
after "||=".
Maybe we even should align to the statement by default, because, you
know, Rails.
> Also:
>
> res =
> method do |x, y|
> something
> end
>
> is actually indented like this:
>
> res =
> method do |x, y|
> something
> end
Guess we can special-case this.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 18:42:01 GMT)
Full text and
rfc822 format available.
Message #44 received at 16182 <at> debbugs.gnu.org (full text, mbox):
Coincidentally, I mailed Dmitry about this very issue today! He
encouraged me to chime in on the bug.
In my neck of the woods it's common to indent to the beginning of the statement:
x = if y
y + 1
end
x = list.each do |i|
i
end
x = case y
when 1 then 2
end
@x ||= begin
expensive_operation
...
end
CONSTANT = begin
expensive_operation
...
end
I patched my personal ruby-mode to default to this indenting.
Incidentally, as the resident emacs enthusiast my dotfiles are used by
many emacs rubyists here in Seattle.
I'd love to see this supported in the new ruby-mode. Just my two cents.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 20:33:01 GMT)
Full text and
rfc822 format available.
Message #47 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Thursday, December 19, 2013 at 7:15 PM, Dmitry Gutov wrote:
> On 19.12.2013 14:54, Bozhidar Batsov wrote:
> > I can confirm that your method args indentation fix is working. I did,
> > however, notice the following problem after I mentioned the
> > if/unless/case with assignment indentation. Consider the following:
> >
> > res = method do |x, y|
> > something
> > end
> >
> > Might make sense to indent those like:
> >
> > res = method do |x, y|
> > something
> > end
> >
> > for consistency with the if/unless/case indentation by default.
>
> It might be more consistent, but I don't see any projects doing that.
> For example, ActiveRecord, Grape, Goliath and Rack don't.
>
> Check out the examples at the top:
>
> https://github.com/rails/rails/blob/master/activerecord/lib/active_record/base.rb
>
> https://github.com/rack/rack/blob/master/lib/rack/builder.rb
>
> It can be an option, though.
Part of the reason people are not using a particular style from time to time is simply lack of tool support. :-) I guess more people would have used that style if their editor supported it.
>
> ---
>
> Come to think of it, do you see the "align end to the keyword" style
> much? I did a grep on my gems directory, and the other style seems to be
> prevalent, especially among the non-core gems:
>
> Pry, RDoc, Minitest, Rubygems, EventMachine, Nokogiri align to keyword.
>
> ActiveRecord, ActiveSupport, other Active* gems, Cucumber, Thor, Grape,
> Excon, WebMock, Faraday align to the beginning of the statement.
>
> RSpec uses both. Yard aligns to keyword after "=", but to statement
> after "||=".
>
> Maybe we even should align to the statement by default, because, you
> know, Rails.
>
>
Well, even though I develop Rails apps for a living I wouldn’t say the style used in the Rails codebase should be considered some gold standard - after all they are outdenting “private/protected” there :-) That said - before I started using programming Ruby in Emacs I aligned to the beginning of the statement, but I stopped because this wasn’t supported in ruby-mode. After using the alignment to keyword style for several years I’ve grown to like it a lot (and it seems others are enjoying it as well http://stackoverflow.com/questions/2925028/how-do-you-assign-a-variable-with-the-result-of-a-if-else-block). I’m perfectly fine with alignment to statement becoming the default (although the change of this default would be fairly visible/disruptive, since as it stands keyword alignment is the only supported style and I guess most Rubyists using Emacs employ it).
>
> > Also:
> >
> > res =
> > method do |x, y|
> > something
> > end
> >
> > is actually indented like this:
> >
> > res =
> > method do |x, y|
> > something
> > end
> >
>
>
> Guess we can special-case this.
That’d be great.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Thu, 19 Dec 2013 20:43:01 GMT)
Full text and
rfc822 format available.
Message #50 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 19 Dec 2013, at 20:33, Bozhidar Batsov <bozhidar <at> batsov.com> wrote:
> Well, even though I develop Rails apps for a living I wouldn’t say the style used in the Rails codebase should be considered some gold standard - after all they are outdenting “private/protected” there :-) That said - before I started using programming Ruby in Emacs I aligned to the beginning of the statement, but I stopped because this wasn’t supported in ruby-mode. After using the alignment to keyword style for several years I’ve grown to like it a lot (and it seems others are enjoying it as well http://stackoverflow.com/questions/2925028/how-do-you-assign-a-variable-with-the-result-of-a-if-else-block). I’m perfectly fine with alignment to statement becoming the default (although the change of this default would be fairly visible/disruptive, since as it stands keyword alignment is the only supported style and I guess most Rubyists using Emacs employ it).
I really wouldn’t advise changing the default alignment in this case. The current default is “right” for many if not most existing users.
But +1 for there being options. :-)
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Fri, 20 Dec 2013 05:22:01 GMT)
Full text and
rfc822 format available.
Message #53 received at 16182 <at> debbugs.gnu.org (full text, mbox):
On 19.12.2013 22:33, Bozhidar Batsov wrote:
> Part of the reason people are not using a particular style from time to
> time is simply lack of tool support. :-) I guess more people would have
> used that style if their editor supported it.
Maybe so. I'll have to return to the "do" block later, since this kind
of special handling requires finding the beginning of the method chain
(in the general case) that the block is passed to. Other keywords are
simpler.
> Well, even though I develop Rails apps for a living I wouldn’t say the
> style used in the Rails codebase should be considered some gold standard
> - after all they are outdenting “private/protected” there :-)
Yuck indeed. :)
> That said
> - before I started using programming Ruby in Emacs I aligned to the
> beginning of the statement, but I stopped because this wasn’t supported
> in ruby-mode. After using the alignment to keyword style for several
> years I’ve grown to like it a lot (and it seems others are enjoying it
> as well
> http://stackoverflow.com/questions/2925028/how-do-you-assign-a-variable-with-the-result-of-a-if-else-block).
> I’m perfectly fine with alignment to statement becoming the default
> (although the change of this default would be fairly visible/disruptive,
> since as it stands keyword alignment is the only supported style and I
> guess most Rubyists using Emacs employ it).
Well, since there's not much support for changing the defaults, I've
reverted the special handling of "begin" that already made its way in,
and added a user option that would control all applicable keywords:
`ruby-align-to-stmt-keywords', in revision 115624.
Everyone, please try how it works for you, maybe comment on the name, etc.
The feature freeze is in a couple of days, so we have to get the basics
right.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Fri, 20 Dec 2013 09:53:02 GMT)
Full text and
rfc822 format available.
Message #56 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Friday, December 20, 2013 at 7:21 AM, Dmitry Gutov wrote:
> On 19.12.2013 22:33, Bozhidar Batsov wrote:
> > Part of the reason people are not using a particular style from time to
> > time is simply lack of tool support. :-) I guess more people would have
> > used that style if their editor supported it.
> >
>
>
> Maybe so. I'll have to return to the "do" block later, since this kind
> of special handling requires finding the beginning of the method chain
> (in the general case) that the block is passed to. Other keywords are
> simpler.
>
> > Well, even though I develop Rails apps for a living I wouldn’t say the
> > style used in the Rails codebase should be considered some gold standard
> > - after all they are outdenting “private/protected” there :-)
> >
>
>
> Yuck indeed. :)
>
> > That said
> > - before I started using programming Ruby in Emacs I aligned to the
> > beginning of the statement, but I stopped because this wasn’t supported
> > in ruby-mode. After using the alignment to keyword style for several
> > years I’ve grown to like it a lot (and it seems others are enjoying it
> > as well
> > http://stackoverflow.com/questions/2925028/how-do-you-assign-a-variable-with-the-result-of-a-if-else-block).
> > I’m perfectly fine with alignment to statement becoming the default
> > (although the change of this default would be fairly visible/disruptive,
> > since as it stands keyword alignment is the only supported style and I
> > guess most Rubyists using Emacs employ it).
> >
>
>
> Well, since there's not much support for changing the defaults, I've
> reverted the special handling of "begin" that already made its way in,
> and added a user option that would control all applicable keywords:
> `ruby-align-to-stmt-keywords', in revision 115624.
>
>
Just a small nitpick - everything that returns a value is actually an expression, not a statement.
Maybe `ruby-align-to-expr-keywords’ would be a more appropriate name for the option.
>
> Everyone, please try how it works for you, maybe comment on the name, etc.
>
> The feature freeze is in a couple of days, so we have to get the basics
> right.
>
>
Btw, I noticed this in the indent examples:
zoo
.lose(
q, p)
Shouldn’t it be:
zoo
.lose(
q, p)
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Fri, 20 Dec 2013 11:58:02 GMT)
Full text and
rfc822 format available.
Message #59 received at 16182 <at> debbugs.gnu.org (full text, mbox):
On 20.12.2013 11:51, Bozhidar Batsov wrote:
> Just a small nitpick - everything that returns a value is actually an
> expression, not a statement.
It can be both (see "expression statement"). This way it's not
ambiguous, because I'm really aligning to the statement: the containing
expression, which follows the bob or an [implicit] semicolon.
In Rubocop, you've chosen to align to just the parent expression. Maybe
we should find a realistic example where one would be different from the
other.
> Maybe `ruby-align-to-expr-keywords’ would be a more appropriate name for
> the option.
I was thinking rather of `ruby-align-to-statement'. A non-functional
change that may be easier to pronounce.
> Btw, I noticed this in the indent examples:
>
> zoo
> .lose(
> q, p)
>
> Shouldn’t it be:
>
> zoo
> .lose(
> q, p)
Maybe, but that's harder to do. Basically, we'd want to keep the
additional indentation when and only when the parent token (.), or any
one of its siblings (in case of a chained method call) are at indentation.
Checking if the parent is at indentation is easy, but finding its
siblings - not so much.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Fri, 20 Dec 2013 12:45:02 GMT)
Full text and
rfc822 format available.
Message #62 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> When I'm breaking line on argument list it's
>> because the line is too long. With indentation to the opened paren the
>> line stays long despite breaking the line.
>
> Like Stefan suggests, if the opened paren is immediately followed by a
> newline, the arguments will be indented less (but still indented by
> additional two columns, compared to the beginning of the statement).
I did not think about it before. It makes sense.
>> I think this is how vim indents ruby code by default.
> If that's true, could you point to:
>
> * Some other open source project or two using this style.
>
> * Some tutorial or step-by-step instruction for me to test this
> indentation in Vim. Do I need to install anything apart from the > > base
> distribution?
> Suppose I have the snippet of code typed out. What do I press next?
Actually that's not true. I was wrong. Sorry for the confusion.
>> I you ask me emacs can only support the indentation to the beginning
>> of the statement.
>
> I don't think it's sufficient, by itself.
>
> Take this example:
>
> current_user.statuses.find(params[:id]).update({
> user: current_user,
> text: params[:status]
> })
>
> Suppose `update' accepted a second argument, and we wanted to pass it
> here, on the next line after the hash. Which column would it be indented
> to? 0?
Yes it's not sufficient.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Fri, 20 Dec 2013 15:47:02 GMT)
Full text and
rfc822 format available.
Message #65 received at 16182 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Friday, December 20, 2013 at 1:57 PM, Dmitry Gutov wrote:
> On 20.12.2013 11:51, Bozhidar Batsov wrote:
> > Just a small nitpick - everything that returns a value is actually an
> > expression, not a statement.
> >
>
>
> It can be both (see "expression statement"). This way it's not
> ambiguous, because I'm really aligning to the statement: the containing
> expression, which follows the bob or an [implicit] semicolon.
>
> In Rubocop, you've chosen to align to just the parent expression. Maybe
> we should find a realistic example where one would be different from the
> other.
>
>
I don’t quite understand what you mean.
>
> > Maybe `ruby-align-to-expr-keywords’ would be a more appropriate name for
> > the option.
> >
>
>
> I was thinking rather of `ruby-align-to-statement'. A non-functional
> change that may be easier to pronounce.
>
>
Sounds reasonable.
>
> > Btw, I noticed this in the indent examples:
> >
> > zoo
> > .lose(
> > q, p)
> >
> > Shouldn’t it be:
> >
> > zoo
> > .lose(
> > q, p)
> >
>
>
> Maybe, but that's harder to do. Basically, we'd want to keep the
> additional indentation when and only when the parent token (.), or any
> one of its siblings (in case of a chained method call) are at indentation.
>
> Checking if the parent is at indentation is easy, but finding its
> siblings - not so much.
>
>
I guess this can be ignored for now, since such code is not particularly common.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Sat, 21 Dec 2013 15:32:02 GMT)
Full text and
rfc822 format available.
Message #68 received at 16182 <at> debbugs.gnu.org (full text, mbox):
On 20.12.2013 17:46, Bozhidar Batsov wrote:
> On Friday, December 20, 2013 at 1:57 PM, Dmitry Gutov wrote:
>> On 20.12.2013 11:51, Bozhidar Batsov wrote:
>>> Just a small nitpick - everything that returns a value is actually an
>>> expression, not a statement.
>>
>> It can be both (see "expression statement"). This way it's not
>> ambiguous, because I'm really aligning to the statement: the containing
>> expression, which follows the bob or an [implicit] semicolon.
>>
>> In Rubocop, you've chosen to align to just the parent expression. Maybe
>> we should find a realistic example where one would be different from the
>> other.
> I don’t quite understand what you mean.
This example is indented just like Robocop master likes with (AlignWith:
variable):
b = a = if 3 == 4
1
else
2
end
puts a
puts b
Someone correct me if I'm wrong, but I suspect that users who like less
indentation would prefer to have the `if' body and closer to be aligned
to the beginning of the statement, rather than to `a'.
That's what ruby-mode does now if `if' is in `ruby-align-to-stmt-keywords'.
Another reason to pick this behavior is that "align to parent" is harder
to implement. SMIE has no AST: we can find the position of the parent
token (=), but finding the position of `a' will require manual seeking.
And `a' could be more than a plan variable: maybe something like
`b[a+1]' or `foo[:bar][:qux]`.
`=' is also not the only operator we can handle. Aside from its
variations (||=, etc), we might want to support `||' and others.
And the left side of `||' can be an arbitrary expression.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Sat, 21 Dec 2013 15:39:03 GMT)
Full text and
rfc822 format available.
Message #71 received at 16182 <at> debbugs.gnu.org (full text, mbox):
On 21 Dec 2013, at 15:31, Dmitry Gutov <dgutov <at> yandex.ru> wrote:
> This example is indented just like Robocop master likes with (AlignWith: variable):
>
> b = a = if 3 == 4
> 1
> else
> 2
> end
>
> puts a
> puts b
>
>
> Someone correct me if I'm wrong, but I suspect that users who like less indentation would prefer to have the `if' body and closer to be aligned to the beginning of the statement, rather than to `a’.
I wouldn’t personally consider as reasonable *any* scheme which placed related “if”, “else” and “end” keywords at differing levels of indentation.
To get less indentation in the above case, one should place the “if” on a new line IMO.
Just my 2c. :-)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Sat, 21 Dec 2013 15:55:01 GMT)
Full text and
rfc822 format available.
Message #74 received at 16182 <at> debbugs.gnu.org (full text, mbox):
On 21.12.2013 17:38, Steve Purcell wrote:
> I wouldn’t personally consider as reasonable *any* scheme which placed related “if”, “else” and “end” keywords at differing levels of indentation.
You're not the target audience, then. :) Not to worry, this won't be the
default.
But this style or all over the Rails codebase. And, personally, I quite
like this usage of `begin' (basically, one of Adam's examples):
a ||= begin
perform_long_lookup
end
Indenting `if' and friends similarly might be good for consistency, at
least.
(Again, this example is indented differently by default in ruby-mode.)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Sat, 21 Dec 2013 16:50:01 GMT)
Full text and
rfc822 format available.
Message #77 received at 16182 <at> debbugs.gnu.org (full text, mbox):
On 21 Dec 2013, at 15:53, Dmitry Gutov <dgutov <at> yandex.ru> wrote:
> But this style or all over the Rails codebase. And, personally, I quite like this usage of `begin' (basically, one of Adam's examples):
>
> a ||= begin
> perform_long_lookup
> end
>
> Indenting `if' and friends similarly might be good for consistency, at least.
>
> (Again, this example is indented differently by default in ruby-mode.)
For some reason, that example doesn’t look quite as ugly to me. Any “rescue” clause would presumably be aligned to match the “end”.
Obviously my tastes are not self-consistent.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16182
; Package
emacs
.
(Sat, 21 Dec 2013 19:33:01 GMT)
Full text and
rfc822 format available.
Message #80 received at 16182 <at> debbugs.gnu.org (full text, mbox):
> This example is indented just like Robocop master likes with (AlignWith: variable):
>
> b = a = if 3 == 4
> 1
> else
> 2
> end
>
> Someone correct me if I'm wrong, but I suspect that users who like less indentation would prefer to have the `if' body and closer to be aligned to the beginning of the statement, rather than to `a'.
That's right - ideally it would be formatted like so:
b = a = if 3 == 4
1
else
2
end
I think 'ruby-align-to-stmt-keywords' is a perfectly fine name, btw.
Reply sent
to
Dmitry Gutov <dgutov <at> yandex.ru>
:
You have taken responsibility.
(Sun, 22 Dec 2013 02:02:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Dmitry Gutov <dgutov <at> yandex.ru>
:
bug acknowledged by developer.
(Sun, 22 Dec 2013 02:02:03 GMT)
Full text and
rfc822 format available.
Message #85 received at 16182-done <at> debbugs.gnu.org (full text, mbox):
On 21.12.2013 21:32, Adam Doppelt wrote:
> I think 'ruby-align-to-stmt-keywords' is a perfectly fine name, btw.
Ah, okay then. Without an overwhelming support for a rename, the current
name stays.
Thanks everyone, I'm closing this bug now. It has veered off to the
side, but for now the answer to the original question is no, with only
one vote in favor. Let's maybe revisit it again sometime.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 19 Jan 2014 12:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 11 years and 67 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.