Class: Textbringer::Mode
- Inherits:
-
Object
- Object
- Textbringer::Mode
- Extended by:
- Commands
- Includes:
- Commands
- Defined in:
- lib/textbringer/mode.rb
Direct Known Subclasses
BacktraceMode, BufferListMode, CompletionListMode, FundamentalMode, HelpMode
Constant Summary collapse
- DEFAULT_SYNTAX_TABLE =
{ control: /[\0-\t\v-\x1f\x7f\u{3000}]+/ }
- @@mode_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::HOOKS
Class Attribute Summary collapse
-
.command_name ⇒ Object
Returns the value of attribute command_name.
-
.file_name_pattern ⇒ Object
Returns the value of attribute file_name_pattern.
-
.hook_name ⇒ Object
Returns the value of attribute hook_name.
-
.interpreter_name_pattern ⇒ Object
Returns the value of attribute interpreter_name_pattern.
-
.mode_name ⇒ Object
Returns the value of attribute mode_name.
-
.syntax_table ⇒ Object
readonly
Returns the value of attribute syntax_table.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Class Method Summary collapse
- .define_generic_command(name, **options) ⇒ Object
- .define_local_command(name, **options, &block) ⇒ Object
- .define_syntax(face_name, re) ⇒ Object
- .inherited(child) ⇒ Object
- .list ⇒ Object
Instance Method Summary collapse
-
#initialize(buffer) ⇒ Mode
constructor
A new instance of Mode.
- #name ⇒ Object
- #syntax_table ⇒ Object
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!, 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, 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.
71 72 73 |
# File 'lib/textbringer/mode.rb', line 71 def initialize(buffer) @buffer = buffer end |
Class Attribute Details
.command_name ⇒ Object
Returns the value of attribute command_name.
18 19 20 |
# File 'lib/textbringer/mode.rb', line 18 def command_name @command_name end |
.file_name_pattern ⇒ Object
Returns the value of attribute file_name_pattern.
20 21 22 |
# File 'lib/textbringer/mode.rb', line 20 def file_name_pattern @file_name_pattern end |
.hook_name ⇒ Object
Returns the value of attribute hook_name.
19 20 21 |
# File 'lib/textbringer/mode.rb', line 19 def hook_name @hook_name end |
.interpreter_name_pattern ⇒ Object
Returns the value of attribute interpreter_name_pattern.
21 22 23 |
# File 'lib/textbringer/mode.rb', line 21 def interpreter_name_pattern @interpreter_name_pattern end |
.mode_name ⇒ Object
Returns the value of attribute mode_name.
17 18 19 |
# File 'lib/textbringer/mode.rb', line 17 def mode_name @mode_name end |
.syntax_table ⇒ Object (readonly)
Returns the value of attribute syntax_table.
22 23 24 |
# File 'lib/textbringer/mode.rb', line 22 def syntax_table @syntax_table end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
69 70 71 |
# File 'lib/textbringer/mode.rb', line 69 def buffer @buffer end |
Class Method Details
.define_generic_command(name, **options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/textbringer/mode.rb', line 25 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 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) ⇒ Object
41 42 43 44 45 |
# File 'lib/textbringer/mode.rb', line 41 def self.define_local_command(name, **, &block) define_generic_command(name, **) define_method(name, &block) name end |
.define_syntax(face_name, re) ⇒ Object
47 48 49 |
# File 'lib/textbringer/mode.rb', line 47 def self.define_syntax(face_name, re) @syntax_table[face_name] = re end |
.inherited(child) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
12 13 14 |
# File 'lib/textbringer/mode.rb', line 12 def self.list @@mode_list end |
Instance Method Details
#name ⇒ Object
75 76 77 |
# File 'lib/textbringer/mode.rb', line 75 def name self.class.mode_name end |
#syntax_table ⇒ Object
79 80 81 |
# File 'lib/textbringer/mode.rb', line 79 def syntax_table self.class.syntax_table end |