Class: Neovim::Buffer Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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_missing?, #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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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

.countObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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

.currentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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)

124
125
126
# File 'lib/neovim/buffer.rb', line 124

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

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

See :h nvim_buf_add_highlight()

Parameters:

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

Returns:

  • (Integer)

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


#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

#attach(send_buffer, opts) ⇒ Boolean

See :h nvim_buf_attach()

Parameters:

  • send_buffer (Boolean)
  • opts (Hash)

Returns:

  • (Boolean)

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


#clear_highlight(src_id, line_start, line_end) ⇒ void

This method returns an undefined value.

See :h nvim_buf_clear_highlight()

Parameters:

  • src_id (Integer)
  • line_start (Integer)
  • line_end (Integer)

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


#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(name) ⇒ void

This method returns an undefined value.

See :h nvim_buf_del_var()

Parameters:

  • name (String)

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


#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

#detachBoolean

See :h nvim_buf_detach()

Returns:

  • (Boolean)

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


#get_changedtickInteger

See :h nvim_buf_get_changedtick()

Returns:

  • (Integer)

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


#get_commands(opts) ⇒ Hash

See :h nvim_buf_get_commands()

Parameters:

  • opts (Hash)

Returns:

  • (Hash)

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


#get_keymap(mode) ⇒ Array<Hash>

See :h nvim_buf_get_keymap()

Parameters:

  • mode (String)

Returns:

  • (Array<Hash>)

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


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

See :h nvim_buf_get_lines()

Parameters:

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

Returns:

  • (Array<String>)

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


#get_mark(name) ⇒ Array<Integer>

See :h nvim_buf_get_mark()

Parameters:

  • name (String)

Returns:

  • (Array<Integer>)

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


#get_nameString

See :h nvim_buf_get_name()

Returns:

  • (String)

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


#get_numberInteger

See :h nvim_buf_get_number()

Returns:

  • (Integer)

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


#get_option(name) ⇒ Object

See :h nvim_buf_get_option()

Parameters:

  • name (String)

Returns:

  • (Object)

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


#get_var(name) ⇒ Object

See :h nvim_buf_get_var()

Parameters:

  • name (String)

Returns:

  • (Object)

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


#is_validBoolean

See :h nvim_buf_is_valid()

Returns:

  • (Boolean)

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


#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
# File 'lib/neovim/buffer.rb', line 102

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

#line=(str) ⇒ String?

Set the current line of an active buffer.

Parameters:

  • str (String)

Returns:

  • (String, nil)

110
111
112
# File 'lib/neovim/buffer.rb', line 110

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

#line_countInteger

See :h nvim_buf_line_count()

Returns:

  • (Integer)

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


#line_numberInteger?

Get the current line number of an active buffer.

Returns:

  • (Integer, nil)

117
118
119
# File 'lib/neovim/buffer.rb', line 117

def line_number
  @session.request(:nvim_get_current_win).get_cursor[0] if active?
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(start, end) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_lines()

Parameters:

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

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


#set_name(name) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_name()

Parameters:

  • name (String)

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


#set_option(name, value) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_option()

Parameters:

  • name (String)
  • value (Object)

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


#set_var(name, value) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_var()

Parameters:

  • name (String)
  • value (Object)

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