diakonos 0.8.11 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +439 -0
  3. data/LICENCE.md +675 -0
  4. data/bin/diakonos +6 -0
  5. data/diakonos-256-colour.conf +220 -0
  6. data/diakonos.conf +1802 -0
  7. data/help/about-help.dhf +31 -0
  8. data/help/clipboard.dhf +45 -0
  9. data/help/close-file.dhf +6 -0
  10. data/help/code-block-navigation.dhf +16 -0
  11. data/help/column-markers.dhf +15 -0
  12. data/help/config.dhf +69 -0
  13. data/help/cursor-stack.dhf +19 -0
  14. data/help/delete.dhf +41 -0
  15. data/help/extensions.dhf +125 -0
  16. data/help/file-type.dhf +24 -0
  17. data/help/key-mapping.dhf +127 -0
  18. data/help/line-numbers.dhf +22 -0
  19. data/help/macros.dhf +27 -0
  20. data/help/new-file.dhf +6 -0
  21. data/help/open-file.dhf +21 -0
  22. data/help/quit.dhf +7 -0
  23. data/help/resizing.dhf +19 -0
  24. data/help/ruby.dhf +17 -0
  25. data/help/save-file.dhf +10 -0
  26. data/help/scripting.dhf +92 -0
  27. data/help/search.dhf +103 -0
  28. data/help/shell.dhf +60 -0
  29. data/help/speed.dhf +23 -0
  30. data/help/support.dhf +15 -0
  31. data/help/switch-buffers.dhf +15 -0
  32. data/help/tabs.dhf +36 -0
  33. data/help/undo.dhf +9 -0
  34. data/help/uninstall.dhf +18 -0
  35. data/help/welcome.dhf +32 -0
  36. data/help/word-wrap.dhf +17 -0
  37. data/lib/diakonos/about.rb +70 -0
  38. data/lib/diakonos/bookmark.rb +46 -0
  39. data/lib/diakonos/buffer/bookmarking.rb +47 -0
  40. data/lib/diakonos/buffer/cursor.rb +335 -0
  41. data/lib/diakonos/buffer/delete.rb +170 -0
  42. data/lib/diakonos/buffer/display.rb +362 -0
  43. data/lib/diakonos/buffer/file.rb +157 -0
  44. data/lib/diakonos/buffer/indentation.rb +175 -0
  45. data/lib/diakonos/buffer/searching.rb +552 -0
  46. data/lib/diakonos/buffer/selection.rb +360 -0
  47. data/lib/diakonos/buffer/undo.rb +73 -0
  48. data/lib/diakonos/buffer-hash.rb +60 -0
  49. data/lib/diakonos/buffer-management.rb +59 -0
  50. data/lib/diakonos/buffer.rb +698 -0
  51. data/lib/diakonos/clipboard-klipper-dbus.rb +62 -0
  52. data/lib/diakonos/clipboard-klipper.rb +62 -0
  53. data/lib/diakonos/clipboard-osx.rb +59 -0
  54. data/lib/diakonos/clipboard-xclip.rb +60 -0
  55. data/lib/diakonos/clipboard.rb +47 -0
  56. data/lib/diakonos/config-file.rb +67 -0
  57. data/lib/diakonos/config.rb +382 -0
  58. data/lib/diakonos/core-ext/enumerable.rb +15 -0
  59. data/lib/diakonos/core-ext/hash.rb +60 -0
  60. data/lib/diakonos/core-ext/object.rb +6 -0
  61. data/lib/diakonos/core-ext/regexp.rb +6 -0
  62. data/lib/diakonos/core-ext/string.rb +122 -0
  63. data/lib/diakonos/ctag.rb +28 -0
  64. data/lib/diakonos/cursor.rb +27 -0
  65. data/lib/diakonos/display/format.rb +75 -0
  66. data/lib/diakonos/display.rb +336 -0
  67. data/lib/diakonos/extension-set.rb +49 -0
  68. data/lib/diakonos/extension.rb +34 -0
  69. data/lib/diakonos/finding.rb +40 -0
  70. data/lib/diakonos/functions/basics.rb +34 -0
  71. data/lib/diakonos/functions/bookmarking.rb +61 -0
  72. data/lib/diakonos/functions/buffers.rb +491 -0
  73. data/lib/diakonos/functions/clipboard.rb +70 -0
  74. data/lib/diakonos/functions/cursor.rb +264 -0
  75. data/lib/diakonos/functions/grepping.rb +83 -0
  76. data/lib/diakonos/functions/indentation.rb +71 -0
  77. data/lib/diakonos/functions/readline.rb +93 -0
  78. data/lib/diakonos/functions/search.rb +179 -0
  79. data/lib/diakonos/functions/selection.rb +98 -0
  80. data/lib/diakonos/functions/sessions.rb +78 -0
  81. data/lib/diakonos/functions/shell.rb +250 -0
  82. data/lib/diakonos/functions/tags.rb +65 -0
  83. data/lib/diakonos/functions/text-manipulation.rb +196 -0
  84. data/lib/diakonos/functions-deprecated.rb +77 -0
  85. data/lib/diakonos/functions.rb +292 -0
  86. data/lib/diakonos/grep.rb +98 -0
  87. data/lib/diakonos/help.rb +47 -0
  88. data/lib/diakonos/hooks.rb +13 -0
  89. data/lib/diakonos/installation.rb +19 -0
  90. data/lib/diakonos/interaction-handler.rb +216 -0
  91. data/lib/diakonos/interaction.rb +52 -0
  92. data/lib/diakonos/key-map.rb +62 -0
  93. data/lib/diakonos/keying.rb +442 -0
  94. data/lib/diakonos/line-mover.rb +42 -0
  95. data/lib/diakonos/list.rb +59 -0
  96. data/lib/diakonos/logging.rb +27 -0
  97. data/lib/diakonos/mode.rb +17 -0
  98. data/lib/diakonos/mouse.rb +18 -0
  99. data/lib/diakonos/number-fitter.rb +11 -0
  100. data/lib/diakonos/range.rb +31 -0
  101. data/lib/diakonos/readline/functions.rb +82 -0
  102. data/lib/diakonos/readline.rb +223 -0
  103. data/lib/diakonos/search.rb +58 -0
  104. data/lib/diakonos/sessions.rb +257 -0
  105. data/lib/diakonos/sized-array.rb +48 -0
  106. data/lib/diakonos/text-mark.rb +19 -0
  107. data/lib/diakonos/vendor/fuzzy_file_finder.rb +386 -0
  108. data/lib/diakonos/version.rb +25 -0
  109. data/lib/diakonos/window.rb +43 -0
  110. data/lib/diakonos.rb +592 -0
  111. metadata +160 -68
