class Textbringer::Mode
Constants
- DEFAULT_SYNTAX_TABLE
Attributes
command_name[RW]
file_name_pattern[RW]
hook_name[RW]
interpreter_name_pattern[RW]
mode_name[RW]
syntax_table[R]
buffer[R]
Public Class Methods
define_generic_command(name, **options)
click to toggle source
# File lib/textbringer/mode.rb, line 25 def self.define_generic_command(name, **options) command_name = (name.to_s + "_command").intern define_command(command_name, **options) do |*args| begin Buffer.current.mode.send(name, *args) rescue NoMethodError => e if (e.receiver rescue nil) == Buffer.current.mode && e.name == name raise EditorError, "#{command_name} is not supported in the current mode" else raise end end end end
define_local_command(name, **options, &block)
click to toggle source
# File lib/textbringer/mode.rb, line 41 def self.define_local_command(name, **options, &block) define_generic_command(name, **options) define_method(name, &block) name end
define_syntax(face_name, re)
click to toggle source
# File lib/textbringer/mode.rb, line 47 def self.define_syntax(face_name, re) @syntax_table[face_name] = re end
inherited(child)
click to toggle source
# File lib/textbringer/mode.rb, line 51 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, DEFAULT_SYNTAX_TABLE.dup) end
list()
click to toggle source
# File lib/textbringer/mode.rb, line 12 def self.list @@mode_list end
new(buffer)
click to toggle source
# File lib/textbringer/mode.rb, line 71 def initialize(buffer) @buffer = buffer end
Public Instance Methods
name()
click to toggle source
# File lib/textbringer/mode.rb, line 75 def name self.class.mode_name end
syntax_table()
click to toggle source
# File lib/textbringer/mode.rb, line 79 def syntax_table self.class.syntax_table end