Module: PryEditline

Defined in:
lib/pry-editline.rb

Class Method Summary collapse

Class Method Details

.completion_procObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pry-editline.rb', line 49

def self.completion_proc
  lambda do |s|
    if Readline.respond_to?(:point) && Readline.respond_to?(:line_buffer) &&
      Readline.point == 0 && Readline.line_buffer =~ /  $/
    then
      require 'tempfile'
      Tempfile.open(['readline-','.rb']) do |f|
        f.puts(Readline.line_buffer[0..-3])
        f.close
        system("#{editor} #{f.path}")
        File.read(f.path).chomp
      end
    else
      yield s
    end
  end
end

.editorObject



3
4
5
6
7
8
9
# File 'lib/pry-editline.rb', line 3

def self.editor
  if defined?(Pry)
    Pry.editor
  else
    ENV.values_at('VISUAL', 'EDITOR').compact.first || 'vi'
  end
end

.hijack_inputrcObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pry-editline.rb', line 11

def self.hijack_inputrc
  inputrc = [
    ENV['INPUTRC'],
    (File.expand_path('~/.inputrc') rescue nil),
    '/etc/inputrc'
  ].compact.detect { |x| File.exist?(x) }

  require 'tempfile'
  @file = Tempfile.new('inputrc')
  @file.puts <<-'EOF'
set keymap vi-insert
"\C-a": beginning-of-line
"\C-b": backward-char
"\C-d": delete-char
"\C-e": end-of-line
"\C-f": forward-char
"\C-k": kill-line
"\C-n": next-history
"\C-p": previous-history
"\C-x\C-l": redraw-current-line
"\C-x\C-e": "\C-e  \C-a\t\C-k\C-x\C-l"
"\C-o": "\C-e  \C-a\t\C-k\C-x\C-l"
set keymap vi-command
"o": "A  \C-a\t\C-k\C-x\C-l\e"
"v": "A  \C-a\t\C-k\C-x\C-l\e"
set keymap emacs
"\C-x\C-l": redraw-current-line
"\C-x\C-e": "\C-e  \C-a\t\C-k\C-x\C-l"
"\C-o":     "\C-e  \C-a\t\C-k\C-x\C-l"
$if mode=vi
set keymap vi
$endif
EOF
  @file.puts "$include #{inputrc}" if inputrc
  @file.close
  ENV['INPUTRC'] = @file.path
end