Class: Neovim::Buffer

Inherits:
RemoteObject show all
Defined in:
lib/neovim/buffer.rb,
lib/neovim/ruby_provider/buffer_ext.rb

Overview

Class representing an nvim buffer.

The methods documented here were generated using NVIM v0.2.2

Instance Attribute Summary collapse

Attributes inherited from RemoteObject

#index

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemoteObject

#==, #method_missing, #methods, #respond_to?, #to_msgpack

Constructor Details

#initialize(*args) ⇒ Buffer

Returns a new instance of Buffer.



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

def initialize(*args)
  super
  @lines = LineRange.new(self)
end

Dynamic Method Handling

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

Instance Attribute Details

#linesObject

Returns the value of attribute lines.



9
10
11
# File 'lib/neovim/buffer.rb', line 9

def lines
  @lines
end

Class Method Details

.[](index) ⇒ Object



13
14
15
# File 'lib/neovim/ruby_provider/buffer_ext.rb', line 13

def self.[](index)
  ::Vim.list_bufs[index]
end

.countObject



9
10
11
# File 'lib/neovim/ruby_provider/buffer_ext.rb', line 9

def self.count
  ::Vim.list_bufs.size
end

.currentObject



5
6
7
# File 'lib/neovim/ruby_provider/buffer_ext.rb', line 5

def self.current
  ::Vim.get_current_buf
end

Instance Method Details

#[](index) ⇒ String

Get the given line (1-indexed).

Parameters:

  • index (Integer)

Returns:

  • (String)


56
57
58
59
# File 'lib/neovim/buffer.rb', line 56

def [](index)
  check_index(index)
  @lines[index-1]
end

#[]=(index, str) ⇒ String

Set the given line (1-indexed).

Parameters:

  • index (Integer)
  • str (String)

Returns:

  • (String)


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

def []=(index, str)
  check_index(index)
  @lines[index-1] = str
end

#active?Boolean

Determine if the buffer is active.

Returns:

  • (Boolean)


130
131
132
# File 'lib/neovim/buffer.rb', line 130

def active?
  @session.request(:nvim_get_current_buf) == self
end

#add_highlight(buffer, src_id, hl_group, line, col_start, col_end) ⇒ Integer

See :h nvim_buf_add_highlight()

Parameters:

  • buffer (Buffer)
  • src_id (Integer)
  • hl_group (String)
  • line (Integer)
  • col_start (Integer)
  • col_end (Integer)

Returns:

  • (Integer)


# File 'lib/neovim/buffer.rb', line 146


#append(index, str) ⇒ String

Append a line after the given line (1-indexed).

To maintain backwards compatibility with vim, the cursor is forced back to its previous position after inserting the line.

Parameters:

  • index (Integer)
  • str (String)

Returns:

  • (String)


89
90
91
92
93
94
95
96
97
# File 'lib/neovim/buffer.rb', line 89

def append(index, str)
  check_index(index)
  window = @session.request(:nvim_get_current_win)
  cursor = window.cursor

  set_lines(index, index, true, [str])
  window.set_cursor(cursor)
  str
end

#clear_highlight(buffer, src_id, line_start, line_end) ⇒ void

This method returns an undefined value.

See :h nvim_buf_clear_highlight()

Parameters:

  • buffer (Buffer)
  • src_id (Integer)
  • line_start (Integer)
  • line_end (Integer)


# File 'lib/neovim/buffer.rb', line 146


#countInteger

Get the number of lines.

Returns:

  • (Integer)


41
42
43
# File 'lib/neovim/buffer.rb', line 41

def count
  line_count
end

#del_var(buffer, name) ⇒ void

This method returns an undefined value.

See :h nvim_buf_del_var()

Parameters:

  • buffer (Buffer)
  • name (String)


# File 'lib/neovim/buffer.rb', line 146


#delete(index) ⇒ void

This method returns an undefined value.

Delete the given line (1-indexed).

Parameters:

  • index (Integer)


75
76
77
78
79
# File 'lib/neovim/buffer.rb', line 75

def delete(index)
  check_index(index)
  @lines.delete(index-1)
  nil
end

#get_changedtick(buffer) ⇒ Integer

See :h nvim_buf_get_changedtick()

Parameters:

Returns:

  • (Integer)


