[前][次][番号順一覧][スレッド一覧]

ruby-changes:71251

From: Tim <ko1@a...>
Date: Tue, 22 Feb 2022 18:53:10 +0900 (JST)
Subject: [ruby-changes:71251] 37d5890e49 (master): [ruby/reline] Fix support for emacs-ctlx and emacs-meta keymaps

https://git.ruby-lang.org/ruby.git/commit/?id=37d5890e49

From 37d5890e4941cedf6918821b29bb4a7e3a092e62 Mon Sep 17 00:00:00 2001
From: Tim Pope <code@t...>
Date: Fri, 18 Feb 2022 16:11:33 -0500
Subject: [ruby/reline] Fix support for emacs-ctlx and emacs-meta keymaps

The existing implementation, given the below .inputrc, erroneously
creates a "C-v" key binding:

	set keymap emacs-ctlx
	"\C-v": "[C-x C-v was pressed]"

This fixes it to instead create a "C-x C-v" keybinding.

https://github.com/ruby/reline/commit/719f52d231
---
 lib/reline/config.rb       | 16 ++++++++++++++--
 test/reline/test_config.rb | 22 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 5ef5ce4e8d..1bb12a2506 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -55,6 +55,7 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L55
     @if_stack = nil
     @editing_mode_label = :emacs
     @keymap_label = :emacs
+    @keymap_prefix = []
     @key_actors = {}
     @key_actors[:emacs] = Reline::KeyActor::Emacs.new
     @key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new
@@ -221,7 +222,7 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L222
         key, func_name = $1, $2
         keystroke, func = bind_key(key, func_name)
         next unless keystroke
-        @additional_key_bindings[@keymap_label][keystroke] = func
+        @additional_key_bindings[@keymap_label][@keymap_prefix + keystroke] = func
       end
     end
     unless @if_stack.empty?
@@ -292,18 +293,29 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L293
       when 'emacs'
         @editing_mode_label = :emacs
         @keymap_label = :emacs
+        @keymap_prefix = []
       when 'vi'
         @editing_mode_label = :vi_insert
         @keymap_label = :vi_insert
+        @keymap_prefix = []
       end
     when 'keymap'
       case value
-      when 'emacs', 'emacs-standard', 'emacs-meta', 'emacs-ctlx'
+      when 'emacs', 'emacs-standard'
         @keymap_label = :emacs
+        @keymap_prefix = []
+      when 'emacs-ctlx'
+        @keymap_label = :emacs
+        @keymap_prefix = [?\C-x.ord]
+      when 'emacs-meta'
+        @keymap_label = :emacs
+        @keymap_prefix = [?\e.ord]
       when 'vi', 'vi-move', 'vi-command'
         @keymap_label = :vi_command
+        @keymap_prefix = []
       when 'vi-insert'
         @keymap_label = :vi_insert
+        @keymap_prefix = []
       end
     when 'keyseq-timeout'
       @keyseq_timeout = value.to_i
diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb
index e00a47c705..99d190d246 100644
--- a/test/reline/test_config.rb
+++ b/test/reline/test_config.rb
@@ -274,6 +274,28 @@ class Reline::Config::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L274
     assert_equal expected, @config.key_bindings
   end
 
+  def test_additional_key_bindings_for_auxiliary_emacs_keymaps
+    @config.read_lines(<<~'LINES'.lines)
+      set keymap emacs
+      "ab": "AB"
+      set keymap emacs-standard
+      "cd": "CD"
+      set keymap emacs-ctlx
+      "ef": "EF"
+      set keymap emacs-meta
+      "gh": "GH"
+      set editing-mode emacs # keymap changes to be emacs
+    LINES
+
+    expected = {
+      'ab'.bytes => 'AB'.bytes,
+      'cd'.bytes => 'CD'.bytes,
+      "\C-xef".bytes => 'EF'.bytes,
+      "\egh".bytes => 'GH'.bytes,
+    }
+    assert_equal expected, @config.key_bindings
+  end
+
   def test_history_size
     @config.read_lines(<<~LINES.lines)
       set history-size 5000
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]