Class: Textbringer::Mode

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

Direct Known Subclasses

BacktraceMode, FundamentalMode, ProgrammingMode

Constant Summary collapse

@@mode_list =
[]

Constants included from Commands

Commands::ISEARCH_MODE_MAP, Commands::ISEARCH_STATUS, Commands::RE_SEARCH_STATUS, Commands::UNIVERSAL_ARGUMENT_MAP

Constants included from Utils

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

current_prefix_arg, define_command, 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, replace_match, undefine_command, universal_argument_mode

Methods included from Utils

#add_hook, #complete, #handle_exception, #message, #read_buffer, #read_char, #read_command_name, #read_file_name, #read_from_minibuffer, #read_single_char, #received_keyboard_quit?, #remove_hook, #run_hooks, #self_insert_and_exit_minibuffer, #set_transient_map, #sit_for, #sleep_for, #y_or_n?, #yes_or_no?

Constructor Details

#initialize(buffer) ⇒ Mode

Returns a new instance of Mode.



56
57
58
# File 'lib/textbringer/mode.rb', line 56

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

.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

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



54
55
56
# File 'lib/textbringer/mode.rb', line 54

def buffer
  @buffer
end

Class Method Details

.define_generic_command(name) ⇒ Object



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

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

.inherited(child) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/textbringer/mode.rb', line 37

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)
end

.listObject



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

def self.list
  @@mode_list
end

Instance Method Details

#nameObject



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

def name
  self.class.mode_name
end