all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bozhidar Batsov <bozhidar@batsov.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: [ruby-mode] Private/protected method definition layout in Ruby 2.1
Date: Thu, 16 Jan 2014 12:15:49 +0200	[thread overview]
Message-ID: <CAM9Zgm1Nd1j4w-oyFZ4n5Ne0zHXVYbUG3JB7Qqf=AmQ3uDcb+g@mail.gmail.com> (raw)
In-Reply-To: <87r4884gx6.fsf@yandex.ru>

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

I'm OK with the patch, but it makes configuration a bit more difficult
since users should actually know all the alignable keywords. I guess we can
mention `ruby-alignable-keywords' in the docstring
of `ruby-align-to-stmt-keywords' and consider this a good enough hint for
the users. One problem with the current implementation is that it won't
play nice with assignments if you won't to treat them differently:

x = def something
  ala
  bala
end

There won't be a way to get this indentations at the same time:

private def something
  ala
  bala
end

and

x = def something
        ala
        bala
      end

I think that it might make sense to support a different def alignment for
`def` after `private`, `protected`, `public` regardless of the
`ruby-align-to-stmt-keywords' value. What I'm saying is that some people
might prefer to align `def` with a statement beginning only with access
modifier methods. Of course, it seems unlikely that someone will assign the
value of a method def to a variable, but in the future a method definition
in MRI, but it makes sense in Rubinius for instance.



On 16 January 2014 07:47, Dmitry Gutov <dgutov@yandex.ru> wrote:

> Bozhidar Batsov <bozhidar@batsov.com> writes:
>
> > recent changes we did to accommodate similar alignment for `if/unless
> > ` it seems like a good idea to add a defcustom supporting the first
> > style as well.
>
> Come to think of it, why not reuse the same mechanism and defcustom?
>
> The patch below seems to work. Comments?
>
> === modified file 'lisp/progmodes/ruby-mode.el'
> --- lisp/progmodes/ruby-mode.el 2014-01-10 16:32:45 +0000
> +++ lisp/progmodes/ruby-mode.el 2014-01-16 05:35:37 +0000
> @@ -226,7 +226,10 @@
>    :group 'ruby
>    :safe 'integerp)
>
> -(defcustom ruby-align-to-stmt-keywords nil
> +(defconst ruby-alignable-keywords '(if while unless until begin case for
> def)
> +  "Keywords that can be used in `ruby-align-to-stmt-keywords'.")
> +
> +(defcustom ruby-align-to-stmt-keywords '(def)
>    "Keywords after which we align the expression body to statement.
>
>  When nil, an expression that begins with one these keywords is
> @@ -250,17 +253,13 @@
>
>  Only has effect when `ruby-use-smie' is t.
>  "
> -  :type '(choice
> +  :type `(choice
>            (const :tag "None" nil)
>            (const :tag "All" t)
>            (repeat :tag "User defined"
> -                  (choice (const if)
> -                          (const while)
> -                          (const unless)
> -                          (const until)
> -                          (const begin)
> -                          (const case)
> -                          (const for))))
> +                  (choice ,@(mapcar
> +                             (lambda (kw) (list 'const kw))
> +                             ruby-alignable-keywords))))
>    :group 'ruby
>    :safe 'listp
>    :version "24.4")
> @@ -639,7 +638,7 @@
>            (smie-indent--hanging-p)
>            ruby-indent-level))
>      (`(:after . ,(or "?" ":")) ruby-indent-level)
> -    (`(:before . ,(or "if" "while" "unless" "until" "begin" "case" "for"))
> +    (`(:before . ,(guard (memq (intern token) ruby-alignable-keywords)))
>       (when (not (ruby--at-indentation-p))
>         (if (ruby-smie--indent-to-stmt-p token)
>             (ruby-smie--indent-to-stmt)
>
>

[-- Attachment #2: Type: text/html, Size: 4604 bytes --]

  reply	other threads:[~2014-01-16 10:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-15 14:41 [ruby-mode] Private/protected method definition layout in Ruby 2.1 Bozhidar Batsov
2014-01-15 16:24 ` Stefan Monnier
2014-01-15 18:18   ` Dmitry Gutov
2014-01-15 18:51     ` Stefan Monnier
2014-01-16  5:47 ` Dmitry Gutov
2014-01-16 10:15   ` Bozhidar Batsov [this message]
2014-01-16 13:37     ` Dmitry Gutov
2014-01-16 14:26       ` Bozhidar Batsov
2014-01-16 18:40         ` Dmitry Gutov
2014-01-16 19:38           ` Bozhidar Batsov
2014-01-17  3:17             ` 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='CAM9Zgm1Nd1j4w-oyFZ4n5Ne0zHXVYbUG3JB7Qqf=AmQ3uDcb+g@mail.gmail.com' \
    --to=bozhidar@batsov.com \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.