Class: Neovim::Buffer

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

Constant Summary collapse

OPTION_PARAM =
:buf

Constants inherited from RemoteObject

RemoteObject::TRANSFER

Class Attribute Summary collapse

Attributes inherited from RemoteObject

#client, #index

Class Method Summary collapse

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.



267
268
269
# File 'lib/neovim/remote_object.rb', line 267

def chunk
  @chunk
end

Class Method Details

.[](i) ⇒ Object



26
# File 'lib/neovim/ruby_provider.rb', line 26

def [] i    ; $vim.list_bufs[ i]   ; end

.countObject



25
# File 'lib/neovim/ruby_provider.rb', line 25

def count   ; $vim.list_bufs.size  ; end

.currentObject



24
# File 'lib/neovim/ruby_provider.rb', line 24

def current ; $vim.get_current_buf ; end

Instance Method Details

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



142
143
144
145
146
# File 'lib/neovim/remote_object.rb', line 142

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



148
149
150
151
152
153
# File 'lib/neovim/remote_object.rb', line 148

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)


183
184
185
# File 'lib/neovim/remote_object.rb', line 183

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

#append(pos = nil, str) ⇒ Object



161
162
163
164
# File 'lib/neovim/remote_object.rb', line 161

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

#countObject



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

def count  ; call_obj :line_count ; end

#delete(pos, len = nil) ⇒ Object



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

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

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



195
196
197
198
199
# File 'lib/neovim/remote_object.rb', line 195

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`.



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

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

#insert(pos = nil, str) ⇒ Object



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

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

#lengthObject



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

def count  ; call_obj :line_count ; end

#lineObject

Legacy functions



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

def line
  call_api :get_current_line if active?
end

#line=(str) ⇒ Object



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

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

#line_numberObject



178
179
180
# File 'lib/neovim/remote_object.rb', line 178

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

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



201
202
203
204
205
206
# File 'lib/neovim/remote_object.rb', line 201

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”



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

def name   ; call_obj :get_name   ; end

#numberObject



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

def number ; index                ; end

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



222
223
224
# File 'lib/neovim/remote_object.rb', line 222

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

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



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/neovim/remote_object.rb', line 208

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



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

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