[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r116223: Implement user option ruby-align-chained-ca
From: |
Dmitry Gutov |
Subject: |
[Emacs-diffs] trunk r116223: Implement user option ruby-align-chained-calls |
Date: |
Fri, 31 Jan 2014 17:13:57 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 116223
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/16593
committer: Dmitry Gutov <address@hidden>
branch nick: trunk
timestamp: Fri 2014-01-31 19:13:49 +0200
message:
Implement user option ruby-align-chained-calls
* lisp/progmodes/ruby-mode.el (ruby-align-chained-calls): New option.
(ruby-smie-grammar): Make "." right-associative. Make its priority
lower than the ternary and all binary operators.
(ruby-smie-rules): Indent "(" relative to the first non-"."
parent, or the first "." parent at indentation. Use
`ruby-align-chained-calls' for indentation of "." tokens.
* test/automated/ruby-mode-tests.el (ruby-align-chained-calls):
New test.
modified:
lisp/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1432
lisp/progmodes/ruby-mode.el
rubymode.el-20091113204419-o5vbwnq5f7feedwu-8804
test/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-8588
test/automated/ruby-mode-tests.el
rubymodetests.el-20120720101201-mn39s4kfopdxj3ek-1
test/indent/ruby.rb ruby.rb-20120424165921-h044139hbrd7snvw-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2014-01-31 09:41:54 +0000
+++ b/lisp/ChangeLog 2014-01-31 17:13:49 +0000
@@ -1,3 +1,13 @@
+2014-01-31 Dmitry Gutov <address@hidden>
+
+ * progmodes/ruby-mode.el (ruby-align-chained-calls): New option.
+ (ruby-smie-grammar): Make "." right-associative. Make its priority
+ lower than the ternary and all binary operators.
+ (ruby-smie-rules): Indent "(" relative to the first non-"."
+ parent, or the first "." parent at indentation. Use
+ `ruby-align-chained-calls' for indentation of "." tokens.
+ (Bug#16593)
+
2014-01-31 Juri Linkov <address@hidden>
* sort.el (delete-duplicate-lines): Remove `:weakness 'key'
=== modified file 'lisp/progmodes/ruby-mode.el'
--- a/lisp/progmodes/ruby-mode.el 2014-01-17 03:15:02 +0000
+++ b/lisp/progmodes/ruby-mode.el 2014-01-31 17:13:49 +0000
@@ -264,6 +264,15 @@
:safe 'listp
:version "24.4")
+(defcustom ruby-align-chained-calls nil
+ "If non-nil, chained method calls on multiple lines will be
+aligned to the same column.
+
+Only has effect when `ruby-use-smie' is t."
+ :type 'boolean
+ :group 'ruby
+ :safe 'booleanp)
+
(defcustom ruby-deep-arglist t
"Deep indent lists in parenthesis when non-nil.
Also ignores spaces after parenthesis when `space'.
@@ -350,10 +359,10 @@
;; but avoids lots of conflicts:
(exp "and" exp) (exp "or" exp))
(exp (exp1) (exp "," exp) (exp "=" exp)
- (id " @ " exp)
- (exp "." id))
+ (id " @ " exp))
(exp1 (exp2) (exp2 "?" exp1 ":" exp1))
- (exp2 ("def" insts "end")
+ (exp2 (exp3) (exp3 "." exp2))
+ (exp3 ("def" insts "end")
("begin" insts-rescue-insts "end")
("do" insts "end")
("class" insts "end") ("module" insts "end")
@@ -380,7 +389,7 @@
(ielsei (itheni) (itheni "else" insts))
(if-body (ielsei) (if-body "elsif" if-body)))
'((nonassoc "in") (assoc ";") (right " @ ")
- (assoc ",") (right "=") (assoc "."))
+ (assoc ",") (right "="))
'((assoc "when"))
'((assoc "elsif"))
'((assoc "rescue" "ensure"))
@@ -399,7 +408,8 @@
(nonassoc ">" ">=" "<" "<=")
(nonassoc "==" "===" "!=")
(nonassoc "=~" "!~")
- (left "<<" ">>"))))))
+ (left "<<" ">>")
+ (right "."))))))
(defun ruby-smie--bosp ()
(save-excursion (skip-chars-backward " \t")
@@ -609,7 +619,18 @@
;; When after `.', let's always de-indent,
;; because when `.' is inside the line, the
;; additional indentation from it looks out of place.
- ((smie-rule-parent-p ".") (smie-rule-parent (- ruby-indent-level)))
+ ((smie-rule-parent-p ".")
+ (let (smie--parent)
+ (save-excursion
+ ;; Traverse up the parents until the parent is "." at
+ ;; indentation, or any other token.
+ (while (and (progn
+ (goto-char (1- (cadr (smie-indent--parent))))
+ (not (ruby-smie--bosp)))
+ (progn
+ (setq smie--parent nil)
+ (smie-rule-parent-p "."))))
+ (smie-rule-parent))))
(t (smie-rule-parent))))))
(`(:after . ,(or `"(" "[" "{"))
;; FIXME: Shouldn't this be the default behavior of
@@ -622,7 +643,10 @@
(unless (or (eolp) (forward-comment 1))
(cons 'column (current-column)))))
(`(:before . "do") (ruby-smie--indent-to-stmt))
- (`(:before . ".") ruby-indent-level)
+ (`(:before . ".")
+ (if (smie-rule-sibling-p)
+ (and ruby-align-chained-calls 0)
+ ruby-indent-level))
(`(:after . "=>") ruby-indent-level)
(`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure"))
(smie-rule-parent))
=== modified file 'test/ChangeLog'
--- a/test/ChangeLog 2014-01-27 19:10:02 +0000
+++ b/test/ChangeLog 2014-01-31 17:13:49 +0000
@@ -1,3 +1,8 @@
+2014-01-31 Dmitry Gutov <address@hidden>
+
+ * automated/ruby-mode-tests.el (ruby-align-chained-calls):
+ New test.
+
2014-01-27 Michael Albinus <address@hidden>
* automated/file-notify-tests.el (file-notify--deftest-remote):
=== modified file 'test/automated/ruby-mode-tests.el'
--- a/test/automated/ruby-mode-tests.el 2014-01-01 07:43:34 +0000
+++ b/test/automated/ruby-mode-tests.el 2014-01-31 17:13:49 +0000
@@ -333,6 +333,20 @@
| 42
| end")))
+(ert-deftest ruby-align-chained-calls ()
+ (let ((ruby-align-chained-calls t))
+ (ruby-should-indent-buffer
+ "one.two.three
+ | .four
+ |
+ |my_array.select { |str| str.size > 5 }
+ | .map { |str| str.downcase }"
+ "one.two.three
+ | .four
+ |
+ |my_array.select { |str| str.size > 5 }
+ | .map { |str| str.downcase }")))
+
(ert-deftest ruby-move-to-block-stops-at-indentation ()
(ruby-with-temp-buffer "def f\nend"
(beginning-of-line)
=== modified file 'test/indent/ruby.rb'
--- a/test/indent/ruby.rb 2014-01-17 03:15:02 +0000
+++ b/test/indent/ruby.rb 2014-01-31 17:13:49 +0000
@@ -257,8 +257,8 @@
bar
foo_bar_tee(1, 2, 3)
- .qux
- .bar
+ .qux.bar
+ .tee
foo do
bar
@@ -338,7 +338,7 @@
%^abc^
ddd
-qux = foo ?
+qux = foo.fee ?
bar :
tee
@@ -348,7 +348,7 @@
zoo
.lose(
- q, p)
+ q, p)
foo(bar:
tee)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r116223: Implement user option ruby-align-chained-calls,
Dmitry Gutov <=