diff --git a/README.md b/README.md index a6cd6b3b4..483fb9a63 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,7 @@ irb(main):002> a.first. # Completes Integer methods - `NO_COLOR`: Assigning a value to it disables IRB's colorization. - `IRB_USE_AUTOCOMPLETE`: Setting it to `false` disables IRB's autocompletion. +- `IRB_COMPLETOR`: Configures IRB's auto-completion behavior, allowing settings for either `regexp` or `type`. - `VISUAL`: Its value would be used to open files by the `edit` command. - `EDITOR`: Its value would be used to open files by the `edit` command if `VISUAL` is unset. - `IRBRC`: The file specified would be evaluated as IRB's rc-file. diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 470903b45..4df285ce6 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -76,7 +76,7 @@ def IRB.init_config(ap_path) @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod) @CONF[:USE_COLORIZE] = (nc = ENV['NO_COLOR']).nil? || nc.empty? @CONF[:USE_AUTOCOMPLETE] = ENV.fetch("IRB_USE_AUTOCOMPLETE", "true") != "false" - @CONF[:COMPLETOR] = :regexp + @CONF[:COMPLETOR] = ENV.fetch("IRB_COMPLETOR", "regexp").to_sym @CONF[:INSPECT_MODE] = true @CONF[:USE_TRACER] = false @CONF[:USE_LOADER] = false diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index e330cc5e8..b6a8f5529 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -120,6 +120,34 @@ def test_use_autocomplete_environment_variable IRB.conf[:USE_AUTOCOMPLETE] = orig_use_autocomplete_conf end + def test_completor_environment_variable + orig_use_autocomplete_env = ENV['IRB_COMPLETOR'] + orig_use_autocomplete_conf = IRB.conf[:COMPLETOR] + + ENV['IRB_COMPLETOR'] = nil + IRB.setup(__FILE__) + assert_equal(:regexp, IRB.conf[:COMPLETOR]) + + ENV['IRB_COMPLETOR'] = 'regexp' + IRB.setup(__FILE__) + assert_equal(:regexp, IRB.conf[:COMPLETOR]) + + ENV['IRB_COMPLETOR'] = 'type' + IRB.setup(__FILE__) + assert_equal(:type, IRB.conf[:COMPLETOR]) + + ENV['IRB_COMPLETOR'] = 'regexp' + IRB.setup(__FILE__, argv: ['--type-completor']) + assert_equal :type, IRB.conf[:COMPLETOR] + + ENV['IRB_COMPLETOR'] = 'type' + IRB.setup(__FILE__, argv: ['--regexp-completor']) + assert_equal :regexp, IRB.conf[:COMPLETOR] + ensure + ENV['IRB_COMPLETOR'] = orig_use_autocomplete_env + IRB.conf[:COMPLETOR] = orig_use_autocomplete_conf + end + def test_completor_setup_with_argv orig_completor_conf = IRB.conf[:COMPLETOR]