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, 1)
  @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, 1)
  @lines[index - 1] = str
end

#active?Boolean

Determine if the buffer is active.

Returns:

  • (Boolean)


127
128
129
# File 'lib/neovim/buffer.rb', line 127

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

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

See :h nvim_buf_add_highlight()

Parameters:

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

Returns:

  • (Integer)


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

#append(index, str) ⇒ String

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

Unlike the other methods, ‘0` is a valid index argument here, and inserts into the first line of the buffer.

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)


92
93
94
95
96
97
98
99
100
# File 'lib/neovim/buffer.rb', line 92

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

  set_lines(index, index, true, [*str.split($/)])
  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 141

#call(fun) ⇒ Object

See :h nvim_buf_call()

Parameters:

  • fun (LuaRef)

Returns:



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

#clear_highlight(ns_id, line_start, line_end) ⇒ void

This method returns an undefined value.

See :h nvim_buf_clear_highlight()

Parameters:

  • ns_id (Integer)
  • line_start (Integer)
  • line_end (Integer)


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

#clear_namespace(ns_id, line_start, line_end) ⇒ void

This method returns an undefined value.

See :h nvim_buf_clear_namespace()

Parameters:

  • ns_id (Integer)
  • line_start (Integer)
  • line_end (Integer)


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

#countInteger

Get the number of lines.

Returns:

  • (Integer)


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

def count
  line_count
end

#create_user_command(name, command, opts) ⇒ void

This method returns an undefined value.

See :h nvim_buf_create_user_command()

Parameters:

  • name (String)
  • command (Object)
  • opts (Hash)


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

#del_extmark(ns_id, id) ⇒ Boolean

See :h nvim_buf_del_extmark()

Parameters:

  • ns_id (Integer)
  • id (Integer)

Returns:

  • (Boolean)


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

#del_keymap(mode, lhs) ⇒ void

This method returns an undefined value.

See :h nvim_buf_del_keymap()

Parameters:

  • mode (String)
  • lhs (String)


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

#del_mark(name) ⇒ Boolean

See :h nvim_buf_del_mark()

Parameters:

  • name (String)

Returns:

  • (Boolean)


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

#del_user_command(name) ⇒ void

This method returns an undefined value.

See :h nvim_buf_del_user_command()

Parameters:

  • name (String)


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

#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 141

#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, 1)
  @lines.delete(index - 1)
  nil
end

#detachBoolean

See :h nvim_buf_detach()

Returns:

  • (Boolean)


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

#get_changedtickInteger

See :h nvim_buf_get_changedtick()

Returns:

  • (Integer)


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

#get_commands(opts) ⇒ Hash

See :h nvim_buf_get_commands()

Parameters:

  • opts (Hash)

Returns:

  • (Hash)


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

#get_extmark_by_id(ns_id, id, opts) ⇒ Array<Integer>

See :h nvim_buf_get_extmark_by_id()

Parameters:

  • ns_id (Integer)
  • id (Integer)
  • opts (Hash)

Returns:

  • (Array<Integer>)


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

#get_extmarks(ns_id, start, end) ⇒ Array

See :h nvim_buf_get_extmarks()

Parameters:

Returns:

  • (Array)


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

#get_keymap(mode) ⇒ Array<Hash>

See :h nvim_buf_get_keymap()

Parameters:

  • mode (String)

Returns:

  • (Array<Hash>)


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

#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 141

#get_mark(name) ⇒ Array<Integer>

See :h nvim_buf_get_mark()

Parameters:

  • name (String)

Returns:

  • (Array<Integer>)


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

#get_nameString

See :h nvim_buf_get_name()

Returns:

  • (String)


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

#get_numberInteger

See :h nvim_buf_get_number()

Returns:

  • (Integer)


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

#get_offset(index) ⇒ Integer

See :h nvim_buf_get_offset()

Parameters:

  • index (Integer)

Returns:

  • (Integer)


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

#get_option(name) ⇒ Object

See :h nvim_buf_get_option()

Parameters:

  • name (String)

Returns:



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

#get_text(start_row, start_col, end_row, end_col, opts) ⇒ Array<String>

See :h nvim_buf_get_text()

Parameters:

  • start_row (Integer)
  • start_col (Integer)
  • end_row (Integer)
  • end_col (Integer)
  • opts (Hash)

Returns:

  • (Array<String>)


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

#get_var(name) ⇒ Object

See :h nvim_buf_get_var()

Parameters:

  • name (String)

Returns:



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

#is_loadedBoolean

See :h nvim_buf_is_loaded()

Returns:

  • (Boolean)


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

#is_validBoolean

See :h nvim_buf_is_valid()

Returns:

  • (Boolean)


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

#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)


105
106
107
# File 'lib/neovim/buffer.rb', line 105

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)


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

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 141

#line_numberInteger?

Get the current line number of an active buffer.

Returns:

  • (Integer, nil)


120
121
122
# File 'lib/neovim/buffer.rb', line 120

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_extmark(ns_id, line, col, opts) ⇒ Integer

See :h nvim_buf_set_extmark()

Parameters:

  • ns_id (Integer)
  • line (Integer)
  • col (Integer)
  • opts (Hash)

Returns:

  • (Integer)


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

#set_keymap(mode, lhs, rhs, opts) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_keymap()

Parameters:

  • mode (String)
  • lhs (String)
  • rhs (String)
  • opts (Hash)


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

#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 141

#set_mark(name, line, col, opts) ⇒ Boolean

See :h nvim_buf_set_mark()

Parameters:

  • name (String)
  • line (Integer)
  • col (Integer)
  • opts (Hash)

Returns:

  • (Boolean)


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

#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 141

#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 141

#set_text(start_row, start_col, end_row, end_col, replacement) ⇒ void

This method returns an undefined value.

See :h nvim_buf_set_text()

Parameters:

  • start_row (Integer)
  • start_col (Integer)
  • end_row (Integer)
  • end_col (Integer)
  • replacement (Array<String>)


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

#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 141

#set_virtual_text(src_id, line, chunks, opts) ⇒ Integer

See :h nvim_buf_set_virtual_text()

Parameters:

  • src_id (Integer)
  • line (Integer)
  • chunks (Array)
  • opts (Hash)

Returns:

  • (Integer)


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