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 2 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
2 changes: 1 addition & 1 deletion lib/reline/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def read_lines(lines, file = nil)
next if if_stack.any? { |_no, skip| skip }

case line
when /^set +([^ ]+) +([^ ]+)/i
when /^set +([^ ]+) +(.+)/i
var, value = $1.downcase, $2
bind_variable(var, value)
Copy link
Member

Choose a reason for hiding this comment

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

For an example input set foo bar baz, how about passing three values to bind_variable?

var = 'foo'
value = 'bar'
raw_value = 'bar baz'
bind_variable(var, value, raw_value)

Most variable still uses value, and some variables (that uses retrieve_string(value) now) will use retrieve_string(raw_value)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Added raw_value as a third argument to bind_variable()

next
Expand Down
16 changes: 10 additions & 6 deletions test/reline/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ def test_unmatched_endif
def test_if_with_mode
@config.read_lines(<<~LINES.lines)
$if mode=emacs
"\C-e": history-search-backward # comment
# comment
"\C-e": history-search-backward
$else
"\C-f": history-search-forward
$endif
Expand All @@ -292,7 +293,8 @@ def test_if_with_mode
def test_else
@config.read_lines(<<~LINES.lines)
$if mode=vi
"\C-e": history-search-backward # comment
# comment
"\C-e": history-search-backward
$else
"\C-f": history-search-forward
$endif
Expand All @@ -308,7 +310,8 @@ def test_if_with_invalid_mode
$if mode=vim
"\C-e": history-search-backward
$else
"\C-f": history-search-forward # comment
# comment
"\C-f": history-search-forward
$endif
LINES

Expand Down Expand Up @@ -388,7 +391,8 @@ def test_additional_key_bindings_for_other_keymap
"cd": "CD"
set keymap emacs
"ef": "EF"
set editing-mode vi # keymap changes to be vi-insert
# keymap changes to be vi-insert
set editing-mode vi
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Although inline comment does not exist, we should support ignore-after-space feature because readline behave like inline comment exists and it is actually used.

# ignore after space
"\C-f": history-search-forward ignored-string
set editing-mode vi ignored-string

# do not ignore after space
set emacs-mode-string emacs mode string

I think it is better to leave the test as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Trimmed the comment before handling the line.

LINES

expected = { 'cd'.bytes => 'CD'.bytes }
Expand All @@ -405,7 +409,8 @@ def test_additional_key_bindings_for_auxiliary_emacs_keymaps
"ef": "EF"
set keymap emacs-meta
"gh": "GH"
set editing-mode emacs # keymap changes to be emacs
# keymap changes to be emacs
set editing-mode emacs
LINES

expected = {
Expand Down Expand Up @@ -542,4 +547,3 @@ def test_relative_xdg_config_home
ENV['HOME'] = home_backup
end
end

Loading