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
20 21 22 23 |
# File 'lib/vimamsa/buffer_manager.rb', line 20 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 |
# 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 end |
Instance Method Details
#buf_of_current_line ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/vimamsa/buffer_manager.rb', line 25 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
33 34 35 36 37 38 39 40 |
# File 'lib/vimamsa/buffer_manager.rb', line 33 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
51 52 53 54 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 |
# File 'lib/vimamsa/buffer_manager.rb', line 51 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" @header << "=" * 40 s = "" s << @header.join("\n") s << "\n" i = 0 for b in vma.buffers.sort_by { |x| x.list_str } x = b.list_str s << "#{x}\n" @line_to_id[i] = b.id i += 1 end if @buf.nil? @buf = create_new_file(nil, s) @buf.module = self @buf.active_kbd_mode = :buf_mgr else @buf.set_content(s) end @buf.set_line_and_column_pos(@header.size, 0) end |
#select_line ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/vimamsa/buffer_manager.rb', line 42 def select_line buf_i = buf_of_current_line() return if buf_i.nil? vma.buffers.close_current_buffer() vma.buffers.set_current_buffer(buf_i) @@cur = nil end |