vimamsa 0.1.7 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ class BufferManager
2
+ attr_reader :buf
3
+ @@cur = nil # Current object of class
4
+
5
+ def self.cur()
6
+ return @@cur
7
+ end
8
+
9
+ def self.init()
10
+ vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
11
+ reg_act(:bmgr_select, proc { buf.module.select_line }, "")
12
+ reg_act(:bmgr_close, proc { buf.module.close_selected }, "")
13
+
14
+ reg_act(:start_buf_manager, proc { BufferManager.new.run; vma.kbd.set_mode(:buf_mgr) }, "Buffer manager")
15
+
16
+ bindkey "bmgr enter", :bmgr_select
17
+ bindkey "bmgr c", :bmgr_close
18
+ end
19
+
20
+ def initialize()
21
+ @buf = nil
22
+ @line_to_id = {}
23
+ end
24
+
25
+ def buf_of_current_line()
26
+ l = @buf.lpos - @header.size
27
+ return nil if l < 0
28
+ bufid = @line_to_id[l]
29
+ buf_i = vma.buffers.get_buffer_by_id(bufid)
30
+ return buf_i
31
+ end
32
+
33
+ def close_selected
34
+ buf_i = buf_of_current_line()
35
+ if buf_i.nil?
36
+ message("buf already closed")
37
+ return
38
+ end
39
+ vma.buffers.close_other_buffer(buf_i)
40
+ end
41
+
42
+ def select_line
43
+ buf_i = buf_of_current_line()
44
+ return if buf_i.nil?
45
+
46
+ vma.buffers.close_current_buffer()
47
+ vma.buffers.set_current_buffer(buf_i)
48
+ @@cur = nil
49
+ end
50
+
51
+ def run
52
+ if !@@cur.nil? #One instance open already
53
+ #Close it
54
+ buf_i = vma.buffers.get_buffer_by_id(@@cur.buf.id)
55
+ vma.buffers.close_buffer(buf_i)
56
+ end
57
+ @@cur = self
58
+ @header = []
59
+ @header << "Current buffers:"
60
+ @header << "keys: <enter> to select, <c> to close buffer"
61
+ @header << "=" * 40
62
+
63
+ s = ""
64
+ s << @header.join("\n")
65
+ s << "\n"
66
+ i = 0
67
+ for b in vma.buffers.sort_by { |x| x.list_str }
68
+ x = b.list_str
69
+ s << "#{x}\n"
70
+ @line_to_id[i] = b.id
71
+ i += 1
72
+ end
73
+
74
+ if @buf.nil?
75
+ @buf = create_new_file(nil, s)
76
+ @buf.module = self
77
+ @buf.active_kbd_mode = :buf_mgr
78
+ else
79
+ @buf.set_content(s)
80
+ end
81
+ @buf.set_line_and_column_pos(@header.size, 0)
82
+ end
83
+ end
@@ -0,0 +1,21 @@
1
+ $cnf = {} # TODO
2
+
3
+ def conf(id)
4
+ return $cnf[id]
5
+ end
6
+
7
+ def set_conf(id, val)
8
+ $cnf[id] = val
9
+ end
10
+
11
+ def setcnf(id, val)
12
+ set_conf(id, val)
13
+ end
14
+
15
+ setcnf :indent_based_on_last_line, true
16
+ setcnf :extensions_to_open, [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".inc", ".php", ".sh", ".m", ".gd", ".js"]
17
+
18
+
19
+ setcnf "log.verbose", 1
20
+ setcnf :tab_width, 4
21
+
data/lib/vimamsa/debug.rb CHANGED
@@ -21,8 +21,9 @@ def debug_dump_deltas()
21
21
  end
22
22
 
23
23
  $log_messages = []
24
- def log_message(message)
25
- puts message
24
+
25
+ def log_message(message,vlevel=1)
26
+ puts message if conf("log.verbose") >= vlevel
26
27
  $log_messages << message
27
28
  end
28
29
 
@@ -80,19 +81,19 @@ end
80
81
 
81
82
  def run_test(test_id)
82
83
  target_results = read_file("", "tests/test_#{test_id}_output.txt")
83
- old_buffer = $buffer
84
- $buffer = Buffer.new("", "")
84
+ old_buffer = vma.buf
85
+ vma.buf = Buffer.new("", "")
85
86
  load "tests/test_#{test_id}.rb"
