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,489 @@
|
|
1
|
+
module Diakonos
|
2
|
+
module Functions
|
3
|
+
|
4
|
+
# Closes a buffer.
|
5
|
+
#
|
6
|
+
# @param [Diakonos::Buffer] buffer
|
7
|
+
# The buffer to close. If no buffer is provided, defaults to the current buffer.
|
8
|
+
# @option opts [Integer] :to_all
|
9
|
+
# The CHOICE to assume for the prompt.
|
10
|
+
# @option opts [Boolean] :do_display
|
11
|
+
# Whether or not to update the display after closure
|
12
|
+
# @return [Integer] the choice the user made, or nil if the user was not prompted to choose.
|
13
|
+
# @see Diakonos::CHOICE_YES
|
14
|
+
# @see Diakonos::CHOICE_NO
|
15
|
+
def close_buffer( buffer = buffer_current, opts = {} )
|
16
|
+
return nil if buffer.nil?
|
17
|
+
|
18
|
+
to_all = opts[:to_all]
|
19
|
+
do_display = opts.fetch( :do_display, true )
|
20
|
+
|
21
|
+
choice = nil
|
22
|
+
if ! @buffers.include?( buffer )
|
23
|
+
log "No such buffer: #{buffer.name}"
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
|
27
|
+
do_closure = true
|
28
|
+
|
29
|
+
if buffer.modified? && ! buffer.read_only
|
30
|
+
if to_all
|
31
|
+
choice = to_all
|
32
|
+
else
|
33
|
+
choices = [ CHOICE_YES, CHOICE_NO, CHOICE_CANCEL ]
|
34
|
+
if @quitting
|
35
|
+
choices.concat [ CHOICE_YES_TO_ALL, CHOICE_NO_TO_ALL ]
|
36
|
+
end
|
37
|
+
choice = get_choice(
|
38
|
+
"Save changes to #{buffer.nice_name}?",
|
39
|
+
choices,
|
40
|
+
CHOICE_CANCEL
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
case choice
|
45
|
+
when CHOICE_YES, CHOICE_YES_TO_ALL
|
46
|
+
do_closure = true
|
47
|
+
save_file buffer
|
48
|
+
when CHOICE_NO, CHOICE_NO_TO_ALL
|
49
|
+
do_closure = true
|
50
|
+
when CHOICE_CANCEL
|
51
|
+
do_closure = false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if do_closure
|
56
|
+
del_buffer = nil
|
57
|
+
previous_buffer = nil
|
58
|
+
to_switch_to = nil
|
59
|
+
switching = false
|
60
|
+
|
61
|
+
# Search the buffer hash for the buffer we want to delete,
|
62
|
+
# and mark the one we will switch to after deletion.
|
63
|
+
@buffers.each do |b|
|
64
|
+
if switching
|
65
|
+
to_switch_to = b
|
66
|
+
break
|
67
|
+
end
|
68
|
+
|
69
|
+
if b == buffer
|
70
|
+
del_buffer = b
|
71
|
+
switching = true
|
72
|
+
next
|
73
|
+
end
|
74
|
+
|
75
|
+
previous_buffer = b
|
76
|
+
end
|
77
|
+
|
78
|
+
buf = nil
|
79
|
+
while(
|
80
|
+
@buffer_stack.any? &&
|
81
|
+
! @buffers.include?( buf ) ||
|
82
|
+
buf == del_buffer
|
83
|
+
) do
|
84
|
+
buf = @buffer_stack.pop
|
85
|
+
end
|
86
|
+
if @buffers.include?( buf )
|
87
|
+
to_switch_to = buf
|
88
|
+
end
|
89
|
+
|
90
|
+
if to_switch_to
|
91
|
+
switch_to to_switch_to, do_display: do_display
|
92
|
+
elsif previous_buffer
|
93
|
+
switch_to previous_buffer, do_display: do_display
|
94
|
+
end
|
95
|
+
|
96
|
+
@buffer_closed = del_buffer
|
97
|
+
@buffers.delete del_buffer
|
98
|
+
cursor_stack_remove_buffer del_buffer
|
99
|
+
|
100
|
+
if @buffer_stack.empty?
|
101
|
+
# No buffers left. Open a new blank one.
|
102
|
+
open_file
|
103
|
+
end
|
104
|
+
|
105
|
+
save_session
|
106
|
+
|
107
|
+
update_status_line
|
108
|
+
update_context_line
|
109
|
+
end
|
110
|
+
|
111
|
+
choice
|
112
|
+
end
|
113
|
+
|
114
|
+
# Opens the special "buffer selection" buffer, and prompts the user
|
115
|
+
# to select a buffer. The user can select a buffer either with the
|
116
|
+
# arrow keys and the Enter key, or by pressing the key corresponding
|
117
|
+
# to an index presented in a left-hand column in the list.
|
118
|
+
def list_buffers
|
119
|
+
bullets = ( ('0'..'9').to_a + ('a'..'z').to_a ).map { |s| "#{s} " }
|
120
|
+
buffers_unnamed = @buffers.find_all { |b| b.name.nil? }
|
121
|
+
buffers_named = @buffers.find_all { |b| b.name }
|
122
|
+
|
123
|
+
with_list_file do |f|
|
124
|
+
if buffers_unnamed.size == 1
|
125
|
+
bullet = bullets.shift
|
126
|
+
f.puts "#{bullet}(unnamed buffer)"
|
127
|
+
else
|
128
|
+
buffers_unnamed.each_with_index do |b,i|
|
129
|
+
bullet = bullets.shift
|
130
|
+
f.puts "#{bullet}(unnamed buffer #{i+1})"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
buffers_named.collect { |b| b.name }.sort.each_with_index do |name, index|
|
135
|
+
bullet = bullets.shift
|
136
|
+
f.puts "#{bullet}#{name}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
open_list_buffer
|
140
|
+
filename = get_user_input( "Switch to buffer: ", numbered_list: true )
|
141
|
+
buffer = buffers_named.find { |b| b.name == filename }
|
142
|
+
if buffer
|
143
|
+
switch_to buffer
|
144
|
+
elsif filename =~ /\(unnamed buffer( \d+)?/
|
145
|
+
switch_to( buffers_unnamed[ $1.to_i - 1 ] )
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Opens a file into a new Buffer.
|
150
|
+
# @param filename
|
151
|
+
# The file to open. If nil, an empty, unnamed buffer is opened.
|
152
|
+
# @param [Hash] meta
|
153
|
+
# metadata containing additional information on how to open the file
|
154
|
+
# @option meta [Hash] 'cursor' (nil)
|
155
|
+
# A Hash containing the 'row' and 'col' to position the cursor after opening.
|
156
|
+
# @option meta [Hash] 'display' (nil)
|
157
|
+
# A Hash containing the 'top_line' and 'left_column' to use to position
|
158
|
+
# the view after opening.
|
159
|
+
# @option meta [Boolean] 'read_only' (false)
|
160
|
+
# Whether to open the file in read-only (unmodifiable) mode
|
161
|
+
# @option meta [Boolean] 'revert' (false)
|
162
|
+
# Whether to skip asking about reverting to on-disk file contents (if different)
|
163
|
+
# @return [Buffer] the buffer of the opened file
|
164
|
+
# @return [NilClass] nil on failure
|
165
|
+
def open_file( filename = nil, meta = {} )
|
166
|
+
read_only = !!meta[ 'read_only' ]
|
167
|
+
force_revert = meta[ 'revert' ] || ASK_REVERT
|
168
|
+
if meta[ 'cursor' ]
|
169
|
+
last_row = meta[ 'cursor' ][ 'row' ]
|
170
|
+
last_col = meta[ 'cursor' ][ 'col' ]
|
171
|
+
end
|
172
|
+
if meta[ 'display' ]
|
173
|
+
top_line = meta[ 'display' ][ 'top_line' ]
|
174
|
+
left_column = meta[ 'display' ][ 'left_column' ]
|
175
|
+
end
|
176
|
+
|
177
|
+
do_open = true
|
178
|
+
buffer = nil
|
179
|
+
if filename
|
180
|
+
filename, last_row_ = ::Diakonos.parse_filename_and_line_number( filename )
|
181
|
+
last_row = last_row_ || last_row
|
182
|
+
if filename =~ /\(unnamed buffer (\d+)\)/
|
183
|
+
existing_buffer = @buffers.find { |b| b.object_id == $1.to_i }
|
184
|
+
filename = nil
|
185
|
+
do_open = false
|
186
|
+
else
|
187
|
+
existing_buffer = @buffers.find { |b| b.name == filename }
|
188
|
+
end
|
189
|
+
|
190
|
+
if filename
|
191
|
+
if existing_buffer
|
192
|
+
do_open = force_revert || ( filename =~ /\.diakonos/ )
|
193
|
+
switch_to existing_buffer, do_display: false
|
194
|
+
|
195
|
+
if ! do_open && existing_buffer.file_different?
|
196
|
+
show_buffer_file_diff( existing_buffer ) do
|
197
|
+
choice = get_choice(
|
198
|
+
"Load on-disk version of #{existing_buffer.nice_name}?",
|
199
|
+
[ CHOICE_YES, CHOICE_NO ]
|
200
|
+
)
|
201
|
+
case choice
|
202
|
+
when CHOICE_YES
|
203
|
+
do_open = true
|
204
|
+
when CHOICE_NO
|
205
|
+
do_open = false
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
if FileTest.exist?( filename )
|
212
|
+
# Don't try to open non-files (i.e. directories, pipes, sockets, etc.)
|
213
|
+
do_open &&= FileTest.file?( filename )
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
if do_open
|
219
|
+
# Is file readable?
|
220
|
+
|
221
|
+
# Does the "file" utility exist?
|
222
|
+
if(
|
223
|
+
filename &&
|
224
|
+
@settings[ 'use_magic_file' ] &&
|
225
|
+
FileTest.exist?( "/usr/bin/file" ) &&
|
226
|
+
FileTest.exist?( filename ) &&
|
227
|
+
/\blisting\.txt\b/ !~ filename
|
228
|
+
)
|
229
|
+
file_type = `/usr/bin/file -L #{filename}`
|
230
|
+
if file_type !~ /text/ && file_type !~ /empty$/
|
231
|
+
choice = get_choice(
|
232
|
+
"#{filename} does not appear to be readable. Try to open it anyway?",
|
233
|
+
[ CHOICE_YES, CHOICE_NO ],
|
234
|
+
CHOICE_NO
|
235
|
+
)
|
236
|
+
case choice
|
237
|
+
when CHOICE_NO
|
238
|
+
do_open = false
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
if do_open
|
245
|
+
buffer = Buffer.new(
|
246
|
+
'filepath' => filename,
|
247
|
+
'read_only' => read_only,
|
248
|
+
'display' => {
|
249
|
+
'top_line' => top_line,
|
250
|
+
'left_column' => left_column,
|
251
|
+
},
|
252
|
+
'cursor' => {
|
253
|
+
'row' => last_row,
|
254
|
+
'col' => last_col,
|
255
|
+
}
|
256
|
+
)
|
257
|
+
if existing_buffer
|
258
|
+
@buffers[ @buffers.index( existing_buffer ) ] = buffer
|
259
|
+
else
|
260
|
+
if @settings['open_as_first_buffer']
|
261
|
+
@buffers.unshift buffer
|
262
|
+
else
|
263
|
+
@buffers << buffer
|
264
|
+
end
|
265
|
+
end
|
266
|
+
run_hook_procs( :after_open, buffer )
|
267
|
+
save_session
|
268
|
+
if switch_to( buffer, do_display: false )
|
269
|
+
if last_row
|
270
|
+
buffer.cursor_to last_row, last_col || 0, Buffer::DONT_DISPLAY
|
271
|
+
end
|
272
|
+
display_buffer buffer
|
273
|
+
end
|
274
|
+
end
|
275
|
+
elsif existing_buffer
|
276
|
+
if switch_to( existing_buffer, do_display: false )
|
277
|
+
if last_row
|
278
|
+
existing_buffer.cursor_to last_row, last_col || 0, Buffer::DONT_DISPLAY
|
279
|
+
end
|
280
|
+
display_buffer existing_buffer
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
buffer || existing_buffer
|
285
|
+
end
|
286
|
+
alias_method :new_file, :open_file
|
287
|
+
|
288
|
+
# Prompts the user for a file to open, then opens it with #open_file .
|
289
|
+
# @see #open_file
|
290
|
+
def open_file_ask
|
291
|
+
prefill = ''
|
292
|
+
|
293
|
+
if buffer_current
|
294
|
+
if buffer_current.current_line =~ %r#(/\w+)+/\w+\.\w+#
|
295
|
+
prefill = $&
|
296
|
+
elsif buffer_current.name
|
297
|
+
prefill = File.expand_path( File.dirname( buffer_current.name ) ) + "/"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
if @settings[ 'fuzzy_file_find' ]
|
302
|
+
prefill = ''
|
303
|
+
finder = FuzzyFileFinder.new(
|
304
|
+
directories: @session.dir,
|
305
|
+
ceiling: @settings['fuzzy_file_find.max_files'] || 8192,
|
306
|
+
ignores: @fuzzy_ignores,
|
307
|
+
recursive: @settings['fuzzy_file_find.recursive']
|
308
|
+
)
|
309
|
+
|
310
|
+
finder_block = lambda { |input|
|
311
|
+
break if input =~ %r{^/}
|
312
|
+
|
313
|
+
matches = finder.find(input).sort_by { |m| m[:path] }
|
314
|
+
with_list_file do |list|
|
315
|
+
list.puts matches.map { |m| m[:path] }
|
316
|
+
end
|
317
|
+
open_list_buffer
|
318
|
+
}
|
319
|
+
end
|
320
|
+
|
321
|
+
file = get_user_input(
|
322
|
+
"Filename: ",
|
323
|
+
history: @rlh_files,
|
324
|
+
initial_text: prefill,
|
325
|
+
&finder_block
|
326
|
+
)
|
327
|
+
|
328
|
+
if file && ! file.empty?
|
329
|
+
open_file file
|
330
|
+
update_status_line
|
331
|
+
update_context_line
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# Opens all files within a directory whose contents match a regular
|
336
|
+
# expression.
|
337
|
+
# @param regexp [String]
|
338
|
+
# The regular expression used to match against. If nil, the user is
|
339
|
+
# prompted for a value.
|
340
|
+
# @param search_root [String]
|
341
|
+
# The directory under which to recursively search for matches. If nil,
|
342
|
+
# the user is prompted for a value.
|
343
|
+
def open_matching_files( regexp = nil, search_root = nil )
|
344
|
+
regexp ||= get_user_input( "Regexp: ", history: @rlh_search )
|
345
|
+
return if regexp.nil?
|
346
|
+
|
347
|
+
if buffer_current.current_line =~ %r{\w*/[/\w.]+}
|
348
|
+
prefill = $&
|
349
|
+
else
|
350
|
+
prefill = File.expand_path( File.dirname( buffer_current.name ) ) + "/"
|
351
|
+
end
|
352
|
+
search_root ||= get_user_input( "Search within: ", history: @rlh_files, initial_text: prefill )
|
353
|
+
return if search_root.nil?
|
354
|
+
|
355
|
+
files = `egrep -rl '#{regexp.gsub( /'/, "'\\\\''" )}' #{search_root}/*`.split( /\n/ )
|
356
|
+
if files.any?
|
357
|
+
if files.size > 5
|
358
|
+
choice = get_choice( "Open #{files.size} files?", [ CHOICE_YES, CHOICE_NO ] )
|
359
|
+
return if choice == CHOICE_NO
|
360
|
+
end
|
361
|
+
files.each do |f|
|
362
|
+
open_file f
|
363
|
+
end
|
364
|
+
find regexp, direction: :down, case_sensitive: true
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
# Places a buffer at a new position in the array of Buffers
|
369
|
+
# after shifting down (index+1) all existing Buffers from that position onwards.
|
370
|
+
# @param to [Integer] The new 1-based position of the buffer to move
|
371
|
+
# @param from [Integer] The original 1-based position of the buffer to move. Default: current buffer
|
372
|
+
def renumber_buffer( to, from = nil )
|
373
|
+
if to < 1
|
374
|
+
raise "Invalid buffer index: #{to.inspect}"
|
375
|
+
end
|
376
|
+
if from && from < 1
|
377
|
+
raise "Invalid buffer index: #{from.inspect}"
|
378
|
+
end
|
379
|
+
|
380
|
+
from ||= buffer_to_number( buffer_current )
|
381
|
+
from_ = from - 1
|
382
|
+
to_ = to - 1
|
383
|
+
b = @buffers[from_]
|
384
|
+
@buffers.delete_at from_
|
385
|
+
@buffers.insert( to_, b )
|
386
|
+
@buffers.compact!
|
387
|
+
|
388
|
+
update_status_line
|
389
|
+
end
|
390
|
+
|
391
|
+
# If the prompt is non-nil, ask the user yes or no question first.
|
392
|
+
def revert( prompt = nil )
|
393
|
+
do_revert = true
|
394
|
+
|
395
|
+
if prompt
|
396
|
+
show_buffer_file_diff do
|
397
|
+
choice = get_choice(
|
398
|
+
prompt,
|
399
|
+
[ CHOICE_YES, CHOICE_NO ]
|
400
|
+
)
|
401
|
+
case choice
|
402
|
+
when CHOICE_NO
|
403
|
+
do_revert = false
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
if do_revert
|
409
|
+
open_file(
|
410
|
+
buffer_current.name,
|
411
|
+
'read_only' => false,
|
412
|
+
'revert' => FORCE_REVERT,
|
413
|
+
'cursor' => {
|
414
|
+
'row' => buffer_current.last_row,
|
415
|
+
'col' => buffer_current.last_col
|
416
|
+
}
|
417
|
+
)
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# Saves a buffer, then runs the :after_save hook on it.
|
422
|
+
# @param [Buffer] buffer
|
423
|
+
# The buffer to save. If nil, defaults to the current buffer.
|
424
|
+
def save_file( buffer = buffer_current )
|
425
|
+
buffer.save
|
426
|
+
run_hook_procs( :after_save, buffer )
|
427
|
+
end
|
428
|
+
|
429
|
+
def save_file_as
|
430
|
+
if buffer_current && buffer_current.name
|
431
|
+
path = File.expand_path( File.dirname( buffer_current.name ) ) + "/"
|
432
|
+
file = get_user_input( "Filename: ", history: @rlh_files, initial_text: path )
|
433
|
+
else
|
434
|
+
file = get_user_input( "Filename: ", history: @rlh_files )
|
435
|
+
end
|
436
|
+
if file
|
437
|
+
old_name = buffer_current.name
|
438
|
+
if buffer_current.save( file, PROMPT_OVERWRITE )
|
439
|
+
save_session
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
# Sets the type (language) of the current buffer.
|
445
|
+
# @param [String] type_
|
446
|
+
# The type to set the current buffer to.
|
447
|
+
# If nil, the user is prompted for a value.
|
448
|
+
def set_buffer_type( type_ = nil )
|
449
|
+
type = type_ || get_user_input( "Content type: " )
|
450
|
+
|
451
|
+
if type
|
452
|
+
if buffer_current.set_type( type )
|
453
|
+
update_status_line
|
454
|
+
update_context_line
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
# If read_only is nil, the read_only state of the current buffer is toggled.
|
460
|
+
# Otherwise, the read_only state of the current buffer is set to read_only.
|
461
|
+
def set_read_only( read_only = nil )
|
462
|
+
if read_only
|
463
|
+
buffer_current.read_only = read_only
|
464
|
+
else
|
465
|
+
buffer_current.read_only = ( ! buffer_current.read_only )
|
466
|
+
end
|
467
|
+
update_status_line
|
468
|
+
end
|
469
|
+
|
470
|
+
def switch_to_buffer_number( buffer_number_ )
|
471
|
+
buffer_number = buffer_number_.to_i
|
472
|
+
return if buffer_number < 1
|
473
|
+
if @buffer_number_last && buffer_number == buffer_to_number(buffer_current)
|
474
|
+
buffer_number = @buffer_number_last
|
475
|
+
end
|
476
|
+
@buffer_number_last = buffer_to_number(buffer_current)
|
477
|
+
switch_to @buffers[ buffer_number - 1 ]
|
478
|
+
end
|
479
|
+
|
480
|
+
def switch_to_next_buffer
|
481
|
+
switch_to_buffer_number( buffer_to_number( buffer_current ) + 1 )
|
482
|
+
end
|
483
|
+
|
484
|
+
def switch_to_previous_buffer
|
485
|
+
switch_to_buffer_number( buffer_to_number( buffer_current ) - 1 )
|
486
|
+
end
|
487
|
+
|
488
|
+
end
|
489
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Diakonos
|
2
|
+
module Functions
|
3
|
+
|
4
|
+
# Copies the currently selected text to clipboard then unselects.
|
5
|
+
def copy_selection
|
6
|
+
@clipboard.add_clip buffer_current.copy_selection
|
7
|
+
remove_selection
|
8
|
+
end
|
9
|
+
|
10
|
+
# Copies the currently selected text to clipboard, then deletes it.
|
11
|
+
def cut_selection
|
12
|
+
if @clipboard.add_clip( buffer_current.copy_selection )
|
13
|
+
delete
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Deletes the current line, and adds it to the clipboard.
|
18
|
+
# If the previous command was also delete_and_store_line,
|
19
|
+
# append the line to the previous clip instead of making
|
20
|
+
# a new clip.
|
21
|
+
def delete_and_store_line
|
22
|
+
removed_text = buffer_current.delete_line
|
23
|
+
if removed_text
|
24
|
+
clip = [ removed_text, "" ]
|
25
|
+
if @functions_last[ -1 ] =~ /^delete_and_store_line/
|
26
|
+
@clipboard.append_to_clip clip
|
27
|
+
else
|
28
|
+
@clipboard.add_clip clip
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Deletes the text from the current cursor position to the end of the line,
|
34
|
+
# then adds the deleted text to the clipboard.
|
35
|
+
def delete_to_eol
|
36
|
+
removed_text = buffer_current.delete_to_eol
|
37
|
+
if removed_text
|
38
|
+
@clipboard.add_clip removed_text
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Pastes the current clipboard item at the current cursor position.
|
43
|
+
def paste
|
44
|
+
buffer_current.paste @clipboard.clip
|
45
|
+
end
|
46
|
+
|
47
|
+
# Opens a new buffer showing a list of all internal clipboard items.
|
48
|
+
# Only for use when no external clipboard is used.
|
49
|
+
def show_clips
|
50
|
+
clip_filename = @diakonos_home + "/clips.txt"
|
51
|
+
File.open( clip_filename, "w" ) do |f|
|
52
|
+
case @settings[ 'clipboard.external' ]
|
53
|
+
when 'klipper'
|
54
|
+
f.puts 'Access Klipper directly (tray icon) to get at all clips.'
|
55
|
+
when 'xclip'
|
56
|
+
f.puts 'xclip does not keep a history of clips.'
|
57
|
+
when 'osx'
|
58
|
+
f.puts 'The OSX clipboard does not keep a history of clips.'
|
59
|
+
else
|
60
|
+
@clipboard.each do |clip|
|
61
|
+
f.puts clip
|
62
|
+
f.puts "---------------------------"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
open_file clip_filename
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|