Sha256: 17ca0f77e7d220af4610c517eecb16d8f9c803127cf5c97dd7500973e2240ca1

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Textbringer
  class HelpMode < Mode
    define_generic_command :jump_to_link

    HELP_MODE_MAP = Keymap.new
    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

14 entries across 14 versions & 1 rubygems

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