Module: Textbringer::Commands
- Includes:
- Utils
- Included in:
- GlobalMinorMode, GlobalMinorMode, InputMethod, InputMethod, MinorMode, MinorMode, Mode, Mode
- Defined in:
- lib/textbringer/commands.rb,
lib/textbringer/commands/fill.rb,
lib/textbringer/commands/help.rb,
lib/textbringer/commands/misc.rb,
lib/textbringer/commands/ctags.rb,
lib/textbringer/commands/files.rb,
lib/textbringer/commands/ispell.rb,
lib/textbringer/commands/server.rb,
lib/textbringer/commands/buffers.rb,
lib/textbringer/commands/dabbrev.rb,
lib/textbringer/commands/isearch.rb,
lib/textbringer/commands/replace.rb,
lib/textbringer/commands/windows.rb,
lib/textbringer/commands/register.rb,
lib/textbringer/commands/clipboard.rb,
lib/textbringer/commands/rectangle.rb,
lib/textbringer/commands/input_method.rb,
lib/textbringer/commands/ucs_normalize.rb,
lib/textbringer/commands/keyboard_macro.rb
Defined Under Namespace
Modules: SymbolDump
Classes: BufferPosition, Ispell
Constant Summary
collapse
- HELP_RING =
Ring.new
- CTAGS =
{
path: nil,
tags: nil,
tags_mtime: nil,
name: nil,
candidates: nil,
index: nil,
tag_mark_stack: []
}
- ISPELL_STATUS =
{}
- URI_REGEXP =
URI::RFC2396_PARSER.make_regexp(["http", "https", "ftp", "mailto"])
- EMAIL_REGEXP =
/
# local-part
( # dot-atom
(?<atom>[0-9a-z!\#$%&'*+\-\/=?^_`{|}~]+)
(\.\g<atom>)*
| # quoted-string
\"([\x20\x21\x23-\x5b\x5d-\x7e]
|\\[\x20-\x7e])*\"
)@
# domain
(?<sub_domain>[0-9a-z]([0-9a-z-]*[0-9a-z])?)
(\.\g<sub_domain>)*
/ix
- ISPELL_WORD_REGEXP =
/
(?<uri>#{URI_REGEXP})
| (?<email>#{EMAIL_REGEXP})
| (?<word>[[:alpha:]]+(?:'[[:alpha:]]+)*)
/x
- ISEARCH_STATUS =
{
forward: true,
string: "",
last_string: "",
start: 0,
last_pos: 0,
recursive_edit: false
}
- RE_SEARCH_STATUS =
{
last_regexp: nil
}
- REGISTERS =
{}
- CLIPBOARD_AVAILABLE =
Clipboard.implementation.name != "Clipboard::File"
- KEYBOARD_MACROS =
{}
Constants included
from Utils
Utils::COMPLETION, Utils::EXPRESSION_COMPLETOR, Utils::EXPRESSION_COMPLETOR_OPTIONS, Utils::HOOKS
Class Method Summary
collapse
Instance Method Summary
collapse
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
.[](name) ⇒ Object
20
21
22
|
# File 'lib/textbringer/commands.rb', line 20
def self.[](name)
@command_table[name.intern]
end
|
.command_table ⇒ Object
16
17
18
|
# File 'lib/textbringer/commands.rb', line 16
def self.command_table
@command_table
end
|
.define_command(name, doc: "No documentation", &block) ⇒ Object
24
25
26
27
28
29
30
|
# 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 ⇒ Object
12
13
14
|
# File 'lib/textbringer/commands.rb', line 12
def self.list
@command_table.keys
end
|
.undefine_command(name) ⇒ Object
Instance Method Details
#command_help(cmd) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/textbringer/commands/help.rb', line 67
def command_help(cmd)
file, line = *cmd.block.source_location
s = format("%s:%d\n", file, line)
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 ⇒ Object
166
167
168
|
# File 'lib/textbringer/commands/misc.rb', line 166
def current_prefix_arg
Controller.current.current_prefix_arg
end
|
#ensure_ispell_active ⇒ Object
230
231
232
233
234
|
# File 'lib/textbringer/commands/ispell.rb', line 230
def ensure_ispell_active
if ISPELL_STATUS[:ispell].nil?
raise EditorError, "ispell is not active"
end
end
|
#execute_keyboard_macro(macro, n = 1) ⇒ Object
38
39
40
|
# File 'lib/textbringer/commands/keyboard_macro.rb', line 38
def execute_keyboard_macro(macro, n = 1)
Controller.current.execute_keyboard_macro(macro, n)
end
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/textbringer/commands/ctags.rb', line 73
def get_tags
path = File.expand_path("tags")
mtime = File.mtime(path)
if CTAGS[:path] != path || CTAGS[:tags_mtime] != mtime
CTAGS[:path] = path
tags = Hash.new { |h, k| h[k] = [] }
File.read(path).scan(/^(.*?)\t(.*?)\t(.*?)(?:;".*)?$/) do
|name, file, addr|
n = tags[name].count { |f,| f == file } + 1
tags[name].push([file, addr, n])
end
CTAGS[:tags] = tags
CTAGS[:tags_mtime] = mtime
message("Loaded #{path}")
end
CTAGS[:tags]
end
|
#isearch_mode(forward, recursive_edit: false) ⇒ Object
#isearch_mode? ⇒ Boolean
61
62
63
|
# File 'lib/textbringer/commands/isearch.rb', line 61
def isearch_mode?
Controller.current.overriding_map == ISEARCH_MODE_MAP
end
|
#isearch_pre_command_hook ⇒ Object
73
74
75
76
77
|
# 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 ⇒ Object
65
66
67
68
69
70
71
|
# 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) ⇒ Object
#isearch_repeat_backward ⇒ Object
172
173
174
|
# File 'lib/textbringer/commands/isearch.rb', line 172
def isearch_repeat_backward
isearch_repeat(false)
end
|
#isearch_repeat_forward ⇒ Object
168
169
170
|
# File 'lib/textbringer/commands/isearch.rb', line 168
def isearch_repeat_forward
isearch_repeat(true)
end
|
#ispell_forward ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/textbringer/commands/ispell.rb', line 133
def ispell_forward
buffer = Buffer.current
while buffer.re_search_forward(ISPELL_WORD_REGEXP, raise_error: false,
goto_beginning: true)
if buffer.last_match[:word].nil?
buffer.goto_char(buffer.match_end(0))
next
end
ispell_beginning = buffer.point
unless buffer.mark_active?
buffer.set_visible_mark
end
buffer.goto_char(buffer.match_end(0))
word = buffer.match_string(0)
_original, suggestions = ISPELL_STATUS[:ispell].check_word(word)
if !suggestions.nil? && !suggestions.empty?
ISPELL_STATUS[:beginning] = ispell_beginning
ISPELL_STATUS[:word] = word
ISPELL_STATUS[:suggestions] = suggestions
message_misspelled
recenter
return false
end
end
Controller.current.overriding_map = nil
if ISPELL_STATUS[:ispell]&.personal_dictionary_modified? &&
y_or_n?("Personal dictionary modified. Save?")
ISPELL_STATUS[:ispell].save_personal_dictionary
end
message("Finished spelling check.")
ispell_done
true
end
|
#keymap_bindings(keymap) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/textbringer/commands/help.rb', line 32
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) ⇒ Object
21
22
23
|
# File 'lib/textbringer/commands/replace.rb', line 21
def match_beginning(n)
Buffer.current.match_beginning(n)
end
|
#match_end(n) ⇒ Object
25
26
27
|
# File 'lib/textbringer/commands/replace.rb', line 25
def match_end(n)
Buffer.current.match_end(n)
end
|
#match_string(n) ⇒ Object
29
30
31
|
# File 'lib/textbringer/commands/replace.rb', line 29
def match_string(n)
Buffer.current.match_string(n)
end
|
#message_misspelled ⇒ Object
225
226
227
228
|
# File 'lib/textbringer/commands/ispell.rb', line 225
def message_misspelled
word = ISPELL_STATUS[:word]
message("Misspelled: #{word} [r]eplace, [a]ccept, [i]nsert, [SPC] to skip, [q]uit")
end
|
#number_prefix_arg ⇒ Object
183
184
185
|
# File 'lib/textbringer/commands/misc.rb', line 183
def number_prefix_arg
prefix_numeric_value(current_prefix_arg)
end
|
#prefix_numeric_value(arg) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/textbringer/commands/misc.rb', line 170
def prefix_numeric_value(arg)
case arg
when Integer
arg
when Array
arg.first
when :-
-1
else
1
end
end
|
11
12
13
14
15
16
|
# 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) ⇒ Object
54
55
56
57
58
|
# 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) ⇒ Object
#replace_match(s) ⇒ Object
33
34
35
|
# File 'lib/textbringer/commands/replace.rb', line 33
def replace_match(s)
Buffer.current.replace_match(s)
end
|
#universal_argument_mode ⇒ Object
157
158
159
|
# File 'lib/textbringer/commands/misc.rb', line 157
def universal_argument_mode
set_transient_map(UNIVERSAL_ARGUMENT_MAP)
end
|