From: Dmitry Gutov Date: Fri, 11 Mar 2016 22:18:42 +0000 (+0200) Subject: Support Ruby 2.3.0's safe navigation operator X-Git-Tag: emacs-25.0.93~98 X-Git-Url: https://code.delx.au/gnu-emacs/commitdiff_plain/576e09e150bceb371b22c4bb26d12991737f689d Support Ruby 2.3.0's safe navigation operator * 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. --- diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index be8f96dcfd..36c1aed529 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -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 () diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 585263d02a..51923f7937 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb @@ -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