Class: Rvim::Buffer
- Inherits:
-
Object
- Object
- Rvim::Buffer
- Defined in:
- lib/rvim/buffer.rb
Instance Attribute Summary collapse
-
#byte_pointer ⇒ Object
Returns the value of attribute byte_pointer.
-
#diff_active ⇒ Object
Returns the value of attribute diff_active.
-
#diff_status ⇒ Object
Returns the value of attribute diff_status.
-
#fileencoding ⇒ Object
Returns the value of attribute fileencoding.
-
#fileformat ⇒ Object
Returns the value of attribute fileformat.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#folds ⇒ Object
Returns the value of attribute folds.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_visual ⇒ Object
Returns the value of attribute last_visual.
-
#line_index ⇒ Object
Returns the value of attribute line_index.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#local_settings ⇒ Object
Returns the value of attribute local_settings.
-
#marks ⇒ Object
Returns the value of attribute marks.
-
#modified ⇒ Object
Returns the value of attribute modified.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#undo_redo_history ⇒ Object
Returns the value of attribute undo_redo_history.
-
#undo_redo_index ⇒ Object
Returns the value of attribute undo_redo_index.
-
#vars ⇒ Object
Returns the value of attribute vars.
Instance Method Summary collapse
- #display_name ⇒ Object
- #file_changed_externally? ⇒ Boolean
-
#initialize(id, filepath = nil, encoding: Encoding::UTF_8) ⇒ Buffer
constructor
A new instance of Buffer.
- #reload(encoding: Encoding::UTF_8) ⇒ Object
Constructor Details
#initialize(id, filepath = nil, encoding: Encoding::UTF_8) ⇒ Buffer
Returns a new instance of Buffer.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rvim/buffer.rb', line 13 def initialize(id, filepath = nil, encoding: Encoding::UTF_8) @id = id @filepath = filepath @fileformat = 'unix' @fileencoding = encoding.to_s.downcase @mtime = nil if filepath && File.exist?(filepath) raw = File.binread(filepath) @mtime = File.mtime(filepath) @fileformat = detect_fileformat(raw) decoded = decode_with_encoding(raw, encoding) @lines = split_with_format(decoded, @fileformat).map { |l| String.new(l, encoding: encoding) } else @lines = [String.new('', encoding: encoding)] end @lines = [String.new('', encoding: encoding)] if @lines.empty? @modified = false @marks = Rvim::Marks.new @line_index = 0 @byte_pointer = 0 # Seed the undo history with the file's actual loaded content so the # very first undo from a post-edit state restores the on-disk view, # not Reline's empty default. @undo_redo_history = [[@lines.map(&:dup), 0, 0]] @undo_redo_index = 0 @last_visual = nil @local_settings = {} @folds = Rvim::Folds.new @diff_active = false @diff_status = nil @vars = {} end |
Instance Attribute Details
#byte_pointer ⇒ Object
Returns the value of attribute byte_pointer.
6 7 8 |
# File 'lib/rvim/buffer.rb', line 6 def byte_pointer @byte_pointer end |
#diff_active ⇒ Object
Returns the value of attribute diff_active.
9 10 11 |
# File 'lib/rvim/buffer.rb', line 9 def diff_active @diff_active end |
#diff_status ⇒ Object
Returns the value of attribute diff_status.
9 10 11 |
# File 'lib/rvim/buffer.rb', line 9 def diff_status @diff_status end |
#fileencoding ⇒ Object
Returns the value of attribute fileencoding.
10 11 12 |
# File 'lib/rvim/buffer.rb', line 10 def fileencoding @fileencoding end |
#fileformat ⇒ Object
Returns the value of attribute fileformat.
10 11 12 |
# File 'lib/rvim/buffer.rb', line 10 def fileformat @fileformat end |
#filepath ⇒ Object
Returns the value of attribute filepath.
5 6 7 |
# File 'lib/rvim/buffer.rb', line 5 def filepath @filepath end |
#folds ⇒ Object
Returns the value of attribute folds.
8 9 10 |
# File 'lib/rvim/buffer.rb', line 8 def folds @folds end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/rvim/buffer.rb', line 5 def id @id end |
#last_visual ⇒ Object
Returns the value of attribute last_visual.
7 8 9 |
# File 'lib/rvim/buffer.rb', line 7 def last_visual @last_visual end |
#line_index ⇒ Object
Returns the value of attribute line_index.
6 7 8 |
# File 'lib/rvim/buffer.rb', line 6 def line_index @line_index end |
#lines ⇒ Object
Returns the value of attribute lines.
5 6 7 |
# File 'lib/rvim/buffer.rb', line 5 def lines @lines end |
#local_settings ⇒ Object
Returns the value of attribute local_settings.
8 9 10 |
# File 'lib/rvim/buffer.rb', line 8 def local_settings @local_settings end |
#marks ⇒ Object
Returns the value of attribute marks.
6 7 8 |
# File 'lib/rvim/buffer.rb', line 6 def marks @marks end |
#modified ⇒ Object
Returns the value of attribute modified.
5 6 7 |
# File 'lib/rvim/buffer.rb', line 5 def modified @modified end |
#mtime ⇒ Object
Returns the value of attribute mtime.
10 11 12 |
# File 'lib/rvim/buffer.rb', line 10 def mtime @mtime end |
#undo_redo_history ⇒ Object
Returns the value of attribute undo_redo_history.
7 8 9 |
# File 'lib/rvim/buffer.rb', line 7 def undo_redo_history @undo_redo_history end |
#undo_redo_index ⇒ Object
Returns the value of attribute undo_redo_index.
7 8 9 |
# File 'lib/rvim/buffer.rb', line 7 def undo_redo_index @undo_redo_index end |
#vars ⇒ Object
Returns the value of attribute vars.
11 12 13 |
# File 'lib/rvim/buffer.rb', line 11 def vars @vars end |
Instance Method Details
#display_name ⇒ Object
46 47 48 |
# File 'lib/rvim/buffer.rb', line 46 def display_name @filepath || '[No Name]' end |
#file_changed_externally? ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/rvim/buffer.rb', line 50 def file_changed_externally? return false unless @filepath && File.exist?(@filepath) return false if @mtime.nil? File.mtime(@filepath) > @mtime end |
#reload(encoding: Encoding::UTF_8) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rvim/buffer.rb', line 57 def reload(encoding: Encoding::UTF_8) return unless @filepath && File.exist?(@filepath) raw = File.binread(@filepath) @mtime = File.mtime(@filepath) @fileformat = detect_fileformat(raw) decoded = decode_with_encoding(raw, encoding) @lines = split_with_format(decoded, @fileformat).map { |l| String.new(l, encoding: encoding) } @lines = [String.new('', encoding: encoding)] if @lines.empty? @line_index = @line_index.clamp(0, [@lines.size - 1, 0].max) target = @lines[@line_index] || '' @byte_pointer = @byte_pointer.clamp(0, [target.bytesize - 1, 0].max) end |