Sha256: 1e69e0e6faf21efc681dbf8b806692ed02bbb685f0f31daaaa475dcf47f744c8

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 KB

Contents

module Textbringer
  class HelpMode < Mode
    define_generic_command :jump_to_link

    define_keymap :HELP_MODE_MAP
    HELP_MODE_MAP.define_key(?\C-m, :jump_to_link_command)
    HELP_MODE_MAP.define_key(?l, :help_go_back)
    HELP_MODE_MAP.define_key("\C-c\C-b", :help_go_back)
    HELP_MODE_MAP.define_key(?r, :help_go_forward)
    HELP_MODE_MAP.define_key("\C-c\C-f", :help_go_forward)
    HELP_MODE_MAP.define_key("q", :bury_buffer)

    define_syntax :link, /
      (?: ^\S*?:\d+$ ) |
      (?: \[[_a-zA-Z][_a-zA-Z0-9]*\] )
    /x

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

    def jump_to_link
      @buffer.save_excursion do
        @buffer.skip_re_backward(/[_a-zA-Z0-9]/)
        if @buffer.char_before == ?[ &&
            @buffer.looking_at?(/([_a-zA-Z][_a-zA-Z0-9]*)\]/)
          describe_command(match_string(1))
        else
          @buffer.beginning_of_line
          if @buffer.looking_at?(/^(\S*?):(\d+)$/)
            file_name = @buffer.match_string(1)
            line_number = @buffer.match_string(2).to_i
            find_file(file_name)
            goto_line(line_number)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
textbringer-1.4.1 lib/textbringer/modes/help_mode.rb
textbringer-1.3.0 lib/textbringer/modes/help_mode.rb
textbringer-1.2.0 lib/textbringer/modes/help_mode.rb
textbringer-1.1.2 lib/textbringer/modes/help_mode.rb
textbringer-1.1.1 lib/textbringer/modes/help_mode.rb
textbringer-1.1.0 lib/textbringer/modes/help_mode.rb
textbringer-1.0.9 lib/textbringer/modes/help_mode.rb
textbringer-1.0.4 lib/textbringer/modes/help_mode.rb
textbringer-1.0.3 lib/textbringer/modes/help_mode.rb
textbringer-1.0.2 lib/textbringer/modes/help_mode.rb