Class: Amun::Buffer

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/amun/buffer.rb

Overview

A buffer could present any kind of IO object (File, StringIO…etc) also it has a major mode responsible update lines and visual lines

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Object

#events

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, io = StringIO.new) ⇒ Buffer

Returns a new instance of Buffer.



14
15
16
17
18
19
20
21
22
# File 'lib/amun/buffer.rb', line 14

def initialize(name, io = StringIO.new)
  super()
  self.io = io
  self.name = name
  self.point = 0
  self.text = ''
  self.major_mode = MajorModes::Fundamental.new(self)
  self.minor_modes = Set.new
end

Class Attribute Details

.currentObject



82
83
84
# File 'lib/amun/buffer.rb', line 82

def current
  @current ||= scratch
end

.instancesObject



78
79
80
# File 'lib/amun/buffer.rb', line 78

def instances
  @instances ||= Set.new
end

Instance Attribute Details

#ioObject

Returns the value of attribute io.



12
13
14
# File 'lib/amun/buffer.rb', line 12

def io
  @io
end

#major_modeObject

Returns the value of attribute major_mode.



12
13
14
# File 'lib/amun/buffer.rb', line 12

def major_mode
  @major_mode
end

#markObject



32
33
34
35
36
37
# File 'lib/amun/buffer.rb', line 32

def mark
  return nil if @mark.nil?
  return 0 if @mark.negative?
  return length if @mark > length
  @mark
end

#minor_modesObject

Returns the value of attribute minor_modes.



12
13
14
# File 'lib/amun/buffer.rb', line 12

def minor_modes
  @minor_modes
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/amun/buffer.rb', line 12

def name
  @name
end

#pointObject



25
26
27
28
29
# File 'lib/amun/buffer.rb', line 25

def point
  return 0 if @point.negative?
  return length if @point > length
  @point
end

Class Method Details

.messagesObject



92
93
94
95
96
# File 'lib/amun/buffer.rb', line 92

def messages
  @messages ||= new('*Messages*')
  instances << @messages
  @messages
end

.scratchObject



86
87
88
89
90
# File 'lib/amun/buffer.rb', line 86

def scratch
  @scratch ||= new('*Scratch*')
  instances << @scratch
  @scratch
end

Instance Method Details

#<<(p1) ⇒ Object



63
64
65
# File 'lib/amun/buffer.rb', line 63

def <<(p1)
  insert(length, p1)
end

#clearObject



67
68
69
# File 'lib/amun/buffer.rb', line 67

def clear
  slice!(0, length)
end

#insert(index, other_str) ⇒ Object



55
56
57
# File 'lib/amun/buffer.rb', line 55

def insert(index, other_str)
  text.insert(index, other_str)
end

#slice!(start, length = 1) ⇒ Object



59
60
61
# File 'lib/amun/buffer.rb', line 59

def slice!(start, length = 1)
  text.slice!(start, length)
end

#to_sObject



71
72
73
# File 'lib/amun/buffer.rb', line 71

def to_s
  text.dup
end

#trigger(event) ⇒ Object



39
40
41
42
43
44
# File 'lib/amun/buffer.rb', line 39

def trigger(event)
  EventManager.join(
    event,
    *([events] + minor_modes.to_a + [major_mode])
  )
end