Class: Textbringer::Mode

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

Constant Summary collapse

@@mode_list =
[]

Constants included from Commands

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

Constants included from Utils

Utils::COMPLETION, Utils::HOOKS, Utils::Y_OR_N_MAP

Class Attribute Summary collapse

Instance Attribute Summary collapse

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_pre_command_hook, isearch_prompt, isearch_repeat, isearch_repeat_backward, isearch_repeat_forward, isearch_search, match_beginning, match_end, match_string, number_prefix_arg, prefix_numeric_value, read_keyboard_macro, read_register, replace_match, undefine_command, universal_argument_mode

Methods included from Utils

add_hook, complete_for_minibuffer, message, read_buffer, read_char, read_command_name, read_file_name, read_from_minibuffer, read_key_sequence, read_single_char, received_keyboard_quit?, remove_hook, ruby_install_name, run_hooks, self_insert_and_exit_minibuffer, set_transient_map, show_exception, sit_for, sleep_for, y_or_n?, yes_or_no?

Constructor Details

#initialize(buffer) ⇒ Mode

Returns a new instance of Mode.



63
64
65
# File 'lib/textbringer/mode.rb', line 63

def initialize(buffer)
  @buffer = buffer
end

Class Attribute Details

.command_nameObject

Returns the value of attribute command_name.



16
17
18
# File 'lib/textbringer/mode.rb', line 16

def command_name
  @command_name
end

.file_name_patternObject

Returns the value of attribute file_name_pattern.



18
19
20
# File 'lib/textbringer/mode.rb', line 18

def file_name_pattern
  @file_name_pattern
end

.hook_nameObject

Returns the value of attribute hook_name.



17
18
19
# File 'lib/textbringer/mode.rb', line 17

def hook_name
  @hook_name
end

.interpreter_name_patternObject

Returns the value of attribute interpreter_name_pattern.



19
20
21
# File 'lib/textbringer/mode.rb', line 19

def interpreter_name_pattern
  @interpreter_name_pattern
end

.mode_nameObject

Returns the value of attribute mode_name.



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

def mode_name
  @mode_name
end

.syntax_tableObject (readonly)

Returns the value of attribute syntax_table.



20
21
22
# File 'lib/textbringer/mode.rb', line 20

def syntax_table
  @syntax_table
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



61
62
63
# File 'lib/textbringer/mode.rb', line 61

def buffer
  @buffer
end

Class Method Details

.define_generic_command(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/textbringer/mode.rb', line 23

def self.define_generic_command(name)
  command_name = (name.to_s + "_command").intern
  define_command(command_name) do |*args|
    begin
      Buffer.current.mode.send(name, *args)
    rescue NoMethodError => e
      if e.receiver == Buffer.current.mode && e.name == name
        raise EditorError,
          "#{command_name} is not supported in the current mode"
      else
        raise
      end
    end
  end
end

.define_syntax(face_name, re) ⇒ Object



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

def self.define_syntax(face_name, re)
  @syntax_table[face_name] = re
end

.inherited(child) ⇒ Object



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

def self.inherited(child)
  base_name = child.name.slice(/[^:]*\z/)
  child.mode_name = base_name.sub(/Mode\z/, "")
  command_name = base_name.sub(/\A[A-Z]/) { |s| s.downcase }.
    gsub(/(?<=[a-z])([A-Z])/) {
      "_" + $1.downcase
    }
  command = command_name.intern
  hook = (command_name + "_hook").intern
  child.command_name = command
  child.hook_name = hook
  define_command(command) do
    Buffer.current.apply_mode(child)
  end
  @@mode_list.push(child)
  child.instance_variable_set(:@syntax_table, {})
end

.listObject



10
11
12
# File 'lib/textbringer/mode.rb', line 10

def self.list
  @@mode_list
end

Instance Method Details

#nameObject



67
68
69
# File 'lib/textbringer/mode.rb', line 67

def name
  self.class.mode_name
end

#syntax_tableObject



71
72
73
# File 'lib/textbringer/mode.rb', line 71

def syntax_table
  self.class.syntax_table
end