nvimutil

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2020 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package nvimutil provides wrapper functions of nvim go-client.

Index

Constants

View Source
const (
	// Map map key mapping type.
	Map = "map"
	// MapNormal nmap that normal mode key mapping.
	MapNormal = "nmap"
	// MapVisualSelect vmap that visual-select mode key mapping.
	MapVisualSelect = "vmap"
	// MapSelect smap that select mode key mapping.
	MapSelect = "smap"
	// MapVisual xmap that visual mode key mapping.
	MapVisual = "xmap"
	// MapOperator omap that operator mode key mapping.
	MapOperator = "omap"
	// MapInsert imap that insert mode key mapping.
	MapInsert = "imap"
	// MapCommandLine cmap that command line mode key mapping.
	MapCommandLine = "cmap"
	// MapTerminal tmap that terminal mode key mapping.
	MapTerminal = "tmap"

	// Noremap map key mapping type with no remap.
	Noremap = "noremap"
	// NoremapNormal nnoremap that normal mode key mapping with no remap.
	NoremapNormal = "nnoremap"
	// NoremapVisualSelect vmap that visual-select mode key mapping with no remap.
	NoremapVisualSelect = "vnoremap"
	// NoremapSelect snoremap that select mode key mapping with no remap.
	NoremapSelect = "snoremap"
	// NoremapVisual xnoremap that visual mode key mapping with no remap.
	NoremapVisual = "xnoremap"
	// NoremapOperator onoremap that operator mode key mapping with no remap.
	NoremapOperator = "onoremap"
	// NoremapInsert inoremap that insert mode key mapping with no remap.
	NoremapInsert = "inoremap"
	// NoremapCommandLine cnoremap that command line mode key mapping with no remap.
	NoremapCommandLine = "cnoremap"
	// NoremapTerminal tmap that terminal mode key mapping with no remap.
	NoremapTerminal = "tnoremap"
)
View Source
const (
	// BufOptionBufhidden represents a bufhidden.
	BufOptionBufhidden = "bufhidden" // string
	// BufOptionBuflisted represents a buflisted.
	BufOptionBuflisted = "buflisted" // bool
	// BufOptionBuftype represents a buftype.
	BufOptionBuftype = "buftype" // string
	// BufOptionFiletype represents a filetype.
	BufOptionFiletype = "filetype" // string
	// BufOptionModifiable represents a modifiable.
	BufOptionModifiable = "modifiable" // bool
	// BufOptionModified represents a modified.
	BufOptionModified = "modified" // bool
	// BufOptionSwapfile represents a swapfile.
	BufOptionSwapfile = "swapfile" // bool

	// BufVarColorcolumn represents a colorcolumn.
	BufVarColorcolumn = "colorcolumn" // string

	// WinOptionList represents a list.
	WinOptionList = "list" // bool
	// WinOptionNumber represents a number.
	WinOptionNumber = "number" // bool
	// WinOptionRelativenumber represents a relativenumbers.
	WinOptionRelativenumber = "relativenumber" // bool
	// WinOptionWinfixheight represents a winfixheight.
	WinOptionWinfixheight = "winfixheight" // bool
)
View Source
const (
	// BufhiddenDelete delete the buffer from the buffer list, also when 'hidden' is set or using :hide, like using :bdelete.
	BufhiddenDelete = "delete"
	// BufhiddenHide hide the buffer (don't unload it), also when 'hidden' is not set.
	BufhiddenHide = "hide"
	// BufhiddenUnload unload the buffer, also when 'hidden' is set or using :hide.
	BufhiddenUnload = "unload"
	// BufhiddenWipe wipe out the buffer from the buffer list, also when 'hidden' is set or using :hide, like using :bwipeout.
	BufhiddenWipe = "wipe"
	// BuftypeAcwrite buffer which will always be written with BufWriteCmd autocommands.
	BuftypeAcwrite = "acwrite"
	// BuftypeHelp help buffer (you are not supposed to set this manually).
	BuftypeHelp = "help"
	// BuftypeNofile buffer which is not related to a file and will not be written.
	BuftypeNofile = "nofile"
	// BuftypeNowrite buffer which will not be written.
	BuftypeNowrite = "nowrite"
	// BuftypeQuickfix quickfix buffer, contains list of errors :cwindow or list of locations :lwindow.
	BuftypeQuickfix = "quickfix"
	// BuftypeTerminal terminal buffer, this is set automatically when a terminal is created. See nvim-terminal-emulator for more information.
	BuftypeTerminal = "terminal"
)
View Source
const (
	// FiletypeAsm represents a asm filetype.
	FiletypeAsm = "asm"
	// FiletypeC represents a c filetype.
	FiletypeC = "c"
	// FiletypeCpp represents a cpp filetype.
	FiletypeCpp = "cpp"
	// FiletypeDelve represents a delve filetype.
	FiletypeDelve = "delve"
	// FiletypeGas represents a gas filetype.
	FiletypeGas = "gas"
	// FiletypeGo represents a go filetype.
	FiletypeGo = "go"
	// FiletypeSh represents a sh filetype.
	FiletypeSh = "sh"
	// FiletypeTerminal represents a terminal filetype.
	FiletypeTerminal = "terminal"
	// FiletypeGoTerminal represents a go-terminal filetype.
	FiletypeGoTerminal = "goterminal"
)
View Source
const (
	// BreakpointSymbol symbol of breakpoint.
	//
	// ●  BLACK CIRCLE                         (U+25CF)
	BreakpointSymbol = "\u25cf"
	// BreakpointSymbolLarge symbol of breakpoint with large.
	//
	// ⬤  BLACK LARGE CIRCLE                   (U+2B24)
	BreakpointSymbolLarge = "\u2b24"
	// TracepointSymbol symbol of tracepoint.
	//
	// ◆  BLACK DIAMOND                        (U+25C6)
	TracepointSymbol = "\u25c6"
	// TracepointSymbolMidium symbol of tracepoint with midium.
	//
	// ⬥  BLACK DIAMOND SUIT                   (U+2B25)
	TracepointSymbolMidium = "\u2b25"
	// ProgramCounterSymbol symbol of program counter.
	//
	// ◎  BULLSEYE                             (U+25CE)
	ProgramCounterSymbol = "\u25ce"
	// ProgramCounterSymbolRing symbol of program counter with ring.
	//
	// ⏣  BENZENE RING WITH CIRCLE             (U+23e3)
	ProgramCounterSymbolRing = "\u23e3"
	// ErrorSymbol symbol of error.
	//
	//  ⃠  COMBINING ENCLOSING CIRCLE BACKSLASH (U+20E0)
	ErrorSymbol = "\u20e0"
	// RestartSymbol symbol of restart.
	// ⟲  ANTICLOCKWISE GAPPED CIRCLE ARROW    (U+27F2)
	RestartSymbol = "\u27f2"
)

