Skip to content

Commit

Permalink
Implement re-read-init-file (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
ima1zumi authored Aug 31, 2024
1 parent 0851e93 commit 59e4ade
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
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

0 comments on commit 59e4ade

Please sign in to comment.