Class: Debugger::Edit

Inherits:
Command show all
Defined in:
lib/ruby-debug/commands/edit.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Command

Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, #find, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map

Constructor Details

This class inherits a constructor from Debugger::Command

Class Method Details

.help(cmd) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/ruby-debug/commands/edit.rb', line 35

def help(cmd)
  %{
    Edit specified file.

With no argument, edits file containing most recent line listed.
Editing targets can also be specified in this:
  FILE:LINENUM, to edit at that line in that file,
  }
end

.help_commandObject



31
32
33
# File 'lib/ruby-debug/commands/edit.rb', line 31

def help_command
  'edit'
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby-debug/commands/edit.rb', line 8

def execute
  if not @match[1] or @match[1].strip.empty?
    unless @state.context
      errmsg "We are not in a state that has an associated file.\n"
      return 
    end
    file = @state.file
    line_number = @state.line
  elsif @pos_match = /([^:]+)[:]([0-9]+)/.match(@match[1])
    file, line_number = @pos_match.captures
  else
    errmsg "Invalid file/line number specification: #{@match[1]}\n"
    return
  end
  editor = ENV['EDITOR'] || 'ex'
  if File.readable?(file)
    system("#{editor} +#{line_number} #{file}")
  else
    errmsg "File \"#{file}\" is not readable.\n"
  end
end

#regexpObject



4
5
6
# File 'lib/ruby-debug/commands/edit.rb', line 4

def regexp
  /^\s* ed(?:it)? (?:\s+(.*))?$/ix
end