# File 'lib/neovim/buffer.rb', line 146


#get_keymap(buffer, mode) ⇒ Array<Hash>

See :h nvim_buf_get_keymap()

Parameters:

  • buffer (Buffer)
  • mode (String)

Returns:

  • (Array<Hash>)


# File 'lib/neovim/buffer.rb', line 146


#get_lines(buffer, start, end) ⇒ Array<String>

See :h nvim_buf_get_lines()

Parameters:

  • buffer (Buffer)
  • start (Integer)
  • end (Integer)
  • strict_indexing (Boolean)

Returns:

  • (Array<String>)


# File 'lib/neovim/buffer.rb', line 146


#get_mark(buffer, name) ⇒ Array<Integer>

See :h nvim_buf_get_mark()

Parameters:

  • buffer (Buffer)
  • name (String)

Returns:

  • (Array<Integer>)


# File 'lib/neovim/buffer.rb', line 146


#get_name(buffer) ⇒ String

See :h nvim_buf_get_name()

Parameters:

Returns:

  • (String)


# File 'lib/neovim/buffer.rb', line 146


#get_number(buffer) ⇒ Integer

See :h nvim_buf_get_number()

Parameters:

Returns:

  • (Integer)


# File 'lib/neovim/buffer.rb', line 146


#get_option(buffer, name) ⇒ Object

See :h nvim_buf_get_option()

Parameters:

  • buffer (Buffer)
  • name (String)

Returns:

  • (Object)


# File 'lib/neovim/buffer.rb', line 146


#get_var(buffer, name) ⇒ Object

See :h nvim_buf_get_var()

Parameters:

  • buffer (Buffer)
  • name (String)

Returns:

  • (Object)


# File 'lib/neovim/buffer.rb', line 146


#is_valid(buffer) ⇒ Boolean

See :h nvim_buf_is_valid()

Parameters:

Returns:

  • (Boolean)


# File 'lib/neovim/buffer.rb', line 146


#lengthInteger

Get the number of lines.

Returns:

  • (Integer)


48
49
50
# File 'lib/neovim/buffer.rb', line 48

def length
  count
end

#lineString?

Get the current line of an active buffer.

Returns:

  • (String, nil)


102
103
104
105
106
# File 'lib/neovim/buffer.rb', line 102

def line
  if active?
    @session.request(:nvim_get_current_line)
  end
end

#line=(str) ⇒ String?

Set the current line of an active buffer.

Parameters:

  • str (String)

Returns:

  • (String, nil)


112
113
114
115
116
# File 'lib/neovim/buffer.rb', line 112

def line=(str)
  if active?
    @session.request(:nvim_set_current_line, str)
  end
end

#line_count(buffer) ⇒ Integer

See :h nvim_buf_line_count()

Parameters:

Returns:

  • (Integer)


# File 'lib/neovim/buffer.rb', line 146


#line_numberInteger?

Get the current line number of an active buffer.

Returns:

  • (Integer, nil)


121
122
123
124
125
# File 'lib/neovim/buffer.rb', line 121

def line_number
  if active?
    @session.request(:nvim_get_current_win).get_cursor[0]
  end
end

#nameString

Get the buffer name.

Returns:

  • (String)


27
28
29
# File 'lib/neovim/buffer.rb', line 27

def name
  get_name
end

#numberInteger

Get the buffer index.

Returns:

  • (Integer)


34
35
36
# File 'lib/neovim/buffer.rb', line 34

def number
  get_number
end

#set_lines(buffer, start, end) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_lines()

Parameters:

  • buffer (Buffer)
  • start (Integer)
  • end (Integer)
  • strict_indexing (Boolean)
  • replacement (Array<String>)


# File 'lib/neovim/buffer.rb', line 146


#set_name(buffer, name) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_name()

Parameters:

  • buffer (Buffer)
  • name (String)


# File 'lib/neovim/buffer.rb', line 146


#set_option(buffer, name, value) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_option()

Parameters:

  • buffer (Buffer)
  • name (String)
  • value (Object)


# File 'lib/neovim/buffer.rb', line 146


#set_var(buffer, name, value) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_var()

Parameters:

  • buffer (Buffer)
  • name (String)
  • value (Object)


# File 'lib/neovim/buffer.rb', line 146