Skip to content
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

allow space in config value #705

Merged
merged 5 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 9 additions & 9 deletions lib/reline/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def read_lines(lines, file = nil)

no += 1

line = line.chomp.lstrip
line = line.gsub(/#.*$/, '').chomp.strip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for making confusion, I think we don't need to explicitly implement inline comment because readline does not have it.
But we need to retain set editing-mode vi # pseudo inline comment ignoring " # pseudo inline comment" part because readline ignores it and act like inline comment exist in some directives.
It is already implemented in L186

# value ignores " # pseudo comment" part. raw_value does not.
var, value, raw_value = $1.downcase, $2.partition(' ').first, $2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because readline does not have it.

Sorry for not getting the whole picture 💦 Removed this change!

if line.start_with?('$')
handle_directive(line[1..-1], file, no, if_stack)
next
Expand All @@ -182,9 +182,9 @@ def read_lines(lines, file = nil)
next if if_stack.any? { |_no, skip| skip }

case line
when /^set +([^ ]+) +([^ ]+)/i
var, value = $1.downcase, $2
bind_variable(var, value)
when /^set +([^ ]+) +(.+)/i
var, value, raw_value = $1.downcase, $2.partition(' ').first, $2
bind_variable(var, value, raw_value)
next
when /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o
key, func_name = $1, $2
Expand Down Expand Up @@ -234,7 +234,7 @@ def handle_directive(directive, file, no, if_stack)
end
end

def bind_variable(name, value)
def bind_variable(name, value, raw_value)
case name
when 'history-size'
begin
Expand All @@ -259,7 +259,7 @@ def bind_variable(name, value)
when 'completion-query-items'
@completion_query_items = value.to_i
when 'isearch-terminators'
@isearch_terminators = retrieve_string(value)
@isearch_terminators = retrieve_string(raw_value)
when 'editing-mode'
case value
when 'emacs'
Expand Down Expand Up @@ -301,11 +301,11 @@ def bind_variable(name, value)
@show_mode_in_prompt = false
end
when 'vi-cmd-mode-string'
@vi_cmd_mode_string = retrieve_string(value)
@vi_cmd_mode_string = retrieve_string(raw_value)
when 'vi-ins-mode-string'
@vi_ins_mode_string = retrieve_string(value)
@vi_ins_mode_string = retrieve_string(raw_value)
when 'emacs-mode-string'
@emacs_mode_string = retrieve_string(value)
@emacs_mode_string = retrieve_string(raw_value)
when *VARIABLE_NAMES then
variable_name = :"@#{name.tr(?-, ?_)}"
instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on')
Expand Down
11 changes: 10 additions & 1 deletion test/reline/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,16 @@ def test_inputrc
ENV['INPUTRC'] = inputrc_backup
end

def test_inputrc_raw_value
@config.read_lines(<<~'LINES'.lines)
set editing-mode vi
set vi-ins-mode-string aaa
set vi-cmd-mode-string bbb ccc # comment
LINES
assert_equal 'aaa', @config.vi_ins_mode_string
assert_equal 'bbb ccc', @config.vi_cmd_mode_string
end

def test_inputrc_with_utf8
# This file is encoded by UTF-8 so this heredoc string is also UTF-8.
@config.read_lines(<<~'LINES'.lines)
Expand Down Expand Up @@ -542,4 +552,3 @@ def test_relative_xdg_config_home
ENV['HOME'] = home_backup
end
end

Loading