diakonos 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. metadata +38 -59
  2. data/CHANGELOG +0 -238
  3. data/LICENCE +0 -21
  4. data/README +0 -75
  5. data/bin/diakonos +0 -6
  6. data/diakonos-256-colour.conf +0 -102
  7. data/diakonos.conf +0 -1233
  8. data/lib/diakonos.rb +0 -618
  9. data/lib/diakonos/array.rb +0 -15
  10. data/lib/diakonos/bignum.rb +0 -9
  11. data/lib/diakonos/bookmark.rb +0 -50
  12. data/lib/diakonos/buffer-hash.rb +0 -60
  13. data/lib/diakonos/buffer-management.rb +0 -73
  14. data/lib/diakonos/buffer.rb +0 -2044
  15. data/lib/diakonos/clipboard.rb +0 -47
  16. data/lib/diakonos/config.rb +0 -304
  17. data/lib/diakonos/ctag.rb +0 -28
  18. data/lib/diakonos/display.rb +0 -288
  19. data/lib/diakonos/enumerable.rb +0 -15
  20. data/lib/diakonos/finding.rb +0 -32
  21. data/lib/diakonos/fixnum.rb +0 -17
  22. data/lib/diakonos/functions.rb +0 -1420
  23. data/lib/diakonos/grep.rb +0 -78
  24. data/lib/diakonos/hash.rb +0 -108
  25. data/lib/diakonos/help.rb +0 -92
  26. data/lib/diakonos/hooks.rb +0 -13
  27. data/lib/diakonos/interaction.rb +0 -139
  28. data/lib/diakonos/keycode.rb +0 -110
  29. data/lib/diakonos/keying.rb +0 -124
  30. data/lib/diakonos/list.rb +0 -55
  31. data/lib/diakonos/logging.rb +0 -24
  32. data/lib/diakonos/object.rb +0 -6
  33. data/lib/diakonos/readline.rb +0 -274
  34. data/lib/diakonos/regexp.rb +0 -6
  35. data/lib/diakonos/sessions.rb +0 -70
  36. data/lib/diakonos/sized-array.rb +0 -48
  37. data/lib/diakonos/string.rb +0 -326
  38. data/lib/diakonos/text-mark.rb +0 -19
  39. data/lib/diakonos/vendor/fuzzy_file_finder.rb +0 -353
  40. data/lib/diakonos/window.rb +0 -32
  41. data/test/buffer-test.rb +0 -53
  42. data/test/clipboard-test.rb +0 -70
  43. data/test/diakonos-test.rb +0 -14
  44. data/test/hash-test.rb +0 -404
  45. data/test/regexp-test.rb +0 -26
  46. data/test/sizedarray-test.rb +0 -113
  47. data/test/string-test.rb +0 -160
