]> code.delx.au - gnu-emacs/commitdiff
Support Ruby 2.3.0's safe navigation operator
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 11 Mar 2016 22:18:42 +0000 (00:18 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 11 Mar 2016 22:18:42 +0000 (00:18 +0200)
* lisp/progmodes/ruby-mode.el (ruby-smie--forward-token)
(ruby-smie--backward-token): Tokenize '&.' as '.'.
(ruby-smie--implicit-semi-p): Check for possible '&' before '.'.

* test/indent/ruby.rb: Add an example using safe navigation
operator.  Fix a syntax error in existing example.

lisp/progmodes/ruby-mode.el
test/indent/ruby.rb

index be8f96dcfd9d271948a48634a5c9b63c3f2bbc56..36c1aed529ef634548e7608b3ab9067771ea1513 100644 (file)
@@ -444,7 +444,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
                           '("iuwu-mod" "and" "or")))
              (save-excursion
                (forward-comment 1)
-               (eq (char-after) ?.))))))
+               (looking-at "&?\\."))))))
 
 (defun ruby-smie--redundant-do-p (&optional skip)
   (save-excursion
@@ -535,6 +535,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
                  (line-end-position))
               (ruby-smie--forward-token)) ;Fully redundant.
              (t ";")))
+           ((equal tok "&.") ".")
            (t tok)))))))))
 
 (defun ruby-smie--backward-token ()
@@ -580,6 +581,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
                (line-end-position))
             (ruby-smie--backward-token)) ;Fully redundant.
            (t ";")))
+         ((equal tok "&.") ".")
          (t tok)))))))
 
 (defun ruby-smie--indent-to-stmt ()
index 585263d02a6c713ff076079947d21b3f20ae43b4..51923f79373e6e8a0f46f418879e8ba61ea18eb7 100644 (file)
@@ -24,8 +24,8 @@ d = %(hello (nested) world)
 # Don't propertize percent literals inside strings.
 "(%s, %s)" % [123, 456]
 
-"abc/#{def}ghi"
-"abc\#{def}ghi"
+"abc/#{ddf}ghi"
+"abc\#{ddf}ghi"
 
 # Or inside comments.
 x = # "tot %q/to"; =
@@ -303,8 +303,9 @@ foo ^
   bar
 
 foo_bar_tee(1, 2, 3)
-  .qux.bar
-  .tee
+  .qux&.bar
+  .tee.bar
+  &.tee
 
 foo do
   bar