Class: Textbringer::InputMethod

Inherits:
Object
  • Object
show all
Extended by:
Commands
Includes:
Commands
Defined in:
lib/textbringer/input_method.rb

Constant Summary collapse

@@list =
[]

Constants included from Commands

Commands::CLIPBOARD_AVAILABLE, Commands::CTAGS, Commands::HELP_RING, Commands::ISEARCH_STATUS, Commands::KEYBOARD_MACROS, Commands::REGISTERS, Commands::RE_SEARCH_STATUS

Constants included from Utils

Utils::COMPLETION, Utils::EXPRESSION_COMPLETOR, Utils::EXPRESSION_COMPLETOR_OPTIONS, Utils::HOOKS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Commands

[], command_help, command_table, current_prefix_arg, define_command, execute_keyboard_macro, get_tags, isearch_done, isearch_mode, isearch_mode?, isearch_pre_command_hook, isearch_prompt, isearch_repeat, isearch_repeat_backward, isearch_repeat_forward, isearch_search, keymap_bindings, match_beginning, match_end, match_string, number_prefix_arg, prefix_numeric_value, read_input_method_name, read_keyboard_macro, read_register, replace_match, undefine_command, universal_argument_mode

Methods included from Utils

add_hook, background, complete_for_minibuffer, foreground, foreground!, get_hooks, message, read_buffer, read_char, read_command_name, read_encoding, read_event, read_expression, read_file_name, read_from_minibuffer, read_key_sequence, read_object, read_single_char, received_keyboard_quit?, remove_hook, ruby_install_name, run_hooks, run_hooks_in, self_insert_and_exit_minibuffer, set_transient_map, show_exception, sit_for, sleep_for, y_or_n?, yes_or_no?

Constructor Details

#initializeInputMethod

Returns a new instance of InputMethod.



26
27
28
29
# File 'lib/textbringer/input_method.rb', line 26

def initialize
  @enabled = false
  @skip_next_event = false
end

Class Method Details

.find(name) ⇒ Object



19
20
21
22
23
24
# File 'lib/textbringer/input_method.rb', line 19

def self.find(name)
  class_name = name.split(/_/).map(&:capitalize).join + "InputMethod"
  Textbringer.const_get(class_name).new
rescue NameError
  raise EditorError, "No such input method: #{name}"
end

.inherited(subclass) ⇒ Object



8
9
10
11
12
13
# File 'lib/textbringer/input_method.rb', line 8

def self.inherited(subclass)
  name = subclass.name.sub(/Textbringer::/, "").sub(/InputMethod/, "").
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').
    downcase
  @@list.push(name)
end

.listObject



15
16
17
# File 'lib/textbringer/input_method.rb', line 15

def self.list
  @@list
end

Instance Method Details

#disableObject



35
36
37
# File 'lib/textbringer/input_method.rb', line 35

def disable
  @enabled = false
end

#enabled?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/textbringer/input_method.rb', line 39

def enabled?
  @enabled
end

#filter_event(event) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/textbringer/input_method.rb', line 43

def filter_event(event)
  if @enabled
    if event == "\e"
      @skip_next_event = true
      event
    elsif @skip_next_event
      @skip_next_event = false
      event
    else
      handle_event(event)
    end
  else
    event
  end
end

#handle_event(event) ⇒ Object

Raises:



59
60
61
# File 'lib/textbringer/input_method.rb', line 59

def handle_event(event)
  raise EditorError, "subclass must override InputMethod#handle_event"
end

#toggleObject



31
32
33
# File 'lib/textbringer/input_method.rb', line 31

def toggle
  @enabled = !@enabled
end

#with_target_buffer(&block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/textbringer/input_method.rb', line 63

def with_target_buffer(&block)
  if isearch_mode?
    @isearch_buffer ||= Buffer.new
    if @isearch_buffer.to_s != ISEARCH_STATUS[:string]
      @isearch_buffer.replace(ISEARCH_STATUS[:string])
    end
    @isearch_buffer.modified = false
    begin
      block.call(@isearch_buffer)
    ensure
      ISEARCH_STATUS[:string] = @isearch_buffer.to_s
      isearch_search if @isearch_buffer.modified?
      if Buffer.current != Buffer.minibuffer
        message(isearch_prompt + ISEARCH_STATUS[:string], log: false)
      end
      Window.redisplay
    end
  else
    block.call(Buffer.current)
  end
end