Class: Textbringer::GlobalMinorMode
- Inherits:
-
Object
- Object
- Textbringer::GlobalMinorMode
- Extended by:
- Commands
- Includes:
- Commands
- Defined in:
- lib/textbringer/global_minor_mode.rb
Overview
Base class for global minor modes that affect all buffers. Unlike buffer-local MinorMode, global minor modes have a single on/off state.
Direct Known Subclasses
Constant Summary
Constants included from Commands
Commands::CLIPBOARD_AVAILABLE, Commands::CTAGS, Commands::EMAIL_REGEXP, Commands::HELP_RING, Commands::ISEARCH_STATUS, Commands::ISPELL_STATUS, Commands::ISPELL_WORD_REGEXP, Commands::KEYBOARD_MACROS, Commands::REGISTERS, Commands::RE_SEARCH_STATUS, Commands::URI_REGEXP
Constants included from Utils
Utils::COMPLETION, Utils::EXPRESSION_COMPLETOR, Utils::EXPRESSION_COMPLETOR_OPTIONS, Utils::HOOKS
Class Attribute Summary collapse
-
.command_name ⇒ Object
Returns the value of attribute command_name.
-
.mode_name ⇒ Object
Returns the value of attribute mode_name.
Class Method Summary collapse
- .disable ⇒ Object
-
.enable ⇒ Object
Override these in subclasses.
- .enabled=(val) ⇒ Object
- .enabled? ⇒ Boolean
- .inherited(child) ⇒ Object
Methods included from Commands
[], command_help, command_table, current_prefix_arg, define_command, ensure_ispell_active, 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, ispell_done, ispell_forward, ispell_mode, keymap_bindings, list, match_beginning, match_end, match_string, message_misspelled, 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, delete_completions_window, 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?
Class Attribute Details
.command_name ⇒ Object
Returns the value of attribute command_name.
10 11 12 |
# File 'lib/textbringer/global_minor_mode.rb', line 10 def command_name @command_name end |
.mode_name ⇒ Object
Returns the value of attribute mode_name.
9 10 11 |
# File 'lib/textbringer/global_minor_mode.rb', line 9 def mode_name @mode_name end |
Class Method Details
.disable ⇒ Object
54 55 56 |
# File 'lib/textbringer/global_minor_mode.rb', line 54 def self.disable raise EditorError, "Subclass must implement disable" end |
.enable ⇒ Object
Override these in subclasses
50 51 52 |
# File 'lib/textbringer/global_minor_mode.rb', line 50 def self.enable raise EditorError, "Subclass must implement enable" end |
.enabled=(val) ⇒ Object
12 13 14 |
# File 'lib/textbringer/global_minor_mode.rb', line 12 def enabled=(val) @enabled = val end |
.enabled? ⇒ Boolean
16 |
# File 'lib/textbringer/global_minor_mode.rb', line 16 def enabled? = @enabled |
.inherited(child) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/textbringer/global_minor_mode.rb', line 19 def self.inherited(child) # Initialize enabled to false immediately child.instance_variable_set(:@enabled, false) class_name = child.name if class_name.nil? || class_name.empty? raise ArgumentError, "GlobalMinorMode subclasses must be named classes (anonymous classes are not supported)" end base_name = class_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 child.command_name = command # Define the toggle command define_command(command) do if child.enabled? child.disable child.enabled = false else child.enable child.enabled = true end end end |