Skip to content

Implement re-read-init-file #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions lib/reline/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class InvalidInputrc < RuntimeError
attr_accessor :autocompletion

def initialize
reset_variables
end

def reset
if editing_mode_is?(:vi_command)
@editing_mode_label = :vi_insert
end
@oneshot_key_bindings.clear
end

def reset_variables
@additional_key_bindings = { # from inputrc
emacs: Reline::KeyActor::Base.new,
vi_insert: Reline::KeyActor::Base.new,
Expand All @@ -54,13 +65,7 @@ def initialize
@convert_meta = true if seven_bit_encoding?(Reline::IOGate.encoding)
@loaded = false
@enable_bracketed_paste = true
end

def reset
if editing_mode_is?(:vi_command)
@editing_mode_label = :vi_insert
end
@oneshot_key_bindings.clear
@show_mode_in_prompt = false
end

def editing_mode
Expand Down Expand Up @@ -360,6 +365,11 @@ def parse_keyseq(str)
ret
end

def reload
reset_variables
read
end

private def seven_bit_encoding?(encoding)
encoding == Encoding::US_ASCII
end
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2554,4 +2554,8 @@ def finish
private def set_next_action_state(type, value)
@next_action_state = [type, value]
end

private def re_read_init_file(_key)
@config.reload
end
end
15 changes: 15 additions & 0 deletions test/reline/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ def setup
Dir.chdir(@tmpdir)
Reline.test_mode
@config = Reline::Config.new
@inputrc_backup = ENV['INPUTRC']
end

def teardown
Dir.chdir(@pwd)
FileUtils.rm_rf(@tmpdir)
Reline.test_reset
@config.reset
ENV['INPUTRC'] = @inputrc_backup
end

def additional_key_bindings(keymap_label)
Expand Down Expand Up @@ -562,4 +564,17 @@ def test_relative_xdg_config_home
ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup
ENV['HOME'] = home_backup
end

def test_reload
inputrc = "#{@tmpdir}/inputrc"
ENV['INPUTRC'] = inputrc

File.write(inputrc, "set emacs-mode-string !")
@config.read
assert_equal '!', @config.emacs_mode_string

File.write(inputrc, "set emacs-mode-string ?")
@config.reload
assert_equal '?', @config.emacs_mode_string
end
end
Loading