summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2014-01-17 05:15:02 +0200
committerDmitry Gutov <dgutov@yandex.ru>2014-01-17 05:15:02 +0200
commitfb3d479c911936b9a10897728547075f91aaea8c (patch)
tree2771cd2816021d7195600f0d9773bd703ffccc9f
parentfc23fe2d522eae464a1ddb738311847c40180662 (diff)
downloademacs-fb3d479c911936b9a10897728547075f91aaea8c.tar.gz
ruby-mode: Align def...end to the beginning of statement
* lisp/progmodes/ruby-mode.el (ruby-alignable-keywords): New constant. (ruby-align-to-stmt-keywords): Change the default value. Use `ruby-alignable-keywords' to generate the possible customization choices. (ruby-smie-rules): Instead of using a hardcoded list of alignable keywords, check against the value of `ruby-alignable-keywords' (http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01439.html).
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/ruby-mode.el19
-rw-r--r--test/indent/ruby.rb4
3 files changed, 23 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b98f68c99ae..25c4e9e75b7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
+2014-01-17 Dmitry Gutov <dgutov@yandex.ru>
+
+ * progmodes/ruby-mode.el (ruby-alignable-keywords): New constant.
+ (ruby-align-to-stmt-keywords): Change the default value. Use
+ `ruby-alignable-keywords' to generate the possible customization
+ choices.
+ (ruby-smie-rules): Instead of using a hardcoded list of alignable
+ keywords, check against the value of `ruby-alignable-keywords'
+ (http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01439.html).
+
2014-01-17 Glenn Morris <rgm@gnu.org>
* emacs-lisp/authors.el (authors-aliases): Remove unnecessary entries.
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 76945adaacb..f0a9da80ea4 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -226,7 +226,10 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
: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 @@ the statement:
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 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
(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-soft token) ruby-alignable-keywords)))
(when (not (ruby--at-indentation-p))
(if (ruby-smie--indent-to-stmt-p token)
(ruby-smie--indent-to-stmt)
diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb
index 0d47bbcf7c0..a0116fef18e 100644
--- a/test/indent/ruby.rb
+++ b/test/indent/ruby.rb
@@ -331,6 +331,10 @@ def qux
end
end
+private def foo
+ bar
+end
+
%^abc^
ddd