86
- test_ok = $buffer.to_s.strip == target_results.strip
87
+ test_ok = vma.buf.to_s.strip == target_results.strip
87
88
  puts "##################"
88
89
  puts target_results
89
90
  puts "##################"
90
- puts $buffer.to_s
91
+ puts vma.buf.to_s
91
92
  puts "##################"
92
93
  puts "TEST OK" if test_ok
93
94
  puts "TEST FAILED" if !test_ok
94
95
  puts "##################"
95
- $buffer = old_buffer
96
+ vma.buf = old_buffer
96
97
  end
97
98
 
98
99
  #TODO: remove?
@@ -120,7 +121,7 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
120
121
  # puts buf.current_line()
121
122
  # puts "======================"
122
123
 
123
- render_buffer($buffer)
124
+ render_buffer(vma.buf)
124
125
 
125
126
  gui_sleep(rand() / 2)
126
127
  if rand() < (1 / 40.0)
@@ -129,9 +130,9 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
129
130
 
130
131
  gui_trigger_event
131
132
  buf.insert_txt("X") if rand() > 0.25
132
- render_buffer($buffer)
133
+ render_buffer(vma.buf)
133
134
 
134
- $buffers.set_current_buffer(rand($buffers.size)) if rand > 0.25
135
+ vma.buffers.set_current_buffer(rand(vma.buffers.size)) if rand > 0.25
135
136
  step += 1
136
137
  end
137
138
  end
@@ -9,7 +9,6 @@ class EasyJump
9
9
  end
10
10
 
11
11
  def initialize()
12
- # message "EASY JUMP"
13
12
  visible_range = get_visible_area()
14
13
  visible_text = buf[visible_range[0]..visible_range[1]]
15
14
  wsmarks = scan_word_start_marks(visible_text)
@@ -17,12 +16,24 @@ class EasyJump
17
16
  lsh = Hash[line_starts.collect { |x| [x, true] }]
18
17
  wsmh = Hash[wsmarks.collect { |x| [x, true] }]
19
18
 
19
+ # Exclude work starts that are too close to start of line
20
20
  wsmarks.select! { |x|
21
21
  r = true
22
22
  r = false if lsh[x] or lsh[x - 1] or lsh[x - 2]
23
23
  r
24
24
  }
25
25
 
26
+ # Exclude those word start positions that are too close to each other
27
+ wsmarks.sort!
28
+ wsm2 = [wsmarks[0]]
29
+ for i in 1..(wsmarks.size - 1)
30
+ if (wsmarks[i] - wsm2[-1]) >= 4 or visible_text[wsm2[-1]..wsmarks[i]].include?("\n")
31
+
32
+ wsm2 << wsmarks[i]
33
+ end
34
+ end
35
+ wsmarks = wsm2
36
+
26
37
  linestart_buf = (line_starts).collect { |x| x + visible_range[0] }
27
38
  wsmarks_buf = (wsmarks).collect { |x| x + visible_range[0] }
28
39
 
@@ -41,12 +52,12 @@ class EasyJump
41
52
  def easy_jump_input_char(c, event_type)
42
53
  return true if event_type != :key_press
43
54
  # vma.paint_stack = []
44
- puts "EASY JUMP: easy_jump_input_char [#{c}]"
55
+ debug "EASY JUMP: easy_jump_input_char [#{c}]"
45
56
  @easy_jump_input << c.upcase
46
57
  if @jump_sequence.include?(@easy_jump_input)
47
58
  jshash = Hash[@jump_sequence.map.with_index.to_a]
48
59
  nthword = jshash[@easy_jump_input]
49
- puts "nthword:#{nthword} #{[@easy_jump_wsmarks[nthword], @jump_sequence[nthword]]}"
60
+ debug "nthword:#{nthword} #{[@easy_jump_wsmarks[nthword], @jump_sequence[nthword]]}"
50
61
  buf.set_pos(@easy_jump_wsmarks[nthword])
51
62
  # @kbd.set_mode(:command)
52
63
  vma.kbd.remove_keyhandling_override
@@ -63,25 +74,11 @@ class EasyJump
63
74
  end
64
75
 
65
76
  def easy_jump_draw()
