Class: Neovim::Buffer

Inherits:
RemoteObject show all
Includes:
Enumerable
Defined in:
lib/neovim/remote_object.rb

Direct Known Subclasses

Vim::Buffer

Constant Summary collapse

OPTION_PARAM =
:buf

Constants inherited from RemoteObject

RemoteObject::TRANSFER

Class Attribute Summary collapse

Attributes inherited from RemoteObject

#client, #index

Instance Method Summary collapse

Methods inherited from RemoteObject

#==, #call_api, #call_obj, from_mpdata, #initialize, #inspect, #method_missing, #methods, new, plain_new, #respond_to_missing?, #to_mpdata, type, #type

Methods included from OptionAccess

#get_option, #option_params, #set_option

Constructor Details

This class inherits a constructor from Neovim::RemoteObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Neovim::RemoteObject

Class Attribute Details

.chunkObject

Returns the value of attribute chunk.



264
265
266
# File 'lib/neovim/remote_object.rb', line 264

def chunk
  @chunk
end

Instance Method Details

#[](pos = nil, len = nil) ⇒ Object



139
140
141
142
143
# File 'lib/neovim/remote_object.rb', line 139

def [] pos = nil, len = nil
  line_indices pos, len do |fst,lst|
    get_lines fst, lst, false
  end
end

#[]=(pos = nil, len = nil, str) ⇒ Object



145
146
147
148
149
150
# File 'lib/neovim/remote_object.rb', line 145

def []= pos = nil, len = nil, str
  line_indices pos, len do |fst,lst|
    set_lines fst, lst, false, (str_lines str)
  end
  self
end

#active?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/neovim/remote_object.rb', line 180

def active?
  (call_api :get_current_buf).index == @index
end

#append(pos = nil, str) ⇒ Object



158
159
160
161
# File 'lib/neovim/remote_object.rb', line 158

def append pos = nil, str
  p = (pos||0) + 1
  insert p, str
end

#countObject Also known as: length



136
# File 'lib/neovim/remote_object.rb', line 136

def count  ; call_obj :line_count ; end

#delete(pos, len = nil) ⇒ Object



152
# File 'lib/neovim/remote_object.rb', line 152

def delete pos, len = nil ; self[pos, len] = nil ; end

#each(pos = nil, len = nil, &block) ⇒ Object



192
193
194
195
196
# File 'lib/neovim/remote_object.rb', line 192

def each pos = nil, len = nil, &block
  iter_chunks pos, len do |fst,nxt|
    (get_lines fst, nxt, true).each &block
  end
end

#get_lines(fst, lst, strict) ⇒ Object

Don’t run into ‘method_missing`.



225
# File 'lib/neovim/remote_object.rb', line 225

def get_lines fst, lst, strict      ; call_obj :get_lines, fst, lst, strict      ; end

#insert(pos = nil, str) ⇒ Object



154
155
156
# File 'lib/neovim/remote_object.rb', line 154

def insert pos = nil, str
  self[ pos||0, 0] = str
end

#lineObject

Legacy functions



166
167
168
# File 'lib/neovim/remote_object.rb', line 166

def line
  call_api :get_current_line if active?
end

#line=(str) ⇒ Object



170
171
172
173
# File 'lib/neovim/remote_object.rb', line 170

def line= str
  raise "Buffer not active. Use Buffer#[]= instead." unless active?
  call_api :set_current_line, str
end

#line_numberObject



175
176
177
# File 'lib/neovim/remote_object.rb', line 175

def line_number
  (call_api :get_current_win).line if active?
end

#map!(pos = nil, len = nil, &block) ⇒ Object



198
199
200
201
202
203
# File 'lib/neovim/remote_object.rb', line 198

def map! pos = nil, len = nil, &block
  iter_chunks pos, len do |fst,nxt|
    l = (get_lines fst, nxt, true).map &block
    set_lines fst, nxt, true, l
  end
end

#nameObject

Functions as described in “:h ruby”



133
# File 'lib/neovim/remote_object.rb', line 133

def name   ; call_obj :get_name   ; end

#numberObject



134
# File 'lib/neovim/remote_object.rb', line 134

def number ; call_obj :get_number ; end

#reject!(pos = nil, len = nil, &block) ⇒ Object



219
220
221
# File 'lib/neovim/remote_object.rb', line 219

def reject! pos = nil, len = nil, &block
  select! pos, len do |l| !yield l end
end

#select!(pos = nil, len = nil, &block) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/neovim/remote_object.rb', line 205

def select! pos = nil, len = nil, &block
  line_indices_positive pos, len do |fst,lst|
    while fst < lst do
      l, = get_lines fst, fst+1, true
      if yield l then
        fst += 1
      else
        set_lines fst, fst+1, true, []
        lst -= 1
      end
    end
  end
end

#set_lines(fst, lst, strict, ary) ⇒ Object



226
# File 'lib/neovim/remote_object.rb', line 226

def set_lines fst, lst, strict, ary ; call_obj :set_lines, fst, lst, strict, ary ; end