Variables

View Source
var (
	// ErrorColor highlight error message use Identifier syntax color.
	ErrorColor = "Identifier"
	// ProgressColor highlight progress message use Identifier syntax color.
	ProgressColor = "Identifier"
	// SuccessColor highlight success message use Identifier syntax color.
	SuccessColor = "Function"
)

Functions

func ByteOffset

func ByteOffset(n *nvim.Nvim, b nvim.Buffer, w nvim.Window) (int, error)

ByteOffset calculates the byte-offset of current cursor position.

func ClearErrorlist

func ClearErrorlist(v *nvim.Nvim, close bool) error

ClearErrorlist clear the Neovim error list.

func ClearMsg

func ClearMsg(v *nvim.Nvim) error

ClearMsg cleanups the echo area.

func CloseLoclist

func CloseLoclist(v *nvim.Nvim) error

CloseLoclist close the current buffer's locationlist window.

func CloseQuickfix

func CloseQuickfix(v *nvim.Nvim) error

CloseQuickfix close the quickfix list window.

func CompleteFiles

func CompleteFiles(v *nvim.Nvim, a *nvim.CommandCompletionArgs, dir string) (filelist []string, err error)

CompleteFiles provides a "-complete=file" completion exclude the non go files.

func Echo

func Echo(v *nvim.Nvim, format string, a ...interface{}) error

Echo provide the vim 'echo' command.

func EchoProgress

func EchoProgress(v *nvim.Nvim, prefix, format string, a ...interface{}) error

EchoProgress displays a command progress message to echo area.

func EchoRaw

func EchoRaw(v *nvim.Nvim, a string) error

EchoRaw provide the raw output vim 'echo' command.

func EchoSuccess

func EchoSuccess(v *nvim.Nvim, prefix string, msg string) error

EchoSuccess displays the success of the command to echo area.

func Echoerr

func Echoerr(v *nvim.Nvim, format string, a ...interface{}) error

Echoerr provide the vim 'echoerr' command.

func EchohlAfter

func EchohlAfter(v *nvim.Nvim, prefix string, highlight string, format string, a ...interface{}) error

EchohlAfter provide the vim 'echo' command with the 'echohl' highlighting message text.

func EchohlBefore

func EchohlBefore(v *nvim.Nvim, prefix string, highlight string, format string, a ...interface{}) error

EchohlBefore provide the vim 'echo' command with the 'echohl' highlighting prefix text.

func Echomsg

