From 24aa55f2dbbf3742d4dea2ecf5e701d28b88f93c Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 11 Sep 2024 21:01:51 +0900 Subject: [PATCH 1/2] Remove KEYWORD_ALIASES which handled special alias name of irb_break irb_catch and irb_next command --- lib/irb/command/help.rb | 2 +- lib/irb/context.rb | 13 +------------ lib/irb/default_commands.rb | 12 +++++++++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/irb/command/help.rb b/lib/irb/command/help.rb index c2018f9b3..12b468fef 100644 --- a/lib/irb/command/help.rb +++ b/lib/irb/command/help.rb @@ -39,7 +39,7 @@ def help_message help_cmds = commands_grouped_by_categories.delete("Help") no_category_cmds = commands_grouped_by_categories.delete("No category") - aliases = irb_context.instance_variable_get(:@user_aliases).map do |alias_name, target| + aliases = irb_context.instance_variable_get(:@command_aliases).map do |alias_name, target| { display_name: alias_name, description: "Alias for `#{target}`" } end diff --git a/lib/irb/context.rb b/lib/irb/context.rb index aa0c60b0e..9e7118c72 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -150,7 +150,7 @@ def initialize(irb, workspace = nil, input_method = nil) end @user_aliases = IRB.conf[:COMMAND_ALIASES].dup - @command_aliases = @user_aliases.merge(KEYWORD_ALIASES) + @command_aliases = @user_aliases.dup end private def term_interactive? @@ -158,17 +158,6 @@ def initialize(irb, workspace = nil, input_method = nil) STDIN.tty? && ENV['TERM'] != 'dumb' end - # because all input will eventually be evaluated as Ruby code, - # command names that conflict with Ruby keywords need special workaround - # we can remove them once we implemented a better command system for IRB - KEYWORD_ALIASES = { - :break => :irb_break, - :catch => :irb_catch, - :next => :irb_next, - }.freeze - - private_constant :KEYWORD_ALIASES - def use_tracer=(val) require_relative "ext/tracer" if val IRB.conf[:USE_TRACER] = val diff --git a/lib/irb/default_commands.rb b/lib/irb/default_commands.rb index fec41df4e..768fbee9d 100644 --- a/lib/irb/default_commands.rb +++ b/lib/irb/default_commands.rb @@ -181,9 +181,15 @@ def load_command(command) [:edit, NO_OVERRIDE] ) - _register_with_aliases(:irb_break, Command::Break) - _register_with_aliases(:irb_catch, Command::Catch) - _register_with_aliases(:irb_next, Command::Next) + _register_with_aliases(:irb_break, Command::Break, + [:break, OVERRIDE_ALL] + ) + _register_with_aliases(:irb_catch, Command::Catch, + [:catch, OVERRIDE_PRIVATE_ONLY] + ) + _register_with_aliases(:irb_next, Command::Next, + [:next, OVERRIDE_ALL] + ) _register_with_aliases(:irb_delete, Command::Delete, [:delete, NO_OVERRIDE] ) From b066e6f9ff26a5c55d584f03c8d77b2e204f8763 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Thu, 12 Sep 2024 23:54:47 +0900 Subject: [PATCH 2/2] Remove unused instance variable user_aliases Co-authored-by: Stan Lo --- lib/irb/context.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 9e7118c72..fafe99d57 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -149,8 +149,7 @@ def initialize(irb, workspace = nil, input_method = nil) @newline_before_multiline_output = true end - @user_aliases = IRB.conf[:COMMAND_ALIASES].dup - @command_aliases = @user_aliases.dup + @command_aliases = IRB.conf[:COMMAND_ALIASES].dup end private def term_interactive?