Module: CommandT::MRU

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

Overview

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

Class Method Summary collapse

Class Method Details

.deleteObject

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



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

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.
  stack.delete_if do |b|
    b.number == ::VIM::evaluate('expand("<abuf>")').to_i
  end
end

.lastObject

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



14
15
16
# File 'lib/command-t/mru.rb', line 14

def last
  stack.last
end

.stackObject

The stack of used buffers in MRU order.



9
10
11
# File 'lib/command-t/mru.rb', line 9

def stack
  @stack ||= []
end

.touchObject

Mark the current buffer as having been used, effectively moving it to the top of the stack.



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

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

  stack.delete $curbuf
  stack.push $curbuf
end

.used?(buffer) ⇒ Boolean

Returns ‘true` if `buffer` has been used (ie. is present in the stack).

Returns:

  • (Boolean)


38
39
40
# File 'lib/command-t/mru.rb', line 38

def used?(buffer)
  stack.include?(buffer)
end