func Echomsg(v *nvim.Nvim, a ...interface{}) error

Echomsg provide the vim 'echomsg' command.

func ErrorList

func ErrorList(v *nvim.Nvim, errors map[string][]*nvim.QuickfixError, keep bool) error

ErrorList merges the errlist map items and open the locationlist window.

func ErrorWrap

func ErrorWrap(v *nvim.Nvim, err error) error

ErrorWrap splits the errors.Wrap's cause and error messages, and provide the vim 'echo' message with 'echohl' highlighting to cause text.

func GotoPos

func GotoPos(v *nvim.Nvim, w nvim.Window, pos token.Position, cwd string) error

GotoPos change current buffer from the pos position with 'zz' normal behavior.

func IsBufExists

func IsBufExists(n *nvim.Nvim, bufnr int) bool

IsBufExists reports whether buffer list is within bufnr use vim bufexists function.

func IsBufferContains

func IsBufferContains(n *nvim.Nvim, b nvim.Buffer) bool

IsBufferContains reports whether buffer list is within b.

func IsBufferValid

func IsBufferValid(n *nvim.Nvim, b nvim.Buffer) bool

IsBufferValid wrapper of nvim.IsBufferValid function.

func IsVisible

func IsVisible(n *nvim.Nvim, filetype string) bool

IsVisible reports whether buffer list within buffer that &ft has filetype. Useful for Check qf, preview or any specific buffer is whether the opened.

func Modifiable

func Modifiable(n *nvim.Nvim, b nvim.Buffer) func()

Modifiable sets modifiable to true, The returned function restores modifiable to false.

func Notify

func Notify(n *nvim.Nvim, method string, args ...string) error

func OpenLoclist

func OpenLoclist(v *nvim.Nvim, w nvim.Window, loclist []*nvim.QuickfixError, keep bool) error

OpenLoclist open or close the current buffer's locationlist window.

func OpenOuickfix

func OpenOuickfix(b *nvim.Batch, w nvim.Window, keep bool) error

OpenOuickfix open the quickfix list window.

func ParseError

func ParseError(ctx context.Context, errmsg []byte, cwd string, bctxt *buildctxt.Build, ignoreDirs []string) ([]*nvim.QuickfixError, error)

ParseError parses a typical Go tools error messages.

func Profile

func Profile(ctx context.Context, start time.Time, name ...string)

Profile measurement of the time it took to any func and output log file.

Usage: defer nvim.Profile(time.Now(), "name", "...")

func SetErrorlist

func SetErrorlist(v *nvim.Nvim, errlist []*nvim.QuickfixError) error

SetErrorlist set the error results data to Neovim error list.

func SetLoclist

func SetLoclist(v *nvim.Nvim, loclist []*nvim.QuickfixError) error

SetLoclist set the error results data to current buffer's locationlist.

func SetQuickfix

func SetQuickfix(b *nvim.Batch, qflist []*nvim.QuickfixError) error

SetQuickfix set the error results data to quickfix list.

func SplitPos

func SplitPos(pos string, cwd string) (string, int, int)

SplitPos parses a string of form 'token.Pos', and return the relative filepath from the current working directory path.

func StrToByteSlice

func StrToByteSlice(s string) []byte

StrToByteSlice convert string to byte slice use unsafe. https://gist.github.com/dgryski/65d632958e4d88c7f79aaa7e1d2b10c0

func TestNvim

func TestNvim(t *testing.T, file ...string) *nvim.Nvim

TestNvim sets XDG tmpdir and return the *nvim.Nvim for unit testing.

func ToBufferLines

func ToBufferLines(byt []byte) [][]byte

ToBufferLines converts the byte slice to the 2D byte slice of Neovim buffer data.

func ToByteSlice

func ToByteSlice(byt [][]byte) []byte

ToByteSlice converts the 2D buffer byte data to sigle byte slice.

func ToMixedCase

func ToMixedCase(s string) string

ToMixedCase convert s to mixedCase. This function assumes that the character of the beginning is A-Z.

func ToPascalCase

func ToPascalCase(s string) string

ToPascalCase convert s to PascalCase. This function assumes that the character of the beginning is a-z.

Types

type Buffer

type Buffer struct {
	Name     string
	Filetype string
	Bufnr    int
	Mode     string
	Height   int
	Width    int
	Data     []byte

	WindowContext
	TabpageContext
	// contains filtered or unexported fields
}

Buffer represents a Neovim buffer.

func NewBuffer

func NewBuffer(n *nvim.Nvim) *Buffer

NewBuffer return the new Buf instance with goroutine pipeline.

func (*Buffer) Buffer

func (b *Buffer) Buffer() nvim.Buffer

