ruby-changes:64469
From: aycabta <ko1@a...>
Date: Tue, 22 Dec 2020 23:51:32 +0900 (JST)
Subject: [ruby-changes:64469] b52bc4a9c2 (master): [ruby/reline] Support isearch-terminators
https://git.ruby-lang.org/ruby.git/commit/?id=b52bc4a9c2 From b52bc4a9c29e80e10b7e64dbebd97117916d3982 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Tue, 22 Dec 2020 04:38:01 +0900 Subject: [ruby/reline] Support isearch-terminators https://github.com/ruby/reline/commit/a7922da16b diff --git a/lib/reline/config.rb b/lib/reline/config.rb index c66810d..4141031 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -38,6 +38,7 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L38 vi-ins-mode-icon emacs-mode-string enable-bracketed-paste + isearch-terminators } VARIABLE_NAME_SYMBOLS = VARIABLE_NAMES.map { |v| :"#{v.tr(?-, ?_)}" } VARIABLE_NAME_SYMBOLS.each do |v| @@ -238,7 +239,7 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L239 when 'completion-query-items' @completion_query_items = value.to_i when 'isearch-terminators' - @isearch_terminators = instance_eval(value) + @isearch_terminators = retrieve_string(value) when 'editing-mode' case value when 'emacs' diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 0584df3..db5cb3d 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1593,9 +1593,11 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1593 searcher = generate_searcher searcher.resume(key) @searching_prompt = "(reverse-i-search)`': " + termination_keys = ["\C-j".ord] + termination_keys.concat(@config.isearch_terminators&.chars&.map(&:ord)) if @config.isearch_terminators @waiting_proc = ->(k) { case k - when "\C-j".ord + when *termination_keys if @history_pointer buffer = Reline::HISTORY[@history_pointer] else diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 04c3254..84233a9 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -1894,6 +1894,36 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_emacs.rb#L1894 assert_cursor_max(0) end + def test_search_history_with_isearch_terminator + @config.read_lines(<<~LINES.split(/(?<=\n)/)) + set isearch-terminators "XYZ" + LINES + Reline::HISTORY.concat([ + '1235', # old + '12aa', + '1234' # new + ]) + assert_line('') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) + input_keys("\C-r12a") + assert_line('12aa') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) # doesn't determine yet + input_keys('Y') + assert_line('12aa') + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(4) + input_keys('x') + assert_line('x12aa') + assert_byte_pointer_size('x') + assert_cursor(1) + assert_cursor_max(5) + end + def test_em_set_mark_and_em_exchange_mark input_keys('aaa bbb ccc ddd') assert_byte_pointer_size('aaa bbb ccc ddd') -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/