emacs-devel
[Top][All Lists]
Advanced

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

Re: [ruby-mode] Private/protected method definition layout in Ruby 2.1


From: Stefan Monnier
Subject: Re: [ruby-mode] Private/protected method definition layout in Ruby 2.1
Date: Wed, 15 Jan 2014 11:24:49 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> Ruby 2.1 has made it possible to define private/protected/public
> methods on a per method basis (because a `def` now returns a symbol
> instead of nil). It means that now it’s possible to write code like
> this:
> private def map(attribute, to:)
>   @rules[attribute] = to
> end
> We currently don’t support such an indentation scheme, as `def` is
> always aligned with `end`:
> private def map(attribute, to:)
>               @rules[attribute] = to
>             end

I presume you meant

  private def map(attribute, to:)
            @rules[attribute] = to
          end

> I’m not saying the first alignment is preferable,

That's surprising.  The current alignment just looks like a plain bug to
me and can't think of any reason why someone would prefer it over

  private def map(attribute, to:)
    @rules[attribute] = to
  end

Of course, I don't know Ruby very well, so maybe this just shows my ignorance.

In any case, what I wanted to say here, is that in my experience, the
easiest way to handle such things with SMIE is to make the token code
treat "private def" as a single token (and to call it "def").  This may
sound silly, but trying to DTRT (for similar issues in other modes) by
tweaking grammar plus indentation rules has proved a lot more painful.


        Stefan



reply via email to

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