Buffer return the current nvim.Buffer.

func (*Buffer) BufferLines

func (b *Buffer) BufferLines(start, end int, strict bool)

BufferLines gets the current buffer lines.

func (*Buffer) Create

func (b *Buffer) Create(name, filetype, mode string, option map[NvimOption]map[string]interface{}) error

Create creates the new buffer and return the Buffer structure type.

func (*Buffer) GetBufferContext

func (b *Buffer) GetBufferContext() error

GetBufferContext gets the current buffers context.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the Neovim buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as Truncate(0).

func (*Buffer) SetBufferLines

func (b *Buffer) SetBufferLines(start, end int, strict bool, replacement []byte) error

SetBufferLines sets the replacement to current buffer.

func (*Buffer) SetBufferLinesAll

func (b *Buffer) SetBufferLinesAll(replacement []byte) error

SetBufferLinesAll wrapper of SetBufferLines with all lines.

func (*Buffer) SetLocalMapping

func (b *Buffer) SetLocalMapping(mode string, mapping map[string]string) error

SetLocalMapping sets buffer local mapping. 'mapping' arg: [key]{destination}

func (*Buffer) Truncate

func (b *Buffer) Truncate(n int)

Truncate discards all but the first n unread bytes from the Neovim buffer but continues to use the same allocated storage.

func (*Buffer) UpdateSyntax

func (b *Buffer) UpdateSyntax(syntax string)

UpdateSyntax updates the syntax highlight of the buffer.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

Write appends the contents of p to the Neovim buffer.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) error

WriteString appends the contents of s to the Neovim buffer.

type BufferName

type BufferName string

BufferName represents a buffer name.

type ErrorListType

type ErrorListType string

ErrorListType represents a neovim error list type.

const (
	// Quickfix quickfix error list type.
	Quickfix ErrorListType = "quickfix"
	// LocationList locationlist error list type.
	LocationList = "locationlist"
)

type Fade

type Fade struct {
	// contains filtered or unexported fields
}

Fade represents a Fade highlighting.

func NewFader

func NewFader(n *nvim.Nvim, buffer nvim.Buffer, hlGroup string, startLine, endLine, startCol, endCol int, duration int) *Fade

NewFader returns a new Fade.

func (*Fade) FadeOut

func (f *Fade) FadeOut() error

FadeOut fade out the highlights.

func (*Fade) SetHighlight

func (f *Fade) SetHighlight() error

SetHighlight sets the highlight to at once.

type NvimOption

type NvimOption int

NvimOption represents a Neovim buffer, window and tabpage options.

const (
	// BufferOption buffer option type.
	BufferOption NvimOption = iota
	// BufferVar buffer var type.
	BufferVar
	// WindowOption window option type.
	WindowOption
	// WindowVar window var type.
	WindowVar
	// TabpageVar tabpage var type.
	TabpageVar
)

type Sign

type Sign struct {
	Name   string
	Text   string
	Texthl string
	Linehl string

	LastID   int
	LastLine int
	LastFile string
}

Sign represents a Neovim sign.

func NewSign

func NewSign(v *nvim.Nvim, name, text, texthl, linehl string) (*Sign, error)

NewSign define new sign and return the Sign type structure.

func (*Sign) Place

func (s *Sign) Place(v *nvim.Nvim, id, line int, file string, clearLastSign bool) error

Place places the sign to any file.

func (*Sign) Unplace

func (s *Sign) Unplace(v *nvim.Nvim, id int, file string) error

Unplace unplace the sign.

func (*Sign) UnplaceAll

func (s *Sign) UnplaceAll(v *nvim.Nvim, file string) error

UnplaceAll unplace all sign on any file.

type TabpageContext

type TabpageContext struct {
	nvim.Tabpage
}

TabpageContext represents a Neovim tabpage context.

type Terminal

type Terminal struct {

	// Name terminal buffer name.
	Name string
	// Dir specifies the working directory of the command on terminal.
	Dir string
	// Size open the terminal window size.
	Size int

	Nvim  *nvim.Nvim
	Batch *nvim.Batch

	*Buffer
	// contains filtered or unexported fields
}

Terminal represents a Neovim terminal.

func NewTerminal

func NewTerminal(n *nvim.Nvim, name string, command []string, mode string) *Terminal

NewTerminal return the Neovim terminal buffer.

func (*Terminal) Create

func (t *Terminal) Create() (err error)

Create creats the new Neovim terminal buffer.

func (*Terminal) Run

func (t *Terminal) Run(cmd []string) error

Run runs the command in the terminal buffer.

type WindowContext

type WindowContext struct {
	nvim.Window
}

WindowContext represents a Neovim window context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL