Class: Amun::Buffer
- 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
-
#io ⇒ Object
Returns the value of attribute io.
-
#major_mode ⇒ Object
Returns the value of attribute major_mode.
- #mark ⇒ Object
-
#minor_modes ⇒ Object
Returns the value of attribute minor_modes.
-
#name ⇒ Object
Returns the value of attribute name.
- #point ⇒ Object
Attributes inherited from Object
Class Method Summary collapse
Instance Method Summary collapse
- #<<(p1) ⇒ Object
- #clear ⇒ Object
-
#initialize(name, io = StringIO.new) ⇒ Buffer
constructor
A new instance of Buffer.
- #insert(index, other_str) ⇒ Object
- #slice!(start, length = 1) ⇒ Object
- #to_s ⇒ Object
- #trigger(event) ⇒ Object
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
.current ⇒ Object
82 83 84 |
# File 'lib/amun/buffer.rb', line 82 def current @current ||= scratch end |
.instances ⇒ Object
78 79 80 |
# File 'lib/amun/buffer.rb', line 78 def instances @instances ||= Set.new end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
12 13 14 |
# File 'lib/amun/buffer.rb', line 12 def io @io end |
#major_mode ⇒ Object
Returns the value of attribute major_mode.
12 13 14 |
# File 'lib/amun/buffer.rb', line 12 def major_mode @major_mode end |
#mark ⇒ Object
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_modes ⇒ Object
Returns the value of attribute minor_modes.
12 13 14 |
# File 'lib/amun/buffer.rb', line 12 def minor_modes @minor_modes end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/amun/buffer.rb', line 12 def name @name end |
#point ⇒ Object
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
.messages ⇒ Object
92 93 94 95 96 |
# File 'lib/amun/buffer.rb', line 92 def @messages ||= new('*Messages*') instances << @messages @messages end |
.scratch ⇒ Object
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 |
#clear ⇒ Object
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_s ⇒ Object
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 |