Skip to content

Commit 719f52d

Browse files
committed
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.
1 parent 92ee200 commit 719f52d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/reline/config.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def initialize
5555
@if_stack = nil
5656
@editing_mode_label = :emacs
5757
@keymap_label = :emacs
58+
@keymap_prefix = []
5859
@key_actors = {}
5960
@key_actors[:emacs] = Reline::KeyActor::Emacs.new
6061
@key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new
@@ -221,7 +222,7 @@ def read_lines(lines, file = nil)
221222
key, func_name = $1, $2
222223
keystroke, func = bind_key(key, func_name)
223224
next unless keystroke
224-
@additional_key_bindings[@keymap_label][keystroke] = func
225+
@additional_key_bindings[@keymap_label][@keymap_prefix + keystroke] = func
225226
end
226227
end
227228
unless @if_stack.empty?
@@ -292,18 +293,29 @@ def bind_variable(name, value)
292293
when 'emacs'
293294
@editing_mode_label = :emacs
294295
@keymap_label = :emacs
296+
@keymap_prefix = []
295297
when 'vi'
296298
@editing_mode_label = :vi_insert
297299
@keymap_label = :vi_insert
300+
@keymap_prefix = []
298301
end
299302
when 'keymap'
300303
case value
301-
when 'emacs', 'emacs-standard', 'emacs-meta', 'emacs-ctlx'
304+
when 'emacs', 'emacs-standard'
302305
@keymap_label = :emacs
306+
@keymap_prefix = []
307+
when 'emacs-ctlx'
308+
@keymap_label = :emacs
309+
@keymap_prefix = [?\C-x.ord]
310+
when 'emacs-meta'
311+
@keymap_label = :emacs
312+
@keymap_prefix = [?\e.ord]
303313
when 'vi', 'vi-move', 'vi-command'
304314
@keymap_label = :vi_command
315+
@keymap_prefix = []
305316
when 'vi-insert'
306317
@keymap_label = :vi_insert
318+
@keymap_prefix = []
307319
end
308320
when 'keyseq-timeout'
309321
@keyseq_timeout = value.to_i

test/reline/test_config.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,28 @@ def test_additional_key_bindings_for_other_keymap
274274
assert_equal expected, @config.key_bindings
275275
end
276276

277+
def test_additional_key_bindings_for_auxiliary_emacs_keymaps
278+
@config.read_lines(<<~'LINES'.lines)
279+
set keymap emacs
280+
"ab": "AB"
281+
set keymap emacs-standard
282+
"cd": "CD"
283+
set keymap emacs-ctlx
284+
"ef": "EF"
285+
set keymap emacs-meta
286+
"gh": "GH"
287+
set editing-mode emacs # keymap changes to be emacs
288+
LINES
289+
290+
expected = {
291+
'ab'.bytes => 'AB'.bytes,
292+
'cd'.bytes => 'CD'.bytes,
293+
"\C-xef".bytes => 'EF'.bytes,
294+
"\egh".bytes => 'GH'.bytes,
295+
}
296+
assert_equal expected, @config.key_bindings
297+
end
298+
277299
def test_history_size
278300
@config.read_lines(<<~LINES.lines)
279301
set history-size 5000

0 commit comments

Comments
 (0)