summaryrefslogtreecommitdiff
path: root/lib/reline/config.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/reline/config.rb')
-rw-r--r--lib/reline/config.rb64
1 files changed, 34 insertions, 30 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 4b2655d8eb..d7564ba4b7 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -45,16 +45,17 @@ class Reline::Config
attr_accessor v
end
+ attr_accessor :autocompletion
+
def initialize
@additional_key_bindings = {} # from inputrc
@additional_key_bindings[:emacs] = {}
@additional_key_bindings[:vi_insert] = {}
@additional_key_bindings[:vi_command] = {}
@oneshot_key_bindings = {}
- @skip_section = nil
- @if_stack = nil
@editing_mode_label = :emacs
@keymap_label = :emacs
+ @keymap_prefix = []
@key_actors = {}
@key_actors[:emacs] = Reline::KeyActor::Emacs.new
@key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new
@@ -67,6 +68,7 @@ class Reline::Config
@keyseq_timeout = 500
@test_mode = false
@autocompletion = false
+ @convert_meta = true if seven_bit_encoding?(Reline::IOGate.encoding)
end
def reset
@@ -89,15 +91,7 @@ class Reline::Config
end
def editing_mode_is?(*val)
- (val.respond_to?(:any?) ? val : [val]).any?(@editing_mode_label)
- end
-
- def autocompletion=(val)
- @autocompletion = val
- end
-
- def autocompletion
- @autocompletion
+ val.any?(@editing_mode_label)
end
def keymap
@@ -194,9 +188,7 @@ class Reline::Config
end
end
end
- conditions = [@skip_section, @if_stack]
- @skip_section = nil
- @if_stack = []
+ if_stack = []
lines.each_with_index do |line, no|
next if line.match(/\A\s*#/)
@@ -205,11 +197,11 @@ class Reline::Config
line = line.chomp.lstrip
if line.start_with?('$')
- handle_directive(line[1..-1], file, no)
+ handle_directive(line[1..-1], file, no, if_stack)
next
end
- next if @skip_section
+ next if if_stack.any? { |_no, skip| skip }
case line
when /^set +([^ ]+) +([^ ]+)/i
@@ -220,17 +212,15 @@ class Reline::Config
key, func_name = $1, $2
keystroke, func = bind_key(key, func_name)
next unless keystroke
- @additional_key_bindings[@keymap_label][keystroke] = func
+ @additional_key_bindings[@keymap_label][@keymap_prefix + keystroke] = func
end
end
- unless @if_stack.empty?
- raise InvalidInputrc, "#{file}:#{@if_stack.last[1]}: unclosed if"
+ unless if_stack.empty?
+ raise InvalidInputrc, "#{file}:#{if_stack.last[0]}: unclosed if"
end
- ensure
- @skip_section, @if_stack = conditions
end
- def handle_directive(directive, file, no)
+ def handle_directive(directive, file, no, if_stack)
directive, args = directive.split(' ')
case directive
when 'if'
@@ -243,20 +233,19 @@ class Reline::Config
condition = true if args == 'Ruby'
condition = true if args == 'Reline'
end
- @if_stack << [file, no, @skip_section]
- @skip_section = !condition
+ if_stack << [no, !condition]
when 'else'
- if @if_stack.empty?
+ if if_stack.empty?
raise InvalidInputrc, "#{file}:#{no}: unmatched else"
end
- @skip_section = !@skip_section
+ if_stack.last[1] = !if_stack.last[1]
when 'endif'
- if @if_stack.empty?
+ if if_stack.empty?
raise InvalidInputrc, "#{file}:#{no}: unmatched endif"
end
- @skip_section = @if_stack.pop
+ if_stack.pop
when 'include'
- read(args)
+ read(File.expand_path(args))
end
end
@@ -291,18 +280,29 @@ class Reline::Config
when 'emacs'
@editing_mode_label = :emacs
@keymap_label = :emacs
+ @keymap_prefix = []
when 'vi'
@editing_mode_label = :vi_insert
@keymap_label = :vi_insert
+ @keymap_prefix = []
end
when 'keymap'
case value
- when 'emacs', 'emacs-standard', 'emacs-meta', 'emacs-ctlx'
+ when 'emacs', 'emacs-standard'
@keymap_label = :emacs
+ @keymap_prefix = []
+ when 'emacs-ctlx'
+ @keymap_label = :emacs
+ @keymap_prefix = [?\C-x.ord]
+ when 'emacs-meta'
+ @keymap_label = :emacs
+ @keymap_prefix = [?\e.ord]
when 'vi', 'vi-move', 'vi-command'
@keymap_label = :vi_command
+ @keymap_prefix = []
when 'vi-insert'
@keymap_label = :vi_insert
+ @keymap_prefix = []
end
when 'keyseq-timeout'
@keyseq_timeout = value.to_i
@@ -387,4 +387,8 @@ class Reline::Config
end
ret
end
+
+ private def seven_bit_encoding?(encoding)
+ encoding == Encoding::US_ASCII
+ end
end