module Textbringer::Commands
Constants
- CLIPBOARD_AVAILABLE
- CTAGS
- HELP_RING
- ISEARCH_STATUS
- KEYBOARD_MACROS
- REGISTERS
- RE_SEARCH_STATUS
Public Class Methods
[](name)
click to toggle source
# File lib/textbringer/commands.rb, line 20 def self.[](name) @command_table[name.intern] end
command_table()
click to toggle source
# File lib/textbringer/commands.rb, line 16 def self.command_table @command_table end
define_command(name, doc: "No documentation", &block)
click to toggle source
# File lib/textbringer/commands.rb, line 24 def define_command(name, doc: "No documentation", &block) name = name.intern Commands.send(:define_method, name, &block) Commands.send(:module_function, name) Commands.command_table[name] = Command.new(name, block, doc) name end
list()
click to toggle source
# File lib/textbringer/commands.rb, line 12 def self.list @command_table.keys end
undefine_command(name)
click to toggle source
# File lib/textbringer/commands.rb, line 33 def undefine_command(name) name = name.intern if Commands.command_table.key?(name) Commands.send(:undef_method, name) Commands.command_table.delete(name) end end
Public Instance Methods
command_help(cmd)
click to toggle source
# File lib/textbringer/commands/help.rb, line 59 def command_help(cmd) s = format("%s:%d\n", *cmd.block.source_location) s << "-" * (Window.columns - 2) + "\n" s << "#{cmd.name}" if !cmd.block.parameters.empty? s << "(" s << cmd.block.parameters.map { |_, param| param }.join(", ") s << ")" end s << "\n\n" s << "-" * (Window.columns - 2) + "\n\n" s << cmd.doc s << "\n" s end
current_prefix_arg()
click to toggle source
# File lib/textbringer/commands/misc.rb, line 164 def current_prefix_arg Controller.current.current_prefix_arg end
execute_keyboard_macro(macro, n = 1)
click to toggle source
# File lib/textbringer/commands/keyboard_macro.rb, line 38 def execute_keyboard_macro(macro, n = 1) Controller.current.execute_keyboard_macro(macro, n) end
isearch_done()
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 79 def isearch_done Buffer.current.delete_visible_mark Controller.current.overriding_map = nil remove_hook(:pre_command_hook, :isearch_pre_command_hook) ISEARCH_STATUS[:last_string] = ISEARCH_STATUS[:string] if ISEARCH_STATUS[:recursive_edit] exit_recursive_edit end end
isearch_mode(forward, recursive_edit: false)
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 45 def isearch_mode(forward, recursive_edit: false) ISEARCH_STATUS[:forward] = forward ISEARCH_STATUS[:string] = +"" ISEARCH_STATUS[:recursive_edit] = recursive_edit Controller.current.overriding_map = ISEARCH_MODE_MAP run_hooks(:isearch_mode_hook) add_hook(:pre_command_hook, :isearch_pre_command_hook) ISEARCH_STATUS[:start] = ISEARCH_STATUS[:last_pos] = Buffer.current.point if Buffer.current != Buffer.minibuffer message(isearch_prompt, log: false) end if recursive_edit recursive_edit() end end
isearch_mode?()
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 61 def isearch_mode? Controller.current.overriding_map == ISEARCH_MODE_MAP end
isearch_pre_command_hook()
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 73 def isearch_pre_command_hook if /\Aisearch_/ !~ Controller.current.this_command isearch_done end end
isearch_prompt()
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 65 def isearch_prompt if ISEARCH_STATUS[:forward] "I-search: " else "I-search backward: " end end
isearch_repeat(forward)
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 165 def isearch_repeat(forward) ISEARCH_STATUS[:forward] = forward ISEARCH_STATUS[:last_pos] = Buffer.current.point if ISEARCH_STATUS[:string].empty? ISEARCH_STATUS[:string] = ISEARCH_STATUS[:last_string] end isearch_search end
isearch_repeat_backward()
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 161 def isearch_repeat_backward isearch_repeat(false) end
isearch_repeat_forward()
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 157 def isearch_repeat_forward isearch_repeat(true) end
isearch_search()
click to toggle source
# File lib/textbringer/commands/isearch.rb, line 132 def isearch_search forward = ISEARCH_STATUS[:forward] options = if /\A[A-Z]/.match?(ISEARCH_STATUS[:string]) nil else Regexp::IGNORECASE end re = Regexp.new(Regexp.quote(ISEARCH_STATUS[:string]), options) last_pos = ISEARCH_STATUS[:last_pos] offset = forward ? last_pos : last_pos - ISEARCH_STATUS[:string].bytesize if offset >= 0 && Buffer.current.byteindex(forward, re, offset) if Buffer.current != Buffer.minibuffer message(isearch_prompt + ISEARCH_STATUS[:string], log: false) end Buffer.current.set_visible_mark(forward ? match_beginning(0) : match_end(0)) goto_char(forward ? match_end(0) : match_beginning(0)) else if Buffer.current != Buffer.minibuffer message("Failing " + isearch_prompt + ISEARCH_STATUS[:string], log: false) end end end
keymap_bindings(keymap)
click to toggle source
# File lib/textbringer/commands/help.rb, line 24 def keymap_bindings(keymap) s = format("%-16s %s\n", "Key", "Binding") s << format("%-16s %s\n", "---", "-------") s << "\n" keymap.each do |key_sequence, command| if command != :self_insert s << format("%-16s [%s]\n", Keymap.key_sequence_string(key_sequence), command) end end s end
match_beginning(n)
click to toggle source
# File lib/textbringer/commands/replace.rb, line 21 def match_beginning(n) Buffer.current.match_beginning(n) end
match_end(n)
click to toggle source
# File lib/textbringer/commands/replace.rb, line 25 def match_end(n) Buffer.current.match_end(n) end
match_string(n)
click to toggle source
# File lib/textbringer/commands/replace.rb, line 29 def match_string(n) Buffer.current.match_string(n) end
number_prefix_arg()
click to toggle source
# File lib/textbringer/commands/misc.rb, line 181 def number_prefix_arg prefix_numeric_value(current_prefix_arg) end
prefix_numeric_value(arg)
click to toggle source
# File lib/textbringer/commands/misc.rb, line 168 def prefix_numeric_value(arg) case arg when Integer arg when Array arg.first when :- -1 else 1 end end
read_input_method_name(prompt, default: CONFIG[:default_input_method])
click to toggle source
# File lib/textbringer/commands/input_method.rb, line 11 def read_input_method_name(prompt, default: CONFIG[:default_input_method]) f = ->(s) { complete_for_minibuffer(s.tr("-", "_"), InputMethod.list) } read_from_minibuffer(prompt, completion_proc: f, default: default) end
read_keyboard_macro(prompt)
click to toggle source
# File lib/textbringer/commands/keyboard_macro.rb, line 54 def read_keyboard_macro(prompt) macros = KEYBOARD_MACROS.keys.map(&:to_s) f = ->(s) { complete_for_minibuffer(s, macros) } read_from_minibuffer(prompt, completion_proc: f) end
read_register(prompt)
click to toggle source
# File lib/textbringer/commands/register.rb, line 26 def read_register(prompt) Window.echo_area.show(prompt) Window.redisplay begin register = read_char register ensure Window.echo_area.clear Window.redisplay end end
replace_match(s)
click to toggle source
# File lib/textbringer/commands/replace.rb, line 33 def replace_match(s) Buffer.current.replace_match(s) end
universal_argument_mode()
click to toggle source
# File lib/textbringer/commands/misc.rb, line 155 def universal_argument_mode set_transient_map(UNIVERSAL_ARGUMENT_MAP) end
Private Instance Methods
complete_minibuffer_with_string(s)
click to toggle source
# File lib/textbringer/commands/misc.rb, line 113 def complete_minibuffer_with_string(s) minibuffer = Buffer.minibuffer if s.start_with?(minibuffer.to_s) minibuffer.insert(s[minibuffer.to_s.size..-1]) else minibuffer.delete_region(minibuffer.point_min, minibuffer.point_max) minibuffer.insert(s) end end
define_command(name, doc: "No documentation", &block)
click to toggle source
# File lib/textbringer/commands.rb, line 24 def define_command(name, doc: "No documentation", &block) name = name.intern Commands.send(:define_method, name, &block) Commands.send(:module_function, name) Commands.command_table[name] = Command.new(name, block, doc) name end
goto_global_mark() { |global_mark_ring| ... }
click to toggle source
# File lib/textbringer/commands/misc.rb, line 234 def goto_global_mark global_mark_ring = Buffer.global_mark_ring mark = yield(global_mark_ring) if mark.buffer&.current? && Buffer.current.point_at_mark?(mark) mark = yield(global_mark_ring) end if mark.detached? find_file(mark.file_name) goto_char(mark.location) else switch_to_buffer(mark.buffer) mark.buffer.point_to_mark(mark) end end
push_help_command(cmd)
click to toggle source
# File lib/textbringer/commands/help.rb, line 5 def push_help_command(cmd) if HELP_RING.empty? || HELP_RING.current != cmd HELP_RING.push(cmd) end end
push_tag_mark_and_find_file(file)
click to toggle source
# File lib/textbringer/commands/ctags.rb, line 93 def push_tag_mark_and_find_file(file) Buffer.current.push_global_mark(force: true) find_file(file) end
show_help() { |help| ... }
click to toggle source
# File lib/textbringer/commands/help.rb, line 12 def show_help help = Buffer.find_or_new("*Help*", undo_limit: 0) help.read_only_edit do help.clear yield(help) help.beginning_of_buffer switch_to_buffer(help) help_mode end end
undefine_command(name)
click to toggle source
# File lib/textbringer/commands.rb, line 33 def undefine_command(name) name = name.intern if Commands.command_table.key?(name) Commands.send(:undef_method, name) Commands.command_table.delete(name) end end
update_completions(xs)
click to toggle source
# File lib/textbringer/commands/misc.rb, line 83 def update_completions(xs) if xs.size > 1 if COMPLETION[:original_buffer].nil? COMPLETION[:completions_window] = Window.list.last COMPLETION[:original_buffer] = COMPLETION[:completions_window].buffer end completions = Buffer.find_or_new("*Completions*", undo_limit: 0) if !completions.mode.is_a?(CompletionListMode) completions.apply_mode(CompletionListMode) end completions.read_only = false begin completions.clear xs.each do |x| completions.insert(x + "\n") end COMPLETION[:completions_window].buffer = completions ensure completions.read_only = true end else if COMPLETION[:original_buffer] COMPLETION[:completions_window].buffer = COMPLETION[:original_buffer] end end end