Class: Byebug::EditCommand
Overview
Edit a file from byebug’s prompt.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match
Class Method Details
.description ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/byebug/commands/edit.rb', line 42
def description
%(edit[ file:lineno] Edit specified files.
With no argument, edits file containing most recent line listed.
Editing targets can also be specified to start editing at a specific
line in a specific file.)
end
|
.names ⇒ Object
38
39
40
|
# File 'lib/byebug/commands/edit.rb', line 38
def names
%w(edit)
end
|
Instance Method Details
#execute ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/byebug/commands/edit.rb', line 12
def execute
if !@match[1]
unless @state.file
return errmsg "We are not in a state that has an associated file.\n"
end
file = @state.file
line = @state.line if @state.line
elsif (@pos_match = /([^:]+)[:]([0-9]+)/.match(@match[1]))
file, line = @pos_match.captures
elsif File.exist?(@match[1])
file = @match[1]
else
return errmsg "Invalid file[:line] number specification: #{@match[1]}\n"
end
editor = ENV['EDITOR'] || 'vim'
if File.readable?(file)
system("#{editor} +#{line} #{file}") if line
system("#{editor} #{file}") unless line
else
errmsg "File \"#{file}\" is not readable.\n"
end
end
|
#regexp ⇒ Object
8
9
10
|
# File 'lib/byebug/commands/edit.rb', line 8
def regexp
/^\s* ed(?:it)? (?:\s+(\S+))? \s*$/x
end
|