Class: BufferManager
- Inherits:
-
Object
- Object
- BufferManager
- Defined in:
- lib/vimamsa/buffer_manager.rb
Constant Summary collapse
- @@cur =
Current object of class
nil
Instance Attribute Summary collapse
-
#buf ⇒ Object
readonly
Returns the value of attribute buf.
Class Method Summary collapse
Instance Method Summary collapse
- #buf_of_current_line ⇒ Object
- #close_selected ⇒ Object
-
#initialize ⇒ BufferManager
constructor
A new instance of BufferManager.
- #run ⇒ Object
- #select_line ⇒ Object
Constructor Details
#initialize ⇒ BufferManager
Returns a new instance of BufferManager.
21 22 23 24 |
# File 'lib/vimamsa/buffer_manager.rb', line 21 def initialize() @buf = nil @line_to_id = {} end |
Instance Attribute Details
#buf ⇒ Object (readonly)
Returns the value of attribute buf.
2 3 4 |
# File 'lib/vimamsa/buffer_manager.rb', line 2 def buf @buf end |
Class Method Details
.cur ⇒ Object
5 6 7 |
# File 'lib/vimamsa/buffer_manager.rb', line 5 def self.cur() return @@cur end |
.init ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vimamsa/buffer_manager.rb', line 9 def self.init() vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command) reg_act(:bmgr_select, proc { buf.module.select_line }, "") reg_act(:bmgr_close, proc { buf.module.close_selected }, "") reg_act(:start_buf_manager, proc { BufferManager.new.run; vma.kbd.set_mode(:buf_mgr) }, "Buffer manager") bindkey "bmgr enter", :bmgr_select bindkey "bmgr c", :bmgr_close bindkey "bmgr x", :close_current_buffer end |
Instance Method Details
#buf_of_current_line ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/vimamsa/buffer_manager.rb', line 26 def buf_of_current_line() l = @buf.lpos - @header.size return nil if l < 0 bufid = @line_to_id[l] buf_i = vma.buffers.get_buffer_by_id(bufid) return buf_i end |
#close_selected ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/vimamsa/buffer_manager.rb', line 34 def close_selected buf_i = buf_of_current_line() if buf_i.nil? ("buf already closed") return end vma.buffers.close_other_buffer(buf_i) end |
#run ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/vimamsa/buffer_manager.rb', line 55 def run if !@@cur.nil? #One instance open already #Close it buf_i = vma.buffers.get_buffer_by_id(@@cur.buf.id) vma.buffers.close_buffer(buf_i) end @@cur = self @header = [] @header << "Current buffers:" @header << "keys: <enter> to select, <c> to close buffer, <x> exit" @header << "=" * 40 s = "" s << @header.join("\n") s << "\n" i = 0 jump_to_line = 0 for b in vma.buffers.sort_by { |x| x.list_str } if b.id == vma.buf.id # current file # s << " " jump_to_line = i end x = b.list_str s << "#{x}\n" @line_to_id[i] = b.id i += 1 end if @buf.nil? @buf = create_new_buffer(s,"bufmgr") @buf.module = self @buf.active_kbd_mode = :buf_mgr else @buf.set_content(s) end # Position on the line of the active buffer # @buf.set_content(s) newlpos = @header.size + jump_to_line @buf.set_line_and_column_pos(newlpos, 0) # Thread.new{sleep 0.1; center_on_current_line()} # TODO end |
#select_line ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vimamsa/buffer_manager.rb', line 43 def select_line buf_i = buf_of_current_line() return if buf_i.nil? # vma.buffers.close_current_buffer() #TODO:?? vma.buffers.set_current_buffer(buf_i) bid = vma.buffers.get_buffer_by_id(@buf.id) vma.buffers.close_other_buffer(bid) @@cur = nil end |