Sha256: 4a2dfd8685ef6bc8b0d08f328d8a46f5e55b8f0849cb73f974f42475d890125e

Contents?: true

Size: 932 Bytes

Versions: 2

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

module Textbringer
  class CompletionListMode < Mode
    define_generic_command :choose_completion

    COMPLETION_LIST_MODE_MAP = Keymap.new
    COMPLETION_LIST_MODE_MAP.define_key("\n", :choose_completion_command)

    define_syntax :link, /^.+$/

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

    def choose_completion
      unless Window.echo_area.active?
        raise EditorError, "Minibuffer is not active"
      end
      s = @buffer.save_excursion {
        @buffer.beginning_of_line
        @buffer.looking_at?(/.*/)
        @buffer.match_string(0)
      }
      if s.size > 0
        Window.current = Window.echo_area
        complete_minibuffer_with_string(s)
        if COMPLETION[:original_buffer]
          COMPLETION[:completions_window].buffer =
            COMPLETION[:original_buffer]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
textbringer-0.1.9 lib/textbringer/modes/completion_list_mode.rb
textbringer-0.1.8 lib/textbringer/modes/completion_list_mode.rb