Skip to content

Commit

Permalink
[ruby/reline] Refactored Default Key Bindings
Browse files Browse the repository at this point in the history
(ruby/reline#678)

* Reduce duplicate method

* Configured default key mapping with Readline when the method exists

* Remove undefined methods

ruby/reline@155f7047bb
  • Loading branch information
ima1zumi authored and artur-intech committed Apr 26, 2024
1 parent 1d24c2c commit 13949dc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 41 deletions.
20 changes: 10 additions & 10 deletions lib/reline/key_actor/emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
# 23 ^W
:em_kill_region,
# 24 ^X
:ed_sequence_lead_in,
:ed_unassigned,
# 25 ^Y
:em_yank,
# 26 ^Z
Expand Down Expand Up @@ -319,9 +319,9 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
# 158 M-^^
:ed_unassigned,
# 159 M-^_
:em_copy_prev_word,
# 160 M-SPACE
:ed_unassigned,
# 160 M-SPACE
:em_set_mark,
# 161 M-!
:ed_unassigned,
# 162 M-"
Expand Down Expand Up @@ -415,7 +415,7 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
# 206 M-N
:vi_search_next,
# 207 M-O
:ed_sequence_lead_in,
:ed_unassigned,
# 208 M-P
:vi_search_prev,
# 209 M-Q
Expand All @@ -431,15 +431,15 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
# 214 M-V
:ed_unassigned,
# 215 M-W
:em_copy_region,
:ed_unassigned,
# 216 M-X
:ed_command,
# 217 M-Y
:ed_unassigned,
# 217 M-Y
:em_yank_pop,
# 218 M-Z
:ed_unassigned,
# 219 M-[
:ed_sequence_lead_in,
:ed_unassigned,
# 220 M-\
:ed_unassigned,
# 221 M-]
Expand Down Expand Up @@ -495,9 +495,9 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
# 246 M-v
:ed_unassigned,
# 247 M-w
:em_copy_region,
:ed_unassigned,
# 248 M-x
:ed_command,
:ed_unassigned,
# 249 M-y
:ed_unassigned,
# 250 M-z
Expand Down
46 changes: 23 additions & 23 deletions lib/reline/key_actor/vi_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 7 ^G
:ed_unassigned,
# 8 ^H
:ed_unassigned,
:ed_prev_char,
# 9 ^I
:ed_unassigned,
# 10 ^J
Expand All @@ -41,7 +41,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 19 ^S
:ed_ignore,
# 20 ^T
:ed_unassigned,
:ed_transpose_chars,
# 21 ^U
:vi_kill_line_prev,
# 22 ^V
Expand All @@ -51,7 +51,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 24 ^X
:ed_unassigned,
# 25 ^Y
:ed_unassigned,
:em_yank,
# 26 ^Z
:ed_unassigned,
# 27 ^[
Expand All @@ -75,7 +75,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 36 $
:ed_move_to_end,
# 37 %
:vi_match,
:ed_unassigned,
# 38 &
:ed_unassigned,
# 39 '
Expand All @@ -89,11 +89,11 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 43 +
:ed_next_history,
# 44 ,
:vi_repeat_prev_char,
:ed_unassigned,
# 45 -
:ed_prev_history,
# 46 .
:vi_redo,
:ed_unassigned,
# 47 /
:vi_search_prev,
# 48 0
Expand All @@ -117,9 +117,9 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 57 9
:ed_argument_digit,
# 58 :
:ed_command,
:ed_unassigned,
# 59 ;
:vi_repeat_next_char,
:ed_unassigned,
# 60 <
:ed_unassigned,
# 61 =
Expand Down Expand Up @@ -157,41 +157,41 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 77 M
:ed_unassigned,
# 78 N
:vi_repeat_search_prev,
:ed_unassigned,
# 79 O
:ed_sequence_lead_in,
:ed_unassigned,
# 80 P
:vi_paste_prev,
# 81 Q
:ed_unassigned,
# 82 R
:vi_replace_mode,
:ed_unassigned,
# 83 S
:vi_substitute_line,
:ed_unassigned,
# 84 T
:vi_to_prev_char,
# 85 U
:vi_undo_line,
:ed_unassigned,
# 86 V
:ed_unassigned,
# 87 W
:vi_next_big_word,
# 88 X
:ed_delete_prev_char,
# 89 Y
:vi_yank_end,
:ed_unassigned,
# 90 Z
:ed_unassigned,
# 91 [
:ed_sequence_lead_in,
:ed_unassigned,
# 92 \
:ed_unassigned,
# 93 ]
:ed_unassigned,
# 94 ^
:vi_first_print,
# 95 _
:vi_history_word,
:ed_unassigned,
# 96 `
:ed_unassigned,
# 97 a
Expand Down Expand Up @@ -221,7 +221,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 109 m
:ed_unassigned,
# 110 n
:vi_repeat_search_next,
:ed_unassigned,
# 111 o
:ed_unassigned,
# 112 p
Expand All @@ -231,11 +231,11 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 114 r
:vi_replace_char,
# 115 s
:vi_substitute_char,
:ed_unassigned,
# 116 t
:vi_to_next_char,
# 117 u
:vi_undo,
:ed_unassigned,
# 118 v
:vi_histedit,
# 119 w
Expand All @@ -253,9 +253,9 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 125 }
:ed_unassigned,
# 126 ~
:vi_change_case,
# 127 ^?
:ed_unassigned,
# 127 ^?
:em_delete_prev_char,
# 128 M-^@
:ed_unassigned,
# 129 M-^A
Expand Down Expand Up @@ -415,7 +415,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 206 M-N
:ed_unassigned,
# 207 M-O
:ed_sequence_lead_in,
:ed_unassigned,
# 208 M-P
:ed_unassigned,
# 209 M-Q
Expand All @@ -439,7 +439,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
# 218 M-Z
:ed_unassigned,
# 219 M-[
:ed_sequence_lead_in,
:ed_unassigned,
# 220 M-\
:ed_unassigned,
# 221 M-]
Expand Down
4 changes: 2 additions & 2 deletions lib/reline/key_actor/vi_insert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Reline::KeyActor::ViInsert < Reline::KeyActor::Base
# 19 ^S
:vi_search_next,
# 20 ^T
:ed_insert,
:ed_transpose_chars,
# 21 ^U
:vi_kill_line_prev,
# 22 ^V
Expand All @@ -51,7 +51,7 @@ class Reline::KeyActor::ViInsert < Reline::KeyActor::Base
# 24 ^X
:ed_insert,
# 25 ^Y
:ed_insert,
:em_yank,
# 26 ^Z
:ed_insert,
# 27 ^[
Expand Down
7 changes: 1 addition & 6 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class Reline::LineEditor
vi_next_big_word
vi_prev_big_word
vi_end_big_word
vi_repeat_next_char
vi_repeat_prev_char
}

module CompletionState
Expand Down Expand Up @@ -1538,6 +1536,7 @@ def finish
@byte_pointer = 0
end
alias_method :beginning_of_line, :ed_move_to_beg
alias_method :vi_zero, :ed_move_to_beg

private def ed_move_to_end(key)
@byte_pointer = 0
Expand Down Expand Up @@ -2323,10 +2322,6 @@ def finish
copy_for_vi(deleted)
end

private def vi_zero(key)
@byte_pointer = 0
end

private def vi_change_meta(key, arg: nil)
if @vi_waiting_operator
set_current_line('', 0) if @vi_waiting_operator == :vi_change_meta_confirm && arg.nil?
Expand Down

0 comments on commit 13949dc

Please sign in to comment.