Sha256: 4bbd1e035a86b35dd77c6ad803fe1c2f733ff8c9ec56360a4dd6c96811e35e82

Contents?: true

Size: 1.05 KB

Versions: 16

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Textbringer
  class BacktraceMode < Mode
    define_generic_command :jump_to_source_location

    BACKTRACE_MODE_MAP = Keymap.new
    BACKTRACE_MODE_MAP.define_key("\C-m", :jump_to_source_location_command)

    define_syntax :link, /^\S*?:\d+:(?:\d+:)?/

    def initialize(buffer)
      super(buffer)
      buffer.keymap = BACKTRACE_MODE_MAP
    end

    def jump_to_source_location
      file_name, line_number, column_number = get_source_location
      if file_name
        find_file(file_name)
        goto_line(line_number)
        forward_char(column_number - 1)
      end
    end

    private

    def get_source_location
      @buffer.save_excursion do
        @buffer.beginning_of_line
        if @buffer.looking_at?(/^(\S*?):(\d+):(?:(\d+):)?/)
          file_name = @buffer.match_string(1)
          line_number = @buffer.match_string(2).to_i
          column_number = (@buffer.match_string(3) || 1).to_i
          [file_name, line_number, column_number]
        else
          nil
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
textbringer-1.0.0 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.3.2 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.3.1 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.3.0 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.9 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.8 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.7 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.6 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.4 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.5 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.3 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.2 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.1 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.2.0 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.1.9 lib/textbringer/modes/backtrace_mode.rb
textbringer-0.1.8 lib/textbringer/modes/backtrace_mode.rb