@@ -0,0 +1,491 @@
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
+ # TODO: Maybe a bug here, re: paths relative to session dir (external file find)
188
+ existing_buffer = @buffers.find { |b| b.name == filename }
189
+ end
190
+
191
+ if filename
192
+ if existing_buffer
193
+ do_open = force_revert || ( filename =~ /\.diakonos/ )
194
+ switch_to existing_buffer, do_display: false
195
+
196
+ if ! do_open && existing_buffer.file_different?
197
+ show_buffer_file_diff( existing_buffer ) do
198
+ choice = get_choice(
199
+ "Load on-disk version of #{existing_buffer.nice_name}?",
200
+ [ CHOICE_YES, CHOICE_NO ]
201
+ )
202
+ case choice
203
+ when CHOICE_YES
204
+ do_open = true
205
+ when CHOICE_NO
206
+ do_open = false
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ if FileTest.exist?( filename )
213
+ # Don't try to open non-files (i.e. directories, pipes, sockets, etc.)
214
+ do_open &&= FileTest.file?( filename )
215
+ end
216
+ end
217
+ end
218
+
219
+ if do_open
220
+ # Is file readable?
221
+
222
+ # Does the "file" utility exist?
223
+ if(
224
+ filename &&
225
+ @settings[ 'use_magic_file' ] &&
226
+ FileTest.exist?( "/usr/bin/file" ) &&
227
+ FileTest.exist?( filename ) &&
228
+ /\blisting\.txt\b/ !~ filename
229
+ )
230
+ file_type = `/usr/bin/file -L #{filename}`
231
+ if file_type !~ /text/ && file_type !~ /empty$/
232
+ choice = get_choice(
233
+ "#{filename} does not appear to be readable. Try to open it anyway?",
234
+ [ CHOICE_YES, CHOICE_NO ],
235
+ CHOICE_NO
236
+ )
237
+ case choice
238
+ when CHOICE_NO
239
+ do_open = false
240
+ end
241
+
242
+ end
243
+ end
244
+
245
+ if do_open
246
+ buffer = Buffer.new(
247
+ 'filepath' => filename,
248
+ 'read_only' => read_only,
249
+ 'display' => {
250
+ 'top_line' => top_line,
251
+ 'left_column' => left_column,
252
+ },
253
+ 'cursor' => {
254
+ 'row' => last_row,
255
+ 'col' => last_col,
256
+ }
257
+ )
258
+ if existing_buffer
259
+ @buffers[ @buffers.index( existing_buffer ) ] = buffer
260
+ else
261
+ if @settings['open_as_first_buffer']
262
+ @buffers.unshift buffer
263
+ else
264
+ @buffers << buffer
265
+ end
266
+ end
267
+ run_hook_procs( :after_open, buffer )
268
+ save_session
269
+ if switch_to( buffer, do_display: false )
270
+ if last_row
271
+ buffer.cursor_to last_row, last_col || 0, Buffer::DONT_DISPLAY
272
+ end
273
+ display_buffer buffer
274
+ end
275
+ end
276
+ elsif existing_buffer
277
+ if switch_to( existing_buffer, do_display: false )
278
+ if last_row
279
+ existing_buffer.cursor_to last_row, last_col || 0, Buffer::DONT_DISPLAY
280
+ end
281
+ display_buffer existing_buffer
282
+ end
283
+ end
284
+
285
+ buffer || existing_buffer
286
+ end
287
+ alias_method :new_file, :open_file
288
+
289
+ # Prompts the user for a file to open, then opens it with #open_file .
290
+ # @see #open_file
291
+ def open_file_ask
292
+ prefill = ''
293
+
294
+ if buffer_current
295
+ if buffer_current.current_line =~ %r#(/\w+)+/\w+\.\w+#
296
+ prefill = $&
297
+ elsif buffer_current.name
298
+ prefill = File.expand_path( File.dirname( buffer_current.name ) ) + "/"
299
+ end
300
+ end
301
+
302
+ if @settings[ 'fuzzy_file_find' ]
303
+ prefill = ''
304
+ finder = FuzzyFileFinder.new(
305
+ directories: @session.dir,
306
+ ceiling: @settings['fuzzy_file_find.max_files'] || 8192,
307
+ ignores: @fuzzy_ignores,
308
+ recursive: @settings['fuzzy_file_find.recursive'],
309
+ sorted: true
310
+ )
311
+
312
+ finder_block = lambda { |input|
313
+ break if input =~ %r{^/}
314
+
315
+ matches = finder.find(input)
316
+ with_list_file do |list|
317
+ list.puts matches.map { |m| m[:path] }
318
+ end
319
+ open_list_buffer
320
+ }
321
+ end
322
+
323
+ file = get_user_input(
324
+ "Filename: ",
325
+ history: @rlh_files,
326
+ initial_text: prefill,
327
+ &finder_block
328
+ )
329
+
330
+ if file && ! file.empty?
331
+ open_file file
332
+ update_status_line
333
+ update_context_line
334
+ end
335
+ end
336
+
337
+ # Opens all files within a directory whose contents match a regular
338
+ # expression.
339
+ # @param regexp [String]
340
+ # The regular expression used to match against. If nil, the user is
341
+ # prompted for a value.
342
+ # @param search_root [String]
343
+ # The directory under which to recursively search for matches. If nil,
344
+ # the user is prompted for a value.
345
+ def open_matching_files( regexp = nil, search_root = nil )
346
+ regexp ||= get_user_input( "Regexp: ", history: @rlh_search )
347
+ return if regexp.nil?
348
+
349
+ if buffer_current.current_line =~ %r{\w*/[/\w.]+}
350
+ prefill = $&
351
+ else
352
+ prefill = File.expand_path( File.dirname( buffer_current.name ) ) + "/"
353
+ end
354
+ search_root ||= get_user_input( "Search within: ", history: @rlh_files, initial_text: prefill )
355
+ return if search_root.nil?
356
+
357
+ files = `egrep -rl '#{regexp.gsub( /'/, "'\\\\''" )}' #{search_root}/*`.split( /\n/ )
358
+ if files.any?
359
+ if files.size > 5
360
+ choice = get_choice( "Open #{files.size} files?", [ CHOICE_YES, CHOICE_NO ] )
361
+ return if choice == CHOICE_NO
362
+ end
363
+ files.each do |f|
364
+ open_file f
365
+ end
366
+ find regexp, direction: :down, case_sensitive: true
367
+ end
368
+ end
369
+
370
+ # Places a buffer at a new position in the array of Buffers
371
+ # after shifting down (index+1) all existing Buffers from that position onwards.
372
+ # @param to [Integer] The new 1-based position of the buffer to move
373
+ # @param from [Integer] The original 1-based position of the buffer to move. Default: current buffer
374
+ def renumber_buffer( to, from = nil )
375
+ if to < 1
376
+ raise "Invalid buffer index: #{to.inspect}"
377
+ end
378
+ if from && from < 1
379
+ raise "Invalid buffer index: #{from.inspect}"
380
+ end
381
+
382
+ from ||= buffer_to_number( buffer_current )
383
+ from_ = from - 1
384
+ to_ = to - 1
385
+ b = @buffers[from_]
386
+ @buffers.delete_at from_
387
+ @buffers.insert( to_, b )
388
+ @buffers.compact!
389
+
390
+ update_status_line
391
+ end
392
+
393
+ # If the prompt is non-nil, ask the user yes or no question first.
394
+ def revert( prompt = nil )
395
+ do_revert = true
396
+
397
+ if prompt
398
+ show_buffer_file_diff do
399
+ choice = get_choice(
400
+ prompt,
401
+ [ CHOICE_YES, CHOICE_NO ]
402
+ )
403
+ case choice
404
+ when CHOICE_NO
405
+ do_revert = false
406
+ end
407
+ end
408
+ end
409
+
410
+ if do_revert
411
+ open_file(
412
+ buffer_current.name,
413
+ 'read_only' => false,
414
+ 'revert' => FORCE_REVERT,
415
+ 'cursor' => {
416
+ 'row' => buffer_current.last_row,
417
+ 'col' => buffer_current.last_col
418
+ }
419
+ )
420
+ end
421
+ end
422
+
423
+ # Saves a buffer, then runs the :after_save hook on it.
424
+ # @param [Buffer] buffer
425
+ # The buffer to save. If nil, defaults to the current buffer.
426
+ def save_file( buffer = buffer_current )
427
+ buffer.save
428
+ run_hook_procs( :after_save, buffer )
429
+ end
430
+
431
+ def save_file_as
432
+ if buffer_current && buffer_current.name
433
+ path = File.expand_path( File.dirname( buffer_current.name ) ) + "/"
434
+ file = get_user_input( "Filename: ", history: @rlh_files, initial_text: path )
435
+ else
436
+ file = get_user_input( "Filename: ", history: @rlh_files )
437
+ end
438
+ if file
439
+ old_name = buffer_current.name
440
+ if buffer_current.save( file, PROMPT_OVERWRITE )
441
+ save_session
442
+ end
443
+ end
444
+ end
445
+
446
+ # Sets the type (language) of the current buffer.
447
+ # @param [String] type_
448
+ # The type to set the current buffer to.
449
+ # If nil, the user is prompted for a value.
450
+ def set_buffer_type( type_ = nil )
451
+ type = type_ || get_user_input( "Content type: " )
452
+
453
+ if type
454
+ if buffer_current.set_type( type )
455
+ update_status_line
456
+ update_context_line
457
+ end
458
+ end
459
+ end
460
+
461
+ # If read_only is nil, the read_only state of the current buffer is toggled.
462
+ # Otherwise, the read_only state of the current buffer is set to read_only.
463
+ def set_read_only( read_only = nil )
464
+ if read_only
465
+ buffer_current.read_only = read_only
466
+ else
467
+ buffer_current.read_only = ( ! buffer_current.read_only )
468
+ end
469
+ update_status_line
470
+ end
471
+
472
+ def switch_to_buffer_number( buffer_number_ )
473
+ buffer_number = buffer_number_.to_i
474
+ return if buffer_number < 1
475
+ if @buffer_number_last && buffer_number == buffer_to_number(buffer_current)
476
+ buffer_number = @buffer_number_last
477
+ end
478
+ @buffer_number_last = buffer_to_number(buffer_current)
479
+ switch_to @buffers[ buffer_number - 1 ]
480
+ end
481
+
482
+ def switch_to_next_buffer
483
+ switch_to_buffer_number( buffer_to_number( buffer_current ) + 1 )
484
+ end
485
+
486
+ def switch_to_previous_buffer
487
+ switch_to_buffer_number( buffer_to_number( buffer_current ) - 1 )
488
+ end
489
+
490
+ end
491
+ 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