@@ -1,618 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # == Diakonos
4
- #
5
- # A usable console text editor.
6
- # :title: Diakonos
7
- #
8
- # Author:: Pistos (irc.freenode.net)
9
- # http://purepistos.net/diakonos
10
- # Copyright (c) 2004-2009 Pistos
11
- #
12
- # This software is released under the MIT licence.
13
- # See the LICENCE file included with this program, or
14
- # http://www.opensource.org/licenses/mit-license.php
15
- #
16
- require 'curses'
17
- require 'open3'
18
- require 'thread'
19
- require 'English'
20
- require 'set'
21
- require 'yaml'
22
- require 'digest/md5'
23
-
24
- require 'diakonos/object'
25
- require 'diakonos/enumerable'
26
- require 'diakonos/regexp'
27
- require 'diakonos/sized-array'
28
- require 'diakonos/hash'
29
- require 'diakonos/buffer-hash'
30
- require 'diakonos/array'
31
- require 'diakonos/string'
32
- require 'diakonos/fixnum'
33
- require 'diakonos/bignum'
34
-
35
- require 'diakonos/config'
36
- require 'diakonos/functions'
37
- require 'diakonos/help'
38
- require 'diakonos/display'
39
- require 'diakonos/interaction'
40
- require 'diakonos/hooks'
41
- require 'diakonos/keying'
42
- require 'diakonos/logging'
43
- require 'diakonos/list'
44
- require 'diakonos/buffer-management'
45
- require 'diakonos/sessions'
46
- require 'diakonos/grep'
47
-
48
- require 'diakonos/keycode'
49
- require 'diakonos/text-mark'
50
- require 'diakonos/bookmark'
51
- require 'diakonos/ctag'
52
- require 'diakonos/finding'
53
- require 'diakonos/buffer'
54
- require 'diakonos/window'
55
- require 'diakonos/clipboard'
56
- require 'diakonos/readline'
57
-
58
- require 'diakonos/vendor/fuzzy_file_finder'
59
-
60
- #$profiling = true
61
-
62
- #if $profiling
63
- #require 'ruby-prof'
64
- #end
65
-
66
- module Diakonos
67
-
68
- VERSION = '0.8.7'
69
- LAST_MODIFIED = 'February 20, 2009'
70
-
71
- DONT_ADJUST_ROW = false
72
- ADJUST_ROW = true
73
- PROMPT_OVERWRITE = true
74
- DONT_PROMPT_OVERWRITE = false
75
- QUIET = true
76
- NOISY = false
77
-
78
- DEFAULT_TAB_SIZE = 8
79
-
80
- FORCE_REVERT = true
81
- ASK_REVERT = false
82
-
83
- ASK_REPLACEMENT = true
84
-
85
- CASE_SENSITIVE = true
86
- CASE_INSENSITIVE = false
87
-
88
- LANG_TEXT = 'text'
89
-
90
- NUM_LAST_COMMANDS = 2
91
-
92
- class Diakonos
93
-
94
- attr_reader :diakonos_home, :script_dir, :clipboard,
95
- :list_filename, :hooks, :indenters, :unindenters, :closers,
96
- :last_commands, :there_was_non_movement, :do_display
97
-
98
- include ::Diakonos::Functions
99
-
100
- def initialize( argv = [] )
101
- @diakonos_home = ( ( ENV[ 'HOME' ] or '' ) + '/.diakonos' ).subHome
102
- mkdir @diakonos_home
103
- @script_dir = "#{@diakonos_home}/scripts"
104
- mkdir @script_dir
105
- @session_dir = "#{@diakonos_home}/sessions"
106
- mkdir @session_dir
107
- new_session "#{@session_dir}/#{Process.pid}"
108
-
109
- @files = Array.new
110
- @read_only_files = Array.new
111
- @config_filename = nil
112
- parseOptions argv
113
-
114
- init_help
115
-
116
- @debug = File.new( "#{@diakonos_home}/debug.log", 'w' )
117
- @list_filename = @diakonos_home + '/listing.txt'
118
- @diff_filename = @diakonos_home + '/text.diff'
119
- @help_filename = "#{@help_dir}/about-help.dhf"
120
- @error_filename = "#{@diakonos_home}/diakonos.err"
121
-
122
- @win_main = nil
123
- @win_context = nil
124
- @win_status = nil
125
- @win_interaction = nil
126
- @buffers = BufferHash.new
127
-
128
- loadConfiguration
129
-
130
- @quitting = false
131
- @untitled_id = 0
132
-
133
- @x = 0
134
- @y = 0
135
-
136
- @buffer_stack = Array.new
137
- @current_buffer = nil
138
- @buffer_history = Array.new
139
- @buffer_history_pointer = nil
140
- @bookmarks = Hash.new
141
- @macro_history = nil
142
- @macro_input_history = nil
143
- @macros = Hash.new
144
- @last_commands = SizedArray.new( NUM_LAST_COMMANDS )
145
- @playing_macro = false
146
- @display_mutex = Mutex.new
147
- @display_queue_mutex = Mutex.new
148
- @display_queue = nil
149
- @do_display = true
150
- @iline_mutex = Mutex.new
151
- @tag_stack = Array.new
152
- @last_search_regexps = nil
153
- @iterated_choice = nil
154
- @choice_iterations = 0
155
- @there_was_non_movement = false
156
- @status_vars = Hash.new
157
-
158
- # Readline histories
159
- @rlh_general = Array.new
160
- @rlh_files = Array.new
161
- @rlh_search = Array.new
162
- @rlh_shell = Array.new
163
- @rlh_help = Array.new
164
- @rlh_sessions = Array.new
165
-
166
- @hooks = {
167
- :after_buffer_switch => [],
168
- :after_open => [],
169
- :after_save => [],
170
- :after_startup => [],
171
- }
172
- end
173
-
174
- def mkdir( dir )
175
- if not FileTest.exists? dir
176
- Dir.mkdir dir
177
- end
178
- end
179
-
180
- def parseOptions( argv )
181
- @post_load_script = ""
182
- while argv.length > 0
183
- arg = argv.shift
184
- case arg
185
- when '-c', '--config'
186
- @config_filename = argv.shift
187
- if @config_filename.nil?
188
- printUsage
189
- exit 1
190
- end
191
- when '-e', '--execute'
192
- post_load_script = argv.shift
193
- if post_load_script.nil?
194
- printUsage
195
- exit 1
196
- else
197
- @post_load_script << "\n#{post_load_script}"
198
- end
199
- when '-h', '--help'
200
- printUsage
201
- exit 1
202
- when '-m', '--open-matching'
203
- regexp = argv.shift
204
- files = `egrep -rl '#{regexp}' *`.split( /\n/ )
205
- if files.any?
206
- @files.concat files
207
- script = "\nfind 'down', CASE_SENSITIVE, '#{regexp}'"
208
- @post_load_script << script
209
- end
210
- when '-ro'
211
- filename = argv.shift
212
- if filename.nil?
213
- printUsage
214
- exit 1
215
- else
216
- @read_only_files.push filename
217
- end
218
- when '-s', '--load-session'
219
- @session_to_load = session_filepath_for( argv.shift )
220
- when '--test', '--testing'
221
- @testing = true
222
- else
223
- # a name of a file to open
224
- @files.push arg
225
- end
226
- end
227
- end
228
- protected :parseOptions
229
-
230
- def printUsage
231
- puts "Usage: #{$0} [options] [file] [file...]"
232
- puts "\t--help\tDisplay usage"
233
- puts "\t-c <config file>\tLoad this config file instead of ~/.diakonos/diakonos.conf"
234
- puts "\t-e, --execute <Ruby code>\tExecute Ruby code (such as Diakonos commands) after startup"
235
- puts "\t-m, --open-matching <regular expression>\tOpen all matching files under current directory"
236
- puts "\t-ro <file>\tLoad file as read-only"
237
- puts "\t-s, --load-session <session identifier>\tLoad a session"
238
- end
239
- protected :printUsage
240
-
241
- def clearNonMovementFlag
242
- @there_was_non_movement = false
243
- end
244
-
245
- # -----------------------------------------------------------------------
246
-
247
- def start
248
- initializeDisplay
249
-
250
- if ENV[ 'COLORTERM' ] == 'gnome-terminal'
251
- help_key = 'Shift-F1'
252
- else
253
- help_key = 'F1'
254
- end
255
- setILine "Diakonos #{VERSION} (#{LAST_MODIFIED}) #{help_key} for help F12 to configure Ctrl-Q to quit"
256
-
257
- if @session_to_load
258
- pid_session = @session
259
- @session = nil
260
- session_path = session_filepath_for( @session_to_load )
261
- load_session_data session_path
262
- if @session
263
- @files.concat @session[ 'files' ]
264
- else
265
- new_session session_path
266
- end
267
- else
268
- session_buffers = []
269
-
270
- session_files = Dir[ "#{@session_dir}/*" ].grep( %r{/\d+$} )
271
- pids = session_files.map { |sf| sf[ %r{/(\d+)$}, 1 ].to_i }
272
- pids.each do |pid|
273
- begin
274
- Process.kill 0, pid
275
- session_files.reject! { |sf| pid_session? sf }
276
- rescue Errno::ESRCH, Errno::EPERM
277
- # Process is no longer alive, so we consider the session stale
278
- end
279
- end
280
-
281
- session_files.each_with_index do |session_file,index|
282
- session_buffers << openFile( session_file )
283
-
284
- choice = getChoice(
285
- "#{session_files.size} unclosed session(s) found. Open the above files? (session #{index+1} of #{session_files.size})",
286
- [ CHOICE_YES, CHOICE_NO, CHOICE_DELETE ]
287
- )
288
-
289
- case choice
290
- when CHOICE_YES
291
- load_session_data session_file
292
- if @session
293
- @files.concat @session[ 'files' ]
294
- File.delete session_file
295
- break
296
- end
297
- when CHOICE_DELETE
298
- File.delete session_file
299
- end
300
- end
301
-
302
- if session_buffers.empty? and @files.empty? and @settings[ 'session.default_session' ]
303
- session_file = session_filepath_for( @settings[ 'session.default_session' ] )
304
- if File.exist? session_file
305
- load_session_data session_file
306
- if @session
307
- @files.concat @session[ 'files' ]
308
- end
309
- end
310
- end
311
- end
312
-
313
- Dir[ "#{@script_dir}/*" ].each do |script|
314
- begin
315
- require script
316
- rescue Exception => e
317
- showException(
318
- e,
319
- [
320
- "There is a syntax error in the script.",
321
- "An invalid hook name was used."
322
- ]
323
- )
324
- end
325
- end
326
- @hooks.each do |hook_name, hook|
327
- hook.sort { |a,b| a[ :priority ] <=> b[ :priority ] }
328
- end
329
-
330
- num_opened = 0
331
- if @files.length == 0 and @read_only_files.length == 0
332
- num_opened += 1 if openFile
333
- else
334
- @files.each do |file|
335
- num_opened += 1 if openFile file
336
- end
337
- @read_only_files.each do |file|
338
- num_opened += 1 if openFile( file, Buffer::READ_ONLY )
339
- end
340
- end
341
-
342
- if session_buffers
343
- session_buffers.each do |buffer|
344
- closeFile buffer
345
- end
346
- end
347
-
348
- if num_opened > 0
349
- switchToBufferNumber 1
350
-
351
- updateStatusLine
352
- updateContextLine
353
-
354
- if @post_load_script
355
- eval @post_load_script
356
- end
357
-
358
- runHookProcs :after_startup
359
-
360
- if not @settings[ 'suppress_welcome' ]
361
- openFile "#{@help_dir}/welcome.dhf"
362
- end
363
-
364
- begin
365
- # Main keyboard loop.
366
- while not @quitting
367
- processKeystroke
368
- @win_main.refresh
369
- end
370
- rescue SignalException => e
371
- debugLog "Terminated by signal (#{e.message})"
372
- end
373
-
374
- if pid_session?
375
- File.delete @session[ 'filename' ]
376
- end
377
-
378
- @debug.close
379
- end
380
- end
381
-
382
- def showClips
383
- clip_filename = @diakonos_home + "/clips.txt"
384
- File.open( clip_filename, "w" ) do |f|
385
- @clipboard.each do |clip|
386
- f.puts clip
387
- f.puts "---------------------------"
388
- end
389
- end
390
- openFile clip_filename
391
- end
392
-
393
- def getLanguageFromName( name )
394
- retval = nil
395
- @filemasks.each do |language,filemask|
396
- if name =~ filemask
397
- retval = language
398
- break
399
- end
400
- end
401
- retval
402
- end
403
-
404
- def getLanguageFromShaBang( first_line )
405
- retval = nil
406
- @bangmasks.each do |language,bangmask|
407
- if first_line =~ bangmask
408
- retval = language
409
- break
410
- end
411
- end
412
- retval
413
- end
414
-
415
- def showException( e, probable_causes = [ "Unknown" ] )
416
- begin
417
- File.open( @error_filename, "w" ) do |f|
418
- f.puts "Diakonos Error:"
419
- f.puts
420
- f.puts "#{e.class}: #{e.message}"
421
- f.puts
422
- f.puts "Probable Causes:"
423
- f.puts
424
- probable_causes.each do |pc|
425
- f.puts "- #{pc}"
426
- end
427
- f.puts
428
- f.puts "----------------------------------------------------"
429
- f.puts "If you can reproduce this error, please report it at"
430
- f.puts "http://linis.purepistos.net/ticket/list/Diakonos !"
431
- f.puts "----------------------------------------------------"
432
- f.puts e.backtrace
433
- end
434
- openFile( @error_filename )
435
- rescue Exception => e2
436
- debugLog "EXCEPTION: #{e.message}"
437
- debugLog "\t#{e.backtrace}"
438
- end
439
- end
440
-
441
- def subShellVariables( string )
442
- return nil if string.nil?
443
-
444
- retval = string
445
- retval = retval.subHome
446
-
447
- # Current buffer filename
448
- retval.gsub!( /\$f/, ( $1 or "" ) + ( @current_buffer.name or "" ) )
449
-
450
- # space-separated list of all buffer filenames
451
- name_array = Array.new
452
- @buffers.each_value do |b|
453
- name_array.push b.name
454
- end
455
- retval.gsub!( /\$F/, ( $1 or "" ) + ( name_array.join(' ') or "" ) )
456
-
457
- # Get user input, sub it in
458
- if retval =~ /\$i/
459
- user_input = getUserInput( "Argument: ", @rlh_shell )
460
- retval.gsub!( /\$i/, user_input )
461
- end
462
-
463
- # Current clipboard text
464
- if retval =~ /\$c/
465
- clip_filename = @diakonos_home + "/clip.txt"
466
- File.open( clip_filename, "w" ) do |clipfile|
467
- if @clipboard.clip
468
- clipfile.puts( @clipboard.clip.join( "\n" ) )
469
- end
470
- end
471
- retval.gsub!( /\$c/, clip_filename )
472
- end
473
-
474
- # Current klipper (KDE clipboard) text
475
- if retval =~ /\$k/
476
- clip_filename = @diakonos_home + "/clip.txt"
477
- File.open( clip_filename, "w" ) do |clipfile|
478
- clipfile.puts( `dcop klipper klipper getClipboardContents` )
479
- end
480
- retval.gsub!( /\$k/, clip_filename )
481
- end
482
-
483
- # Currently selected text
484
- if retval =~ /\$s/
485
- text_filename = @diakonos_home + "/selected.txt"
486
-
487
- File.open( text_filename, "w" ) do |textfile|
488
- selected_text = @current_buffer.selected_text
489
- if selected_text
490
- textfile.puts( selected_text.join( "\n" ) )
491
- end
492
- end
493
- retval.gsub!( /\$s/, text_filename )
494
- end
495
-
496
- retval
497
- end
498
-
499
- def startRecordingMacro( name = nil )
500
- return if @macro_history
501
- @macro_name = name
502
- @macro_history = Array.new
503
- @macro_input_history = Array.new
504
- setILine "Started macro recording."
505
- end
506
- protected :startRecordingMacro
507
-
508
- def stopRecordingMacro
509
- @macro_history.pop # Remove the stopRecordingMacro command itself
510
- @macros[ @macro_name ] = [ @macro_history, @macro_input_history ]
511
- @macro_history = nil
512
- @macro_input_history = nil
513
- setILine "Stopped macro recording."
514
- end
515
- protected :stopRecordingMacro
516
-
517
- def loadTags
518
- @tags = Hash.new
519
- if @current_buffer and @current_buffer.name
520
- path = File.expand_path( File.dirname( @current_buffer.name ) )
521
- tagfile = path + "/tags"
522
- else
523
- tagfile = "./tags"
524
- end
525
- if FileTest.exists? tagfile
526
- IO.foreach( tagfile ) do |line_|
527
- line = line_.chomp
528
- # <tagname>\t<filepath>\t<line number or regexp>\t<kind of tag>
529
- tag, file, command, kind, rest = line.split( /\t/ )
530
- command.gsub!( /;"$/, "" )
531
- if command =~ /^\/.*\/$/
532
- command = command[ 1...-1 ]
533
- end
534
- @tags[ tag ] ||= Array.new
535
- @tags[ tag ].push CTag.new( file, command, kind, rest )
536
- end
537
- else
538
- setILine "(tags file not found)"
539
- end
540
- end
541
-
542
- def write_to_clip_file( text )
543
- clip_filename = @diakonos_home + "/clip.txt"
544
- File.open( clip_filename, "w" ) do |f|
545
- f.print text
546
- end
547
- clip_filename
548
- end
549
-
550
- # Returns true iff some text was copied to klipper.
551
- def send_to_klipper( text )
552
- return false if text.nil?
553
-
554
- clip_filename = write_to_clip_file( text.join( "\n" ) )
555
- # A little shell sorcery to ensure the shell doesn't strip off trailing newlines.
556
- # Thank you to pgas from irc.freenode.net#bash for help with this.
557
- `clipping=$(cat #{clip_filename};printf "_"); dcop klipper klipper setClipboardContents "${clipping%_}"`
558
- true
559
- end
560
-
561
- # Worker method for find function.
562
- def find_( direction, case_sensitive, regexp_source, replacement, starting_row, starting_col, quiet )
563
- return if( regexp_source.nil? or regexp_source.empty? )
564
-
565
- rs_array = regexp_source.newlineSplit
566
- regexps = Array.new
567
- exception_thrown = nil
568
-
569
- rs_array.each do |source|
570
- begin
571
- warning_verbosity = $VERBOSE
572
- $VERBOSE = nil
573
- regexps << Regexp.new(
574
- source,
575
- case_sensitive ? nil : Regexp::IGNORECASE
576
- )
577
- $VERBOSE = warning_verbosity
578
- rescue RegexpError => e
579
- if not exception_thrown
580
- exception_thrown = e
581
- source = Regexp.escape( source )
582
- retry
583
- else
584
- raise e
585
- end
586
- end
587
- end
588
-
589
- if replacement == ASK_REPLACEMENT
590
- replacement = getUserInput( "Replace with: ", @rlh_search )
591
- end
592
-
593
- if exception_thrown and not quiet
594
- setILine( "Searching literally; #{exception_thrown.message}" )
595
- end
596
-
597
- @current_buffer.find(
598
- regexps,
599
- :direction => direction,
600
- :replacement => replacement,
601
- :starting_row => starting_row,
602
- :starting_col => starting_col,
603
- :quiet => quiet
604
- )
605
- @last_search_regexps = regexps
606
- end
607
-
608
- def settings
609
- @settings.merge @session[ 'settings' ]
610
- end
611
- end
612
-
613
- end
614
-
615
- if __FILE__ == $PROGRAM_NAME
616
- $diakonos = Diakonos::Diakonos.new( ARGV )
617
- $diakonos.start
618
- end