From 17aaff2154d2e36b5adeb825ec940c353263fc0e Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 2 Aug 2011 08:29:08 +1100 Subject: [PATCH] moved invoke_editor() and friends from introspection.rb helper to command_helpers.rb --- lib/pry/default_commands/introspection.rb | 35 --------------------- lib/pry/helpers/command_helpers.rb | 37 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 0f983511..218855f0 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -207,41 +207,6 @@ class Pry end end - helpers do - - def invoke_editor(file, line) - if Pry.editor.respond_to?(:call) - editor_invocation = Pry.editor.call(file, line) - else - editor_invocation = "#{Pry.editor} #{start_line_syntax_for_editor(file, line)}" - end - - run ".#{editor_invocation}" - end - - def start_line_syntax_for_editor(file_name, line_number) - file_name = file_name.gsub(/\//, '\\') if RUBY_PLATFORM =~ /mswin|mingw/ - - case Pry.editor - when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/ - "+#{line_number} #{file_name}" - when /^mate/, /^geany/ - "-l #{line_number} #{file_name}" - when /^uedit32/ - "#{file_name}/#{line_number}" - when /^jedit/ - "#{file_name} +line:#{line_number}" - else - if RUBY_PLATFORM =~ /mswin|mingw/ - "#{file_name}" - else - "+#{line_number} #{file_name}" - end - end - end - - end - end end end diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index dea56fcf..07f3e57d 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -255,7 +255,11 @@ class Pry end language_detected = file_type if file_type - CodeRay.scan(contents, language_detected).term + if Pry.color + CodeRay.scan(contents, language_detected).term + else + contents + end end # convert negative line numbers to positive by wrapping around @@ -328,6 +332,37 @@ class Pry code.sub(/\A\s*\/\*.*?\*\/\s*/m, '') end + def invoke_editor(file, line) + if Pry.editor.respond_to?(:call) + editor_invocation = Pry.editor.call(file, line) + else + editor_invocation = "#{Pry.editor} #{start_line_syntax_for_editor(file, line)}" + end + + run ".#{editor_invocation}" + end + + def start_line_syntax_for_editor(file_name, line_number) + file_name = file_name.gsub(/\//, '\\') if RUBY_PLATFORM =~ /mswin|mingw/ + + case Pry.editor + when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/ + "+#{line_number} #{file_name}" + when /^mate/, /^geany/ + "-l #{line_number} #{file_name}" + when /^uedit32/ + "#{file_name}/#{line_number}" + when /^jedit/ + "#{file_name} +line:#{line_number}" + else + if RUBY_PLATFORM =~ /mswin|mingw/ + "#{file_name}" + else + "+#{line_number} #{file_name}" + end + end + end + def prompt(message, options="Yn") opts = options.scan(/./) optstring = opts.join("/") # case maintained