class Byebug::EditCommand

Edit a file from byebug's prompt.

Public Class Methods

description() click to toggle source
# File lib/byebug/commands/edit.rb, line 15
def self.description
  <<-EOD
    edit[ file:lineno]

    #{short_description}

    With no argumnt, edits file containing most re line listed. Editing
    targets can also be specified to start editing at a specific line in a
    specific file
  EOD
end
regexp() click to toggle source
# File lib/byebug/commands/edit.rb, line 11
def self.regexp
  /^\s* ed(?:it)? (?:\s+(\S+))? \s*$/x
end
short_description() click to toggle source
# File lib/byebug/commands/edit.rb, line 27
def self.short_description
  'Edits source files'
end

Public Instance Methods

execute() click to toggle source
# File lib/byebug/commands/edit.rb, line 31
def execute
  file, line = location(@match[1])
  return edit_error('not_exist', file) unless File.exist?(file)
  return edit_error('not_readable', file) unless File.readable?(file)

  cmd = line ? "#{editor} +#{line} #{file}" : "#{editor} #{file}"

  system(cmd)
end

Private Instance Methods

edit_error(type, file) click to toggle source
# File lib/byebug/commands/edit.rb, line 62
def edit_error(type, file)
  errmsg(pr("edit.errors.#{type}", file: file))
end
editor() click to toggle source
# File lib/byebug/commands/edit.rb, line 58
def editor
  ENV['EDITOR'] || 'vim'
end
location(matched) click to toggle source
# File lib/byebug/commands/edit.rb, line 43
def location(matched)
  if matched.nil?
    file = frame.file
    return errmsg(pr('edit.errors.state')) unless file
    line = frame.line
  elsif (@pos_match = /([^:]+)[:]([0-9]+)/.match(matched))
    file, line = @pos_match.captures
  else
    file = matched
    line = nil
  end

  [File.expand_path(file), line]
end