Class: Pry::Editor

Inherits:
Object show all
Includes:
Helpers::BaseHelpers, Helpers::CommandHelpers
Defined in:
lib/pry/editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CommandHelpers

absolute_index_number, absolute_index_range, command_error, get_method_or_raise, internal_binding?, one_index_number, one_index_range, one_index_range_or_number, restrict_to_lines, set_file_and_dir_locals, temp_file, unindent

Methods included from Helpers::OptionsHelpers

method_object, method_options

Methods included from Helpers::BaseHelpers

colorize_code, command_dependencies_met?, find_command, heading, highlight, jruby?, jruby_19?, mri?, mri_19?, mri_20?, mri_21?, mri_2?, not_a_real_file?, rbx?, #safe_send, safe_send, silence_warnings, stagger_output, use_ansi_codes?, windows?, windows_ansi?

Constructor Details

#initialize(_pry_) ⇒ Editor

Returns a new instance of Editor.



8
9
10
# File 'lib/pry/editor.rb', line 8

def initialize(_pry_)
  @_pry_ = _pry_
end

Instance Attribute Details

#_pry_Object (readonly)

Returns the value of attribute pry.



6
7
8
# File 'lib/pry/editor.rb', line 6

def _pry_
  @_pry_
end

Instance Method Details

#edit_tempfile_with_content(initial_content, line = 1) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/pry/editor.rb', line 12

def edit_tempfile_with_content(initial_content, line=1)
  temp_file do |f|
    f.puts(initial_content)
    f.flush
    f.close(false)
    invoke_editor(f.path, line, true)
    File.read(f.path)
  end
end

#invoke_editor(file, line, blocking = true) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pry/editor.rb', line 22

def invoke_editor(file, line, blocking=true)
  raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless _pry_.config.editor

  editor_invocation = build_editor_invocation_string(file, line, blocking)
  return nil unless editor_invocation

  if jruby?
    open_editor_on_jruby(editor_invocation)
  else
    open_editor(editor_invocation)
  end
end