diakonos 0.8.8 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +433 -0
- data/LICENCE.md +675 -0
- data/bin/diakonos +6 -0
- data/diakonos-256-colour.conf +220 -0
- data/diakonos.conf +1802 -0
- data/help/about-help.dhf +31 -0
- data/help/clipboard.dhf +45 -0
- data/help/close-file.dhf +6 -0
- data/help/code-block-navigation.dhf +16 -0
- data/help/column-markers.dhf +15 -0
- data/help/config.dhf +69 -0
- data/help/cursor-stack.dhf +19 -0
- data/help/delete.dhf +41 -0
- data/help/extensions.dhf +125 -0
- data/help/file-type.dhf +24 -0
- data/help/key-mapping.dhf +127 -0
- data/help/line-numbers.dhf +22 -0
- data/help/macros.dhf +27 -0
- data/help/new-file.dhf +6 -0
- data/help/open-file.dhf +21 -0
- data/help/quit.dhf +7 -0
- data/help/resizing.dhf +19 -0
- data/help/ruby.dhf +17 -0
- data/help/save-file.dhf +10 -0
- data/help/scripting.dhf +92 -0
- data/help/search.dhf +103 -0
- data/help/shell.dhf +60 -0
- data/help/speed.dhf +23 -0
- data/help/support.dhf +15 -0
- data/help/switch-buffers.dhf +15 -0
- data/help/tabs.dhf +36 -0
- data/help/undo.dhf +9 -0
- data/help/uninstall.dhf +18 -0
- data/help/welcome.dhf +32 -0
- data/help/word-wrap.dhf +17 -0
- data/lib/diakonos/about.rb +69 -0
- data/lib/diakonos/bookmark.rb +46 -0
- data/lib/diakonos/buffer/bookmarking.rb +47 -0
- data/lib/diakonos/buffer/cursor.rb +335 -0
- data/lib/diakonos/buffer/delete.rb +170 -0
- data/lib/diakonos/buffer/display.rb +356 -0
- data/lib/diakonos/buffer/file.rb +157 -0
- data/lib/diakonos/buffer/indentation.rb +175 -0
- data/lib/diakonos/buffer/searching.rb +552 -0
- data/lib/diakonos/buffer/selection.rb +360 -0
- data/lib/diakonos/buffer/undo.rb +73 -0
- data/lib/diakonos/buffer-hash.rb +60 -0
- data/lib/diakonos/buffer-management.rb +59 -0
- data/lib/diakonos/buffer.rb +698 -0
- data/lib/diakonos/clipboard-klipper-dbus.rb +62 -0
- data/lib/diakonos/clipboard-klipper.rb +62 -0
- data/lib/diakonos/clipboard-osx.rb +59 -0
- data/lib/diakonos/clipboard-xclip.rb +60 -0
- data/lib/diakonos/clipboard.rb +47 -0
- data/lib/diakonos/config-file.rb +67 -0
- data/lib/diakonos/config.rb +381 -0
- data/lib/diakonos/core-ext/enumerable.rb +15 -0
- data/lib/diakonos/core-ext/hash.rb +60 -0
- data/lib/diakonos/core-ext/object.rb +6 -0
- data/lib/diakonos/core-ext/regexp.rb +6 -0
- data/lib/diakonos/core-ext/string.rb +122 -0
- data/lib/diakonos/ctag.rb +28 -0
- data/lib/diakonos/cursor.rb +27 -0
- data/lib/diakonos/display/format.rb +75 -0
- data/lib/diakonos/display.rb +336 -0
- data/lib/diakonos/extension-set.rb +49 -0
- data/lib/diakonos/extension.rb +34 -0
- data/lib/diakonos/finding.rb +40 -0
- data/lib/diakonos/functions/basics.rb +34 -0
- data/lib/diakonos/functions/bookmarking.rb +61 -0
- data/lib/diakonos/functions/buffers.rb +489 -0
- data/lib/diakonos/functions/clipboard.rb +70 -0
- data/lib/diakonos/functions/cursor.rb +264 -0
- data/lib/diakonos/functions/grepping.rb +83 -0
- data/lib/diakonos/functions/indentation.rb +71 -0
- data/lib/diakonos/functions/readline.rb +93 -0
- data/lib/diakonos/functions/search.rb +179 -0
- data/lib/diakonos/functions/selection.rb +98 -0
- data/lib/diakonos/functions/sessions.rb +78 -0
- data/lib/diakonos/functions/shell.rb +250 -0
- data/lib/diakonos/functions/tags.rb +65 -0
- data/lib/diakonos/functions/text-manipulation.rb +196 -0
- data/lib/diakonos/functions-deprecated.rb +77 -0
- data/lib/diakonos/functions.rb +292 -0
- data/lib/diakonos/grep.rb +98 -0
- data/lib/diakonos/help.rb +47 -0
- data/lib/diakonos/hooks.rb +13 -0
- data/lib/diakonos/installation.rb +19 -0
- data/lib/diakonos/interaction-handler.rb +216 -0
- data/lib/diakonos/interaction.rb +52 -0
- data/lib/diakonos/key-map.rb +62 -0
- data/lib/diakonos/keying.rb +442 -0
- data/lib/diakonos/line-mover.rb +42 -0
- data/lib/diakonos/list.rb +59 -0
- data/lib/diakonos/logging.rb +27 -0
- data/lib/diakonos/mode.rb +17 -0
- data/lib/diakonos/mouse.rb +18 -0
- data/lib/diakonos/number-fitter.rb +11 -0
- data/lib/diakonos/range.rb +31 -0
- data/lib/diakonos/readline/functions.rb +82 -0
- data/lib/diakonos/readline.rb +222 -0
- data/lib/diakonos/search.rb +58 -0
- data/lib/diakonos/sessions.rb +257 -0
- data/lib/diakonos/sized-array.rb +48 -0
- data/lib/diakonos/text-mark.rb +19 -0
- data/lib/diakonos/vendor/fuzzy_file_finder.rb +365 -0
- data/lib/diakonos/version.rb +25 -0
- data/lib/diakonos/window.rb +43 -0
- data/lib/diakonos.rb +592 -0
- metadata +160 -66
@@ -0,0 +1,77 @@
|
|
1
|
+
module Diakonos
|
2
|
+
|
3
|
+
class Diakonos
|
4
|
+
alias_method :loadConfiguration, :load_configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
module Functions
|
8
|
+
alias_method :addNamedBookmark, :add_named_bookmark
|
9
|
+
alias_method :anchorSelection, :anchor_selection
|
10
|
+
alias_method :carriageReturn, :carriage_return
|
11
|
+
alias_method :changeSessionSetting, :change_session_setting
|
12
|
+
alias_method :clearMatches, :clear_matches
|
13
|
+
alias_method :closeFile, :close_buffer
|
14
|
+
alias_method :close_file, :close_buffer
|
15
|
+
alias_method :collapseWhitespace, :collapse_whitespace
|
16
|
+
alias_method :copySelection, :copy_selection
|
17
|
+
alias_method :cursorDown, :cursor_down
|
18
|
+
alias_method :cursorLeft, :cursor_left
|
19
|
+
alias_method :cursorRight, :cursor_right
|
20
|
+
alias_method :cursorUp, :cursor_up
|
21
|
+
alias_method :cursorBOF, :cursor_bof
|
22
|
+
alias_method :cursorBOL, :cursor_bol
|
23
|
+
alias_method :cursorEOL, :cursor_eol
|
24
|
+
alias_method :cursorEOF, :cursor_eof
|
25
|
+
alias_method :cursorTOV, :cursor_tov
|
26
|
+
alias_method :cursorBOV, :cursor_bov
|
27
|
+
alias_method :cursorReturn, :cursor_return
|
28
|
+
alias_method :cutSelection, :cut_selection
|
29
|
+
alias_method :deleteAndStoreLine, :delete_and_store_line
|
30
|
+
alias_method :deleteLine, :delete_line
|
31
|
+
alias_method :deleteToEOL, :delete_to_eol
|
32
|
+
alias_method :findAgain, :find_again
|
33
|
+
alias_method :findAndReplace, :search_and_replace
|
34
|
+
alias_method :findExact, :find_exact
|
35
|
+
alias_method :goToLineAsk, :go_to_line_ask
|
36
|
+
alias_method :goToNamedBookmark, :go_to_named_bookmark
|
37
|
+
alias_method :goToNextBookmark, :go_to_next_bookmark
|
38
|
+
alias_method :goToPreviousBookmark, :go_to_previous_bookmark
|
39
|
+
alias_method :goToTag, :go_to_tag
|
40
|
+
alias_method :goToTagUnderCursor, :go_to_tag_under_cursor
|
41
|
+
alias_method :insertSpaces, :insert_spaces
|
42
|
+
alias_method :insertTab, :insert_tab
|
43
|
+
alias_method :joinLines, :join_lines
|
44
|
+
alias_method :loadScript, :load_script
|
45
|
+
alias_method :newFile, :open_file
|
46
|
+
alias_method :openFile, :open_file
|
47
|
+
alias_method :openFileAsk, :open_file_ask
|
48
|
+
alias_method :operateOnString, :operate_on_string
|
49
|
+
alias_method :operateOnLines, :operate_on_lines
|
50
|
+
alias_method :operateOnEachLine, :operate_on_each_line
|
51
|
+
alias_method :pageUp, :page_up
|
52
|
+
alias_method :pageDown, :page_down
|
53
|
+
alias_method :parsedIndent, :parsed_indent
|
54
|
+
alias_method :playMacro, :play_macro
|
55
|
+
alias_method :popTag, :pop_tag
|
56
|
+
alias_method :printKeychain, :print_keychain
|
57
|
+
alias_method :removeNamedBookmark, :remove_named_bookmark
|
58
|
+
alias_method :removeSelection, :remove_selection
|
59
|
+
alias_method :repeatLast, :repeat_last
|
60
|
+
alias_method :saveFile, :save_file
|
61
|
+
alias_method :saveFileAs, :save_file_as
|
62
|
+
alias_method :scrollDown, :scroll_down
|
63
|
+
alias_method :scrollUp, :scroll_up
|
64
|
+
alias_method :searchAndReplace, :search_and_replace
|
65
|
+
alias_method :setBufferType, :set_buffer_type
|
66
|
+
alias_method :setReadOnly, :set_read_only
|
67
|
+
alias_method :showClips, :show_clips
|
68
|
+
alias_method :pasteShellResult, :paste_shell_result
|
69
|
+
alias_method :toggleMacroRecording, :toggle_macro_recording
|
70
|
+
alias_method :switchToBufferNumber, :switch_to_buffer_number
|
71
|
+
alias_method :switchToNextBuffer, :switch_to_next_buffer
|
72
|
+
alias_method :switchToPreviousBuffer, :switch_to_previous_buffer
|
73
|
+
alias_method :toggleBookmark, :toggle_bookmark
|
74
|
+
alias_method :toggleSelection, :toggle_selection
|
75
|
+
alias_method :toggleSessionSetting, :toggle_session_setting
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,292 @@
|
|
1
|
+
module Diakonos
|
2
|
+
|
3
|
+
# The Diakonos::Functions module contains all the methods that can be mapped
|
4
|
+
# to keys in Diakonos. New methods can be added to this module by
|
5
|
+
# extensions.
|
6
|
+
|
7
|
+
module Functions
|
8
|
+
|
9
|
+
# Shows the About page, which gives information on Diakonos.
|
10
|
+
def about
|
11
|
+
about_write
|
12
|
+
open_file @about_filename
|
13
|
+
end
|
14
|
+
|
15
|
+
# Deletes characters up to, but not including, a given character.
|
16
|
+
# Also puts the deleted text into the clipboard.
|
17
|
+
def delete_to( char = nil )
|
18
|
+
if char.nil?
|
19
|
+
set_iline "Type character to delete to..."
|
20
|
+
char = @win_main.getch
|
21
|
+
set_iline
|
22
|
+
end
|
23
|
+
if char
|
24
|
+
removed_text = buffer_current.delete_to char
|
25
|
+
if removed_text
|
26
|
+
@clipboard.add_clip removed_text
|
27
|
+
else
|
28
|
+
set_iline "'#{char}' not found."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Deletes characters starting from (but not including) a given character
|
34
|
+
# up to (but not including) the current cursor position.
|
35
|
+
# Also puts the deleted text into the clipboard.
|
36
|
+
def delete_from( char = nil )
|
37
|
+
if char.nil?
|
38
|
+
set_iline "Type character to delete from..."
|
39
|
+
char = @win_main.getch
|
40
|
+
set_iline
|
41
|
+
end
|
42
|
+
if char
|
43
|
+
removed_text = buffer_current.delete_from(char)
|
44
|
+
if removed_text
|
45
|
+
@clipboard.add_clip removed_text
|
46
|
+
else
|
47
|
+
set_iline "'#{char}' not found."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Deletes characters between, but not including, a given pair of
|
53
|
+
# characters. Also puts the deleted text into the clipboard.
|
54
|
+
# Brace characters are intelligently matched with their opposite-side
|
55
|
+
# counterparts if the left-side brace is given (e.g. '[').
|
56
|
+
def delete_to_and_from( inclusive = nil, char = nil )
|
57
|
+
if char.nil?
|
58
|
+
set_iline "Type character to delete to and from..."
|
59
|
+
char = @win_main.getch
|
60
|
+
set_iline
|
61
|
+
end
|
62
|
+
if char
|
63
|
+
removed_text = buffer_current.delete_to_and_from(
|
64
|
+
char,
|
65
|
+
inclusive == :inclusive ? INCLUSIVE : NOT_INCLUSIVE
|
66
|
+
)
|
67
|
+
if removed_text
|
68
|
+
@clipboard.add_clip( [ removed_text ] )
|
69
|
+
else
|
70
|
+
set_iline "'#{char}' not found."
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Evaluates (executes) Ruby code.
|
76
|
+
def evaluate( code_ = nil )
|
77
|
+
if code_.nil?
|
78
|
+
if buffer_current.changing_selection
|
79
|
+
selected_text = buffer_current.copy_selection[ 0 ]
|
80
|
+
end
|
81
|
+
code = get_user_input(
|
82
|
+
"Ruby code: ",
|
83
|
+
history: @rlh_general,
|
84
|
+
initial_text: selected_text || "",
|
85
|
+
completion_array: ::Diakonos::Functions.public_instance_methods.map { |m| m.to_s }
|
86
|
+
)
|
87
|
+
else
|
88
|
+
code = code_
|
89
|
+
end
|
90
|
+
|
91
|
+
if code
|
92
|
+
begin
|
93
|
+
eval code
|
94
|
+
rescue Exception => e
|
95
|
+
show_exception(
|
96
|
+
e,
|
97
|
+
[
|
98
|
+
"The code given to evaluate has a syntax error.",
|
99
|
+
"The code given to evaluate refers to a Diakonos command which does not exist, or is misspelled.",
|
100
|
+
"The code given to evaluate refers to a Diakonos command with missing arguments.",
|
101
|
+
"The code given to evaluate refers to a variable or method which does not exist.",
|
102
|
+
]
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Starts the interactive help system.
|
109
|
+
def help( prefill = '' )
|
110
|
+
if ! File.exist?( @help_dir ) || Dir[ "#{@help_dir}/*" ].size == 0
|
111
|
+
set_iline 'There are no help files installed.'
|
112
|
+
return
|
113
|
+
end
|
114
|
+
|
115
|
+
open_help_buffer
|
116
|
+
matching_docs = nil
|
117
|
+
|
118
|
+
selected = get_user_input(
|
119
|
+
"Search terms: ",
|
120
|
+
history: @rlh_help,
|
121
|
+
initial_text: prefill,
|
122
|
+
completion_array: @help_tags
|
123
|
+
) { |input|
|
124
|
+
next if input.length < 3 && input[ 0..0 ] != '/'
|
125
|
+
|
126
|
+
matching_docs = matching_help_documents( input )
|
127
|
+
with_list_file do |list|
|
128
|
+
list.puts matching_docs.join( "\n" )
|
129
|
+
end
|
130
|
+
|
131
|
+
open_list_buffer
|
132
|
+
}
|
133
|
+
|
134
|
+
close_help_buffer
|
135
|
+
|
136
|
+
case selected
|
137
|
+
when /\|/
|
138
|
+
open_help_document selected
|
139
|
+
when nil
|
140
|
+
# Help search aborted; do nothing
|
141
|
+
else
|
142
|
+
# Not a selected help document
|
143
|
+
if matching_docs.nil? || matching_docs.empty?
|
144
|
+
matching_docs = matching_help_documents( selected )
|
145
|
+
end
|
146
|
+
|
147
|
+
case matching_docs.size
|
148
|
+
when 1
|
149
|
+
open_help_document matching_docs[ 0 ]
|
150
|
+
when 0
|
151
|
+
File.open( @error_filename, 'w' ) do |f|
|
152
|
+
f.puts "There were no help documents matching your search."
|
153
|
+
f.puts "(#{selected.strip})"
|
154
|
+
f.puts "Close this message with Ctrl-W (default keychord)."
|
155
|
+
end
|
156
|
+
error_file = open_file( @error_filename )
|
157
|
+
else
|
158
|
+
help selected
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Loads Ruby code from file using Kernel#load.
|
164
|
+
def load_script( name_ = nil )
|
165
|
+
if name_.nil?
|
166
|
+
name = get_user_input( "File to load as script: ", history: @rlh_files )
|
167
|
+
else
|
168
|
+
name = name_
|
169
|
+
end
|
170
|
+
|
171
|
+
if name
|
172
|
+
thread = Thread.new( name ) do |f|
|
173
|
+
begin
|
174
|
+
load( f )
|
175
|
+
rescue Exception => e
|
176
|
+
show_exception(
|
177
|
+
e,
|
178
|
+
[
|
179
|
+
"The filename given does not exist.",
|
180
|
+
"The filename given is not accessible or readable.",
|
181
|
+
"The loaded script does not reference Diakonos commands as members of the global Diakonos object. e.g. cursor_bol instead of $diakonos.cursor_bol",
|
182
|
+
"The loaded script has syntax errors.",
|
183
|
+
"The loaded script references objects or object members which do not exist."
|
184
|
+
]
|
185
|
+
)
|
186
|
+
end
|
187
|
+
set_iline "Loaded script '#{name}'."
|
188
|
+
end
|
189
|
+
|
190
|
+
loop do
|
191
|
+
if thread.status != "run"
|
192
|
+
break
|
193
|
+
else
|
194
|
+
sleep 0.1
|
195
|
+
end
|
196
|
+
end
|
197
|
+
thread.join
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def play_macro( name = nil )
|
202
|
+
macro, input_history = @macros[ name ]
|
203
|
+
if input_history
|
204
|
+
@macro_input_history = input_history.deep_clone
|
205
|
+
if macro
|
206
|
+
@playing_macro = true
|
207
|
+
macro.each do |command|
|
208
|
+
eval command
|
209
|
+
end
|
210
|
+
@playing_macro = false
|
211
|
+
@macro_input_history = nil
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def print_mapped_function
|
217
|
+
@capturing_mapping = true
|
218
|
+
set_iline "Type any chain of keystrokes or key chords, or press Enter to stop."
|
219
|
+
end
|
220
|
+
|
221
|
+
def print_keychain
|
222
|
+
@capturing_keychain = true
|
223
|
+
set_iline "Type any chain of keystrokes or key chords, then press Enter..."
|
224
|
+
end
|
225
|
+
|
226
|
+
# Quits Diakonos (gracefully).
|
227
|
+
def quit
|
228
|
+
@quitting = true
|
229
|
+
to_all = nil
|
230
|
+
save_session
|
231
|
+
@buffers.each do |buffer|
|
232
|
+
next if ! buffer.modified?
|
233
|
+
switch_to buffer
|
234
|
+
closure_choice = close_buffer( buffer, to_all: to_all )
|
235
|
+
case closure_choice
|
236
|
+
when CHOICE_CANCEL
|
237
|
+
@quitting = false
|
238
|
+
break
|
239
|
+
when CHOICE_YES_TO_ALL, CHOICE_NO_TO_ALL
|
240
|
+
to_all = closure_choice
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def repeat_last
|
246
|
+
eval @functions_last[ -1 ] if ! @functions_last.empty?
|
247
|
+
end
|
248
|
+
|
249
|
+
# Send the Diakonos job to background, as if with Ctrl-Z
|
250
|
+
def suspend
|
251
|
+
Curses::close_screen
|
252
|
+
Process.kill( "SIGSTOP", $PID )
|
253
|
+
Curses::init_screen
|
254
|
+
refresh_all
|
255
|
+
end
|
256
|
+
|
257
|
+
# Starts or stops macro recording.
|
258
|
+
def toggle_macro_recording( name = nil )
|
259
|
+
if @macro_history
|
260
|
+
stop_recording_macro
|
261
|
+
else
|
262
|
+
start_recording_macro name
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
# Undoes the latest change made to the current buffer,
|
267
|
+
# or reopens the file that was just closed.
|
268
|
+
def undo( buffer = buffer_current )
|
269
|
+
if @functions_last[-1] == 'close_buffer'
|
270
|
+
open_file(
|
271
|
+
@buffer_closed.name,
|
272
|
+
'cursor' => {
|
273
|
+
'row' => @buffer_closed.last_row,
|
274
|
+
'col' => @buffer_closed.last_col,
|
275
|
+
},
|
276
|
+
'display' => {
|
277
|
+
'top_line' => @buffer_closed.top_line,
|
278
|
+
'left_col' => @buffer_closed.left_column,
|
279
|
+
}
|
280
|
+
)
|
281
|
+
else
|
282
|
+
buffer.undo
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
# Redoes the latest change undone on the current buffer.
|
287
|
+
def unundo( buffer = buffer_current )
|
288
|
+
buffer.unundo
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
292
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Diakonos
|
2
|
+
def self.grep_array( regexp, array, lines_of_context, prefix, filepath )
|
3
|
+
num_lines = array.size
|
4
|
+
line_numbers = []
|
5
|
+
array.each_with_index do |line,index|
|
6
|
+
next if line !~ regexp
|
7
|
+
start_index = [ 0, index - lines_of_context ].max
|
8
|
+
end_index = [ index + lines_of_context, num_lines-1 ].min
|
9
|
+
(start_index..end_index).each do |i|
|
10
|
+
line_numbers << i
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
line_numbers.uniq!
|
15
|
+
results = []
|
16
|
+
last_i = line_numbers[ 0 ]
|
17
|
+
one_result = []
|
18
|
+
line_numbers.each do |i|
|
19
|
+
if i - last_i > 1
|
20
|
+
results << one_result.join( "\n" )
|
21
|
+
one_result = []
|
22
|
+
end
|
23
|
+
one_result << ( "#{prefix}#{i+1}: " << ( "%-300s | #{filepath}:#{i+1}" % array[ i ] ) )
|
24
|
+
last_i = i
|
25
|
+
end
|
26
|
+
if ! one_result.empty?
|
27
|
+
results << one_result.join( "\n" )
|
28
|
+
end
|
29
|
+
|
30
|
+
results
|
31
|
+
end
|
32
|
+
|
33
|
+
class Diakonos
|
34
|
+
|
35
|
+
def actually_grep( regexp_source, *buffers )
|
36
|
+
begin
|
37
|
+
regexp = Regexp.new( regexp_source, Regexp::IGNORECASE )
|
38
|
+
grep_results = buffers.map { |buffer| buffer.grep(regexp) }.flatten
|
39
|
+
if settings[ 'grep.context' ] == 0
|
40
|
+
join_str = "\n"
|
41
|
+
else
|
42
|
+
join_str = "\n---\n"
|
43
|
+
end
|
44
|
+
with_list_file do |list|
|
45
|
+
list.puts grep_results.join( join_str )
|
46
|
+
end
|
47
|
+
list_buffer = open_list_buffer
|
48
|
+
list_buffer.highlight_matches regexp
|
49
|
+
display_buffer list_buffer
|
50
|
+
rescue RegexpError
|
51
|
+
# Do nothing
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def grep_( regexp_source, *buffers )
|
56
|
+
original_buffer = buffer_current
|
57
|
+
if buffer_current.changing_selection
|
58
|
+
selected_text = buffer_current.copy_selection[ 0 ]
|
59
|
+
end
|
60
|
+
starting_row, starting_col = buffer_current.last_row, buffer_current.last_col
|
61
|
+
|
62
|
+
selected = get_user_input(
|
63
|
+
"Grep regexp: ",
|
64
|
+
history: @rlh_search,
|
65
|
+
initial_text: regexp_source || selected_text || "",
|
66
|
+
will_display_after_select: true
|
67
|
+
) { |input|
|
68
|
+
next if input.length < 2
|
69
|
+
actually_grep input, *buffers
|
70
|
+
}
|
71
|
+
|
72
|
+
if selected
|
73
|
+
spl = selected.split( "| " )
|
74
|
+
if spl.size > 1
|
75
|
+
open_file spl[-1]
|
76
|
+
else
|
77
|
+
original_buffer.cursor_to starting_row, starting_col
|
78
|
+
end
|
79
|
+
else
|
80
|
+
original_buffer.cursor_to starting_row, starting_col
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def increase_grep_context
|
85
|
+
current = settings['grep.context']
|
86
|
+
@session.settings['grep.context'] = current + 1
|
87
|
+
merge_session_settings
|
88
|
+
end
|
89
|
+
def decrease_grep_context
|
90
|
+
current = settings['grep.context']
|
91
|
+
if current > 0
|
92
|
+
@session.settings['grep.context'] = current - 1
|
93
|
+
merge_session_settings
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Diakonos
|
2
|
+
class Diakonos
|
3
|
+
def init_help
|
4
|
+
@help_dir = INSTALL_SETTINGS[ :help_dir ]
|
5
|
+
@help_tags = `grep -h Tags #{@help_dir}/* | cut -d ' ' -f 2-`.split.uniq
|
6
|
+
end
|
7
|
+
|
8
|
+
def open_help_buffer
|
9
|
+
@help_buffer = open_file( @help_filename )
|
10
|
+
end
|
11
|
+
def close_help_buffer
|
12
|
+
close_buffer @help_buffer
|
13
|
+
@help_buffer = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def matching_help_documents( str )
|
17
|
+
docs = []
|
18
|
+
|
19
|
+
if str =~ %r{^/(.+)$}
|
20
|
+
regexp = $1
|
21
|
+
files = Dir[ "#{@help_dir}/*" ].select{ |f|
|
22
|
+
File.open( f ) { |io| io.grep( /#{regexp}/i ) }.any?
|
23
|
+
}
|
24
|
+
else
|
25
|
+
terms = str.gsub( /[^a-zA-Z0-9-]/, ' ' ).split.join( '|' )
|
26
|
+
file_grep = `egrep -i -l '^Tags.*\\b(#{terms})\\b' #{@help_dir}/*`
|
27
|
+
files = file_grep.split( /\s+/ )
|
28
|
+
end
|
29
|
+
|
30
|
+
files.each do |file|
|
31
|
+
File.open( file ) do |f|
|
32
|
+
docs << ( "%-300s | %s" % [ f.gets.strip, file ] )
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
docs.sort { |a,b| a.gsub( /^# (?:an?|the) */i, '# ' ) <=> b.gsub( /^# (?:an?|the) */i, '# ' ) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def open_help_document( selected_string )
|
40
|
+
help_file = selected_string.split( "| " )[ -1 ]
|
41
|
+
if File.exist? help_file
|
42
|
+
open_file help_file
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Diakonos
|
2
|
+
class Diakonos
|
3
|
+
def register_proc( the_proc, hook_name, priority = 0 )
|
4
|
+
@hooks[ hook_name ] << { :proc => the_proc, :priority => priority }
|
5
|
+
end
|
6
|
+
|
7
|
+
def run_hook_procs( hook_id, *args )
|
8
|
+
@hooks[ hook_id ].each do |hook_proc|
|
9
|
+
hook_proc[ :proc ].call( *args )
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file is completely overwritten by install.rb upon installation.
|
2
|
+
# This copy is here to permit the tests to execute.
|
3
|
+
|
4
|
+
module Diakonos
|
5
|
+
root = File.expand_path("../..", __dir__)
|
6
|
+
|
7
|
+
INSTALL_SETTINGS = {
|
8
|
+
:prefix => root,
|
9
|
+
:bin_dir => File.join(root, "bin"),
|
10
|
+
:doc_dir => root,
|
11
|
+
:help_dir => File.join(root, "help"),
|
12
|
+
:conf_dir => root,
|
13
|
+
:lib_dir => File.join(root, "lib"),
|
14
|
+
:installed => {
|
15
|
+
:files => [],
|
16
|
+
:dirs => [],
|
17
|
+
},
|
18
|
+
}
|
19
|
+
end
|