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: Bozhidar Batsov
Subject: Re: [ruby-mode] Private/protected method definition layout in Ruby 2.1
Date: Thu, 16 Jan 2014 12:15:49 +0200

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 <address@hidden> wrote:
Bozhidar Batsov <address@hidden> 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)



reply via email to

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