Module: CommandT::MRU

Defined in:
lib/command-t/mru.rb

Overview

Maintains a stack of seen buffer numbers in MRU (most recently used) order.

Class Method Summary collapse

Class Method Details

.buffersObject

All buffer numbers in the stack, returned as a set for fast membership lookup.



17
18
19
# File 'lib/command-t/mru.rb', line 17

def buffers
  Set.new(@stack)
end

.deleteObject

Mark a buffer as deleted, removing it from the stack.



39
40
41
42
43
44
# File 'lib/command-t/mru.rb', line 39

def delete
  # Note that $curbuf does not point to the buffer that is being deleted;
  # we need to use Vim's <abuf> for the correct buffer number.
  current = ::VIM::evaluate('expand("<abuf>")').to_i
  stack.delete_if { |number| number == current }
end

.lastObject

The (last) most recent buffer number in the stack, if any.



22
23
24
# File 'lib/command-t/mru.rb', line 22

def last
  stack.last
end

.stackObject

The stack of used buffer numbers in MRU order.



11
12
13
# File 'lib/command-t/mru.rb', line 11

def stack
  @stack ||= []
end

.touchObject

Mark the current buffer as having been used, effectively moving it to the top of the stack. Has no effect on unlisted buffers or buffers without names.



29
30
31
32
33
34
35
36
# File 'lib/command-t/mru.rb', line 29

def touch
  number = $curbuf.number
  return unless ::VIM::evaluate('buflisted(%d)' % number) == 1
  return unless $curbuf.name

  stack.delete number
  stack.push number
end