ruby-changes:58643
From: aycabta <ko1@a...>
Date: Fri, 8 Nov 2019 16:22:42 +0900 (JST)
Subject: [ruby-changes:58643] 6e72b72881 (master): Suppress "shadowing outer local variable" warning in 2.5
https://git.ruby-lang.org/ruby.git/commit/?id=6e72b72881 From 6e72b72881b42e28d2f97ee023587e3d071fb64b Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Fri, 8 Nov 2019 16:17:53 +0900 Subject: Suppress "shadowing outer local variable" warning in 2.5 diff --git a/lib/reline.rb b/lib/reline.rb index f767807..f5c0f5e 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -260,7 +260,10 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L260 result = key_stroke.match_status(buffer) case result when :matched - block.(key_stroke.expand(buffer).map{ |c| Reline::Key.new(c, c, false) }) + expanded = key_stroke.expand(buffer).map{ |expanded_c| + Reline::Key.new(expanded_c, expanded_c, false) + } + block.(expanded) break when :matching if buffer.size == 1 @@ -289,7 +292,10 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L292 if buffer.size == 1 and c == "\e".ord read_escaped_key(keyseq_timeout, c, block) else - block.(buffer.map{ |c| Reline::Key.new(c, c, false) }) + expanded = buffer.map{ |expanded_c| + Reline::Key.new(expanded_c, expanded_c, false) + } + block.(expanded) end break end diff --git a/lib/reline/key_stroke.rb b/lib/reline/key_stroke.rb index 2f5415e..83136ed 100644 --- a/lib/reline/key_stroke.rb +++ b/lib/reline/key_stroke.rb @@ -32,7 +32,7 @@ class Reline::KeyStroke https://github.com/ruby/ruby/blob/trunk/lib/reline/key_stroke.rb#L32 end def expand(input) - lhs = key_mapping.keys.select { |lhs| input.start_with? lhs }.sort_by(&:size).reverse.first + lhs = key_mapping.keys.select { |item| input.start_with? item }.sort_by(&:size).reverse.first return input unless lhs rhs = key_mapping[lhs] diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 9ae7e6e..ddb9e0a 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -652,9 +652,9 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L652 else old_waiting_proc = @waiting_proc old_waiting_operator_proc = @waiting_operator_proc - @waiting_proc = proc { |key| + @waiting_proc = proc { |k| old_cursor, old_byte_pointer = @cursor, @byte_pointer - old_waiting_proc.(key) + old_waiting_proc.(k) cursor_diff, byte_pointer_diff = @cursor - old_cursor, @byte_pointer - old_byte_pointer @cursor, @byte_pointer = old_cursor, old_byte_pointer @waiting_operator_proc.(cursor_diff, byte_pointer_diff) @@ -996,8 +996,8 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L996 end width else - str.encode(Encoding::UTF_8).grapheme_clusters.inject(0) { |width, gc| - width + Reline::Unicode.get_mbchar_width(gc) + str.encode(Encoding::UTF_8).grapheme_clusters.inject(0) { |w, gc| + w + Reline::Unicode.get_mbchar_width(gc) } end end @@ -1187,8 +1187,8 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1187 end searcher.resume @searching_prompt = "(reverse-i-search)`': " - @waiting_proc = ->(key) { - case key + @waiting_proc = ->(k) { + case k when "\C-j".ord, "\C-?".ord if @history_pointer @line = Reline::HISTORY[@history_pointer] @@ -1208,9 +1208,9 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1208 @cursor_max = calculate_width(@line) @cursor = @byte_pointer = 0 else - chr = key.is_a?(String) ? key : key.chr(Encoding::ASCII_8BIT) - if chr.match?(/[[:print:]]/) or key == "\C-h".ord or key == 127 - searcher.resume(key) + chr = k.is_a?(String) ? k : k.chr(Encoding::ASCII_8BIT) + if chr.match?(/[[:print:]]/) or k == "\C-h".ord or k == 127 + searcher.resume(k) else if @history_pointer line = Reline::HISTORY[@history_pointer] @@ -1863,13 +1863,13 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1863 end private def vi_replace_char(key, arg: 1) - @waiting_proc = ->(key) { + @waiting_proc = ->(k) { if arg == 1 byte_size = Reline::Unicode.get_next_mbchar_size(@line, @byte_pointer) before = @line.byteslice(0, @byte_pointer) remaining_point = @byte_pointer + byte_size after = @line.byteslice(remaining_point, @line.size - remaining_point) - @line = before + key.chr + after + @line = before + k.chr + after @cursor_max = calculate_width(@line) @waiting_proc = nil elsif arg > 1 @@ -1880,7 +1880,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1880 before = @line.byteslice(0, @byte_pointer) remaining_point = @byte_pointer + byte_size after = @line.byteslice(remaining_point, @line.size - remaining_point) - replaced = key.chr * arg + replaced = k.chr * arg @line = before + replaced + after @byte_pointer += replaced.bytesize @cursor += calculate_width(replaced) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/