Class: Textbringer::TransientMarkMode
- Inherits:
-
GlobalMinorMode
- Object
- GlobalMinorMode
- Textbringer::TransientMarkMode
- Defined in:
- lib/textbringer/modes/transient_mark_mode.rb
Overview
Transient Mark Mode is a global minor mode that highlights the region between mark and point when the mark is active.
Constant Summary collapse
- MARK_PRESERVING_COMMANDS =
Commands that should NOT deactivate the mark
[ :set_mark_command, :exchange_point_and_mark, :transient_mark_mode, # Navigation commands that should preserve mark :beginning_of_line, :end_of_line, :next_line, :previous_line, :forward_char, :backward_char, :forward_word, :backward_word, :scroll_up_command, :scroll_down_command, :beginning_of_buffer, :end_of_buffer, # Search commands :isearch_forward, :isearch_backward, :isearch_repeat_forward, :isearch_repeat_backward, :isearch_printing_char, :isearch_delete_char, :isearch_yank_word_or_char, :isearch_quoted_insert, :isearch_exit, # Undo/redo :undo, :redo_command, # Other navigation :goto_line, :goto_char, :recenter, :move_to_beginning_of_line, :move_to_end_of_line ].to_set.freeze
- PRE_COMMAND_HOOK =
Hook to deactivate mark before most commands
-> { buffer = Buffer.current controller = Controller.current return unless buffer.mark_active? # Check if this command preserves the mark command = controller.this_command unless MARK_PRESERVING_COMMANDS.include?(command) buffer.deactivate_mark end }
- POST_COMMAND_HOOK =
Hook to update visible mark after commands
-> { buffer = Buffer.current # Skip if in isearch or ispell mode (they manage their own highlighting) controller = Controller.current if controller.overriding_map return if Commands.const_defined?(:ISEARCH_MODE_MAP) && controller.overriding_map == Commands::ISEARCH_MODE_MAP return if Commands.const_defined?(:ISPELL_MODE_MAP) && controller.overriding_map == Commands::ISPELL_MODE_MAP end # Update visible_mark to reflect mark_active state if buffer.mark_active? begin mark = buffer.mark buffer.set_visible_mark(mark.location) if mark rescue EditorError # Mark is not set, do nothing end elsif !buffer.mark_active? && buffer.visible_mark buffer.delete_visible_mark end }
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 Method Summary collapse
Methods inherited from GlobalMinorMode
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 Method Details
.disable ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/textbringer/modes/transient_mark_mode.rb', line 93 def self.disable # Remove global hooks remove_hook(:pre_command_hook, PRE_COMMAND_HOOK, local: false) remove_hook(:post_command_hook, POST_COMMAND_HOOK, local: false) # Deactivate mark in all buffers Buffer.list.each do |buffer| buffer.deactivate_mark end ("Transient Mark mode disabled") end |
.enable ⇒ Object
86 87 88 89 90 91 |
# File 'lib/textbringer/modes/transient_mark_mode.rb', line 86 def self.enable # Add global hooks (not buffer-local) add_hook(:pre_command_hook, PRE_COMMAND_HOOK, local: false) add_hook(:post_command_hook, POST_COMMAND_HOOK, local: false) ("Transient Mark mode enabled") end |