66
- # puts @jump_sequence.inspect
67
- # puts @easy_jump_wsmarks.inspect
68
77
  vma.gui.start_overlay_draw
69
78
  for i in 0..(@easy_jump_wsmarks.size - 1)
70
- vma.gui.overlay_draw_text(@jump_sequence[i], @easy_jump_wsmarks[i])
79
+ vma.gui.overlay_draw_text(@jump_sequence[i], @easy_jump_wsmarks[i])
71
80
  end
72
81
  vma.gui.end_overlay_draw
73
-
74
- return
75
- return if @jump_sequence.empty?
76
- puts "EASY JUMP DRAW"
77
- screen_cord = cpp_function_wrapper(0, [@easy_jump_wsmarks])
78
- screen_cord = screen_cord[1..@jump_sequence.size]
79
- screen_cord.each_with_index { |point, i|
80
- mark_str = @jump_sequence[i]
81
- #puts "draw #{point[0]}x#{point[1]}"
82
- draw_text(mark_str, point[0] + 3, point[1])
83
- #break if m > @cpos
84
- }
85
82
  end
86
83
 
87
84
  def make_jump_sequence(num_items)
@@ -158,8 +155,6 @@ class EasyJump
158
155
  }
159
156
  }
160
157
 
161
- #printf("Size of sequence: %d\n",sequence.size)
162
- #puts sequence.inspect
163
158
  return sequence
164
159
  end
165
160
  end
@@ -1,11 +1,11 @@
1
1
  require "pty"
2
2
 
3
3
  def exec_in_terminal(cmd, autoclose = false)
4
- # puts "CMD:#{cmd}"
4
+ # debug "CMD:#{cmd}"
5
5
 
6
6
  # global to prevent garbage collect unlink
7
7
  $initf = Tempfile.new("bashinit")
8
- # puts $initf.path
8
+ # debug $initf.path
9
9
  $initf.write(cmd)
10
10
  if autoclose
11
11
  $initf.write("\nsleep 10; exit;\n")
@@ -37,7 +37,7 @@ class Editor
37
37
  #attr_writer :call_func, :update_highlight
38
38
 
39
39
  def initialize()
40
- # Thread.new{10000.times{|x|sleep(3);10000.times{|y|y+2};puts "FOOTHREAD #{x}"}}
40
+ # Thread.new{10000.times{|x|sleep(3);10000.times{|y|y+2};debug "FOOTHREAD #{x}"}}
41
41
 
42
42
  # Search for content inside files (e.g. using ack/grep) in:
43
43
  @file_content_search_paths = []
@@ -70,13 +70,6 @@ class Editor
70
70
  end
71
71
 
72
72
  def start
73
- # $highlight = {}
74
-
75
- # GLib::Idle.add
76
- # Ripl.start :binding => binding
77
- # GLib::Idle.add(proc{ puts "IDLEFUNC"})
78
- # GLib::Idle.add(proc { idle_func })
79
-
80
73
  @gui = $vmag #TODO
81
74
 
82
75
  $hook = Hook.new
@@ -95,28 +88,39 @@ class Editor
95
88
  # build_key_bindings_tree
96
89
  @kbd = KeyBindingTree.new()
97
90
  $kbd = @kbd
98
- $kbd.add_mode("C", :command)
99
- $kbd.add_mode("I", :insert)
100
- $kbd.add_mode("V", :visual)
101
- $kbd.add_mode("M", :minibuffer)
102
- $kbd.add_mode("R", :readchar)
103
- $kbd.add_mode("B", :browse)
104
- $kbd.set_default_mode(:command)
91
+ @kbd.add_mode("C", :command)
92
+ @kbd.add_mode("I", :insert)
93
+ @kbd.add_mode("V", :visual)
94
+ @kbd.add_mode("M", :minibuffer)
95
+ @kbd.add_mode("R", :readchar)
96
+ @kbd.add_mode("B", :browse)
97
+ @kbd.set_default_mode(:command)
98
+ @kbd.set_mode(:command)
99
+ @kbd.show_state_trail
105
100
  require "vimamsa/key_bindings_vimlike"
106
101
  sleep(0.03)
107
102
 
108
103
  FileManager.init
104
+ BufferManager.init
109
105
 
110
106
  mkdir_if_not_exists("~/.vimamsa")
111
107
  mkdir_if_not_exists("~/.vimamsa/backup")
112
108
  mkdir_if_not_exists("~/.vimamsa/listen")
113
109
  listen_dir = File.expand_path "~/.vimamsa/listen"
114
110
  listener = Listen.to(listen_dir) do |modified, added, removed|
115
- puts(modified: modified, added: added, removed: removed)
111
+ debug([modified: modified, added: added, removed: removed])
116
112
  open_file_listener(added)
117
113
  end
118
114
  listener.start
119
115
 
116
+ custom_fn = File.expand_path("~/.vimamsa/custom.rb")
117
+ if !File.exist?(custom_fn)
118
+ example_custom = IO.read(ppath("custom_example.rb"))
119
+ IO.write(custom_fn, example_custom)
120
+ end
121
+
122
+ mkdir_if_not_exists("~/.vimamsa/custom.rb")
123
+
120
124
  $cnf[:theme] = "Twilight_edit"
121
125
  $cnf[:syntax_highlight] = true
122
126
  settings_path = get_dot_path("settings.rb")
@@ -131,6 +135,9 @@ class Editor
131
135
 
132
136
  dotfile = read_file("", "~/.vimamsarc")
133
137
  eval(dotfile) if dotfile
138
+
139
+ custom_script = read_file("", custom_fn)
140
+ eval(custom_script) if custom_script
134
141
 
135
142
  # build_options
136
143
 
@@ -140,6 +147,8 @@ class Editor
140
147
  if File.exist?(fname_)
141
148
  fname = fname_
142
149
  end
150
+ else
151
+ fname = ppath("demo.txt")
143
152
  end
144
153
  fname = ARGV[0] if ARGV.size >= 1 and File.file?(File.expand_path(ARGV[0]))
145
154
  # vma.add_content_search_path(Dir.pwd)
@@ -156,11 +165,11 @@ class Editor
156
165
  else
157
166
  buffer = Buffer.new(" \n")
158
167
  end
159
- $buffers << buffer
168
+ vma.buffers << buffer
160
169
 
161
170
  # load_theme($cnf[:theme])
162
171
 
163
- # render_buffer($buffer, 1) #TODO
172
+ # render_buffer(vma.buf, 1) #TODO
164
173
 
165
174
  # gui_select_buffer_init #TODO
166
175
  # gui_file_finder_init #TODO
@@ -188,6 +197,14 @@ class Editor
188
197
  def buf()
189
198
  return $buffer
190
199
  end
200
+ def buf=(aa)
201
+ $buffer=aa
202
+ end
203
+
204
+
205
+ def buffers()
206
+ return $buffers
207
+ end
191
208
 
192
209
  def marshal_save(varname, vardata)
193
210
  save_var_to_file(varname, Marshal.dump(vardata))
@@ -243,20 +260,25 @@ class Editor
243
260
  # Register converter
244
261
  def reg_conv(converter, converter_id)
245
262
  @converters[converter_id] = converter
246
- reg_act(converter_id, proc { $buffer.convert_selected_text(converter_id) }, "Converter #{converter_id}", { :scope => [:selection] })
263
+ reg_act(converter_id, proc { vma.buf.convert_selected_text(converter_id) }, "Converter #{converter_id}", { :scope => [:selection] })
247
264
  end
248
265
 
249
266
  def apply_conv(converter_id, txt)
250
267
  @converters[converter_id].apply(txt)
251
268
  end
252
269
 
270
+ # Used only by ack module at the moment
253
271
  def get_content_search_paths()
254
272
  r = @file_content_search_paths.clone
255
273
  p = find_project_dir_of_cur_buffer()
274
+ if p.nil?
275
+ p = vma.buffers.last_dir
276
+ end
256
277
 
257
278
  if p and !@file_content_search_paths.include?(p)
258
279
  r.insert(0, p)
259
280
  end
281
+
260
282
  return r
261
283
  end
262
284
 
@@ -264,7 +286,7 @@ class Editor
264
286
  exts = $cnf[:extensions_to_open]
265
287
  extname = Pathname.new(filepath).extname.downcase
266
288
  can_open = exts.include?(extname)
267
- puts "CAN OPEN?: #{can_open}"
289
+ debug "CAN OPEN?: #{can_open}"
268
290
  return can_open
269
291
  end
270
292
  end
@@ -275,7 +297,7 @@ def _quit()
275
297
  end
276
298
 
277
299
  def fatal_error(msg)
278
- puts msg
300
+ debug msg
279
301
  exit!
280
302
  end
281
303
 
@@ -285,7 +307,7 @@ end
285
307
 
286
308
  def open_file_dialog()
287
309
  path = ""
288
- path = $buffer.fname if $buffer.fname
310
+ path = vma.buf.fname if vma.buf.fname
289
311
  gui_open_file_dialog(File.dirname(path))
290
312
  end
291
313
 
@@ -296,7 +318,7 @@ def system_clipboard_changed(clipboard_contents)
296
318
  $paste_lines = false
297
319
  end
298
320
  $clipboard << clipboard_contents
299
- # puts $clipboard[-1]
321
+ # debug $clipboard[-1]
300
322
  $clipboard = $clipboard[-([$clipboard.size, max_clipboard_items].min)..-1]
301
323
  end
302
324
 
@@ -306,10 +328,10 @@ end
306
328
 
307
329
  def set_clipboard(s)
308
330
  if !(s.class <= String) or s.size == 0
309
- puts s.inspect
310
- puts [s, s.class, s.size]
331
+ debug s.inspect
332
+ debug [s, s.class, s.size]
311
333
  log_error("s.class != String or s.size == 0")
312
- Ripl.start :binding => binding
334
+ # Ripl.start :binding => binding
313
335
  return
314
336
  end
315
337
  $clipboard << s
@@ -321,8 +343,8 @@ end
321
343
 
322
344
  def set_cursor_pos(new_pos)
323
345
  buf.set_pos(new_pos)
324
- #render_buffer($buffer)
325
- debug "New pos: #{new_pos}lpos:#{$buffer.lpos} cpos:#{$buffer.cpos}"
346
+ #render_buffer(vma.buf)
347
+ debug "New pos: #{new_pos}lpos:#{vma.buf.lpos} cpos:#{vma.buf.cpos}"
326
348
  end
327
349
 
328
350
  def set_last_command(cmd)
@@ -343,7 +365,7 @@ end
343
365
 
344
366
  def repeat_last_find()
345
367
  return if !defined? $last_find_command
346
- $buffer.jump_to_next_instance_of_char($last_find_command[:char],
368
+ vma.buf.jump_to_next_instance_of_char($last_find_command[:char],
347
369
  $last_find_command[:direction])
348
370
  end
349
371
 
@@ -364,23 +386,30 @@ end
364
386
 
365
387
  def show_key_bindings()
366
388
  kbd_s = "❙Key bindings❙\n"
367
- kbd_s << "=======================================\n"
389
+ kbd_s << "\n⦁[Mode] keys : action⦁\n"
390
+
391
+ kbd_s << "[B]=Browse, [C]=Command, [I]=Insert, [V]=Visual\n"
392
+ kbd_s << "key!: Press key once, release before pressing any other keys\n"
393
+
394
+ kbd_s << "===============================================\n"
368
395
  kbd_s << $kbd.to_s
369
- kbd_s << "\n=======================================\n"
370
- create_new_file(nil, kbd_s)
396
+ kbd_s << "===============================================\n"
397
+ b = create_new_file(nil, kbd_s)
398
+ gui_set_file_lang(b.id, "hyperplaintext")
399
+ #
371
400
  end
372
401
 
373
402
  def diff_buffer()
374
403
  bufstr = ""
375
- orig_path = $buffer.fname
404
+ orig_path = vma.buf.fname
376
405
  infile = Tempfile.new("out")
377
406
  infile = Tempfile.new("in")
378
- infile.write($buffer.to_s)
407
+ infile.write(vma.buf.to_s)
379
408
  infile.flush
380
409
  cmd = "diff -w '#{orig_path}' #{infile.path}"
381
- # puts cmd
410
+ # debug cmd
382
411
  bufstr << run_cmd(cmd)
383
- # puts bufstr
412
+ # debug bufstr
384
413
  infile.close; infile.unlink
385
414
  create_new_file(nil, bufstr)
386
415
  end
@@ -421,7 +450,7 @@ def minibuffer_new_char(c)
421
450
  $minibuffer.insert_txt(c)
422
451
  debug "MINIBUFFER: #{c}"
423
452
  end
424
- #$buffer = $minibuffer
453
+ #vma.buf = $minibuffer
425
454
  end
426
455
 
427
456
  # def readchar_new_char(c)
@@ -434,7 +463,7 @@ end
434
463
 
435
464
  def message(s)
436
465
  s = "[#{DateTime.now().strftime("%H:%M")}] #{s}"
437
- puts s
466
+ debug s
438
467
 
439
468
  $vmag.add_to_minibuf(s)
440
469
  # $minibuffer = Buffer.new(s, "")
@@ -445,6 +474,7 @@ end
445
474
  GUESS_ENCODING_ORDER = [
446
475
  Encoding::US_ASCII,
447
476
  Encoding::UTF_8,
477
+ Encoding::ISO_8859_1,
448
478
  Encoding::Shift_JIS,
449
479
  Encoding::EUC_JP,
450
480
  Encoding::EucJP_ms,
@@ -473,7 +503,8 @@ def create_new_file(filename = nil, file_contents = "\n")
473
503
  debug "NEW FILE CREATED"
474
504
  buffer = Buffer.new(file_contents)
475
505
  # gui_set_current_buffer(buffer.id) #TODO: remove?
476
- $buffers << buffer
506
+ vma.buffers << buffer
507
+ vma.kbd.set_mode_to_default
477
508
  return buffer
478
509
  end
479
510
 
@@ -491,7 +522,7 @@ end
491
522
 
492
523
  def load_buffer(fname)
493
524
  return if !File.exist?(fname)
494
- existing_buffer = $buffers.get_buffer_by_filename(fname)
525
+ existing_buffer = vma.buffers.get_buffer_by_filename(fname)
495
526
  if existing_buffer != nil
496
527
  $buffer_history << existing_buffer
497
528
  return
@@ -503,15 +534,27 @@ def load_buffer(fname)
503
534
  debug("DONE LOAD: #{fname}")
504
535
  #buf = filter_buffer(buffer)
505
536
  # debug("END FILTER: #{fname}")
506
- $buffers << buffer
507
- #$buffer_history << $buffers.size - 1
537
+ vma.buffers << buffer
538
+ #$buffer_history << vma.buffers.size - 1
508
539
  end
509
540
 
510
- def jump_to_file(filename, linenum = 0)
541
+ def jump_to_file(filename, linenum = nil, charn = nil)
511
542
  open_new_file(filename)
512
- if linenum > 0
513
- $buffer.jump_to_line(linenum)
543
+
544
+ # Link to character position
545
+ if !charn.nil?
546
+ if charn == "c"
547
+ buf.jump_to_pos(linenum)
548
+ center_on_current_line
549
+ return
550
+ end
551
+ end
552
+
553
+ # Link to line
554
+ if !linenum.nil?
555
+ buf.jump_to_line(linenum)
514
556
  center_on_current_line
557
+ return
515
558
  end
516
559
  end
517
560
 
@@ -523,11 +566,11 @@ end
523
566
  def open_new_file(filename, file_contents = "")
524
567
  #TODO: expand path
525
568
  filename = File.expand_path(filename)
526
- b = $buffers.get_buffer_by_filename(filename)
569
+ b = vma.buffers.get_buffer_by_filename(filename)
527
570
  # File is already opened to existing buffer
528
571
  if b != nil
529
572
  message "Switching to: #{filename}"
530
- $buffers.set_current_buffer(b)
573
+ vma.buffers.set_current_buffer(b)
531
574
  else
532
575
  message "New file opened: #{filename}"
533
576
  fname = filename
@@ -541,39 +584,11 @@ def scan_word_start_marks(search_str)
541
584
  return wsmarks
542
585
  end
543
586
 
544
- def draw_text(str, x, y)
545
- vma.paint_stack << [4, x, y, str]
546
- end
547
-
548
587
  def hook_draw()
549
588
  # TODO: as hook.register
550
589
  # easy_jump_draw()
551
590
  end
552
591
 
553
- def render_buffer(buffer = 0, reset = 0)
554
- tmpbuf = $buffer.to_s
555
- debug "pos:#{$buffer.pos} L:#{$buffer.lpos} C:#{$buffer.cpos}"
556
- pos = $buffer.pos
557
- selection_start = $buffer.selection_start
558
-
559
- if $buffer.need_redraw?
560
- reset = 1
561
- end
562
- t1 = Time.now
563
- hook_draw()
564
-
565
- if $buffer.need_redraw?
566
- hpt_scan_images() if $debug #experimental
567
- end
568
-
569
- $buffer.highlight
570
- if Time.now - t1 > 1 / 100.0
571
- debug "SLOW render"
572
- debug "Render time: #{Time.now - t1}"
573
- end
574
- $buffer.set_redrawed if reset == 1
575
- end
576
-
577
592
  def get_dot_path(sfx)
578
593
  dot_dir = File.expand_path("~/.vimamsa")
579
594
  Dir.mkdir(dot_dir) unless File.exist?(dot_dir)
@@ -584,10 +599,10 @@ end
584
599
  def get_file_line_pointer(s)
585
600
  #"/code/vimamsa/lib/vimamsa/buffer_select.rb:31:def"
586
601
  # m = s.match(/(~[a-z]*)?\/.*\//)
587
- m = s.match(/((~[a-z]*)?\/.*\/\S+):(\d+)/)
602
+ m = s.match(/((~[a-z]*)?\/.*\/\S+):(c?)(\d+)/)
588
603
  if m != nil
589
604
  if File.exist?(File.expand_path(m[1]))
590
- return [m[1], m[3].to_i]
605
+ return [m[1], m[4].to_i, m[3]]
591
606
  end
592
607
  end
593
608
  return nil
@@ -604,7 +619,7 @@ end
604
619
  def run_cmd(cmd)
605
620
  tmpf = Tempfile.new("vmarun", "/tmp").path
606
621
  cmd = "#{cmd} > #{tmpf}"
607
- puts "CMD:\n#{cmd}"
622
+ debug "CMD:\n#{cmd}"
608
623
  system("bash", "-c", cmd)
609
624
  res_str = File.read(tmpf)
610
625
  return res_str
@@ -633,11 +648,11 @@ def exec_cmd(bin_name, arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil, arg5 = ni
633
648
  end
634
649
 
635
650
  def file_is_text_file(fpath)
636
- puts "file_is_text_file(#{fpath})"
651
+ debug "file_is_text_file(#{fpath})"
637
652
  fpath = File.expand_path(fpath)
638
653
  return false if !File.exist?(fpath)
639
654
  r = exec_cmd("file", fpath)
640
- puts "DEBUG:#{r}"
655
+ debug "DEBUG:#{r}"
641
656
  return true if r.match(/UTF-8.*text/)
642
657
  return true if r.match(/ASCII.*text/)
643
658
  return false
@@ -670,9 +685,9 @@ end
670
685
  def find_project_dir_of_cur_buffer()
671
686
  # Find "project dir" of current file. If currently editing file in path "/foo/bar/baz/fn.txt" and file named "/foo/bar/.vma_project" exists, then dir /foo/bar is treated as project dir and subject to e.g. ack search.
672
687
  pdir = nil
673
- if $buffer.fname
674
- pdir = find_project_dir_of_fn($buffer.fname)
688
+ if vma.buf.fname
689
+ pdir = find_project_dir_of_fn(vma.buf.fname)
675
690
  end
676
- # puts "Proj dir of current file: #{pdir}"
691
+ # debug "Proj dir of current file: #{pdir}"
677
692
  return pdir
678
693
  end
@@ -33,15 +33,15 @@ class Encrypt
33
33
  end
34
34
 
35
35
  def decrypt_cur_buffer(password, b = nil)
36
- $buffer.decrypt(password)
36
+ vma.buf.decrypt(password)
37
37
  end
38
38
 
39
39
  def encrypt_cur_buffer()
40
40
  callback = proc{|x|encrypt_cur_buffer_callback(x)}
41
- gui_one_input_action("Encrypt", "Password:", "Encrypt", callback)
41
+ gui_one_input_action("Encrypt", "Password:", "Encrypt", callback,{:hide=>true})
42
42
  end
43
43
 
44
44
  def encrypt_cur_buffer_callback(password,b=nil)
45
- $buffer.set_encrypted(password)
45
+ vma.buf.set_encrypted(password)
46
46
  end
47
47