(u.pos) add more utility functions
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m18s
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m18s
This commit is contained in:
parent
2ea6c02c69
commit
6785398c96
@ -41,6 +41,18 @@ function Pos.new(bufnr, lnum, col, off)
|
||||
return pos
|
||||
end
|
||||
|
||||
--- @param bufnr? number
|
||||
--- @param lnum0 number 1-based
|
||||
--- @param col0 number 1-based
|
||||
--- @param off? number
|
||||
function Pos.from00(bufnr, lnum0, col0, off) return Pos.new(bufnr, lnum0 + 1, col0 + 1, off) end
|
||||
|
||||
--- @param bufnr? number
|
||||
--- @param lnum1 number 1-based
|
||||
--- @param col0 number 1-based
|
||||
--- @param off? number
|
||||
function Pos.from10(bufnr, lnum1, col0, off) return Pos.new(bufnr, lnum1, col0 + 1, off) end
|
||||
|
||||
function Pos.invalid() return Pos.new(0, 0, 0, 0) end
|
||||
|
||||
function Pos.__lt(a, b) return a.lnum < b.lnum or (a.lnum == b.lnum and a.col < b.col) end
|
||||
@ -110,6 +122,11 @@ function Pos:eol() return Pos.from_eol(self.bufnr, self.lnum) end
|
||||
--- @param pos string
|
||||
function Pos:save_to_pos(pos) vim.fn.setpos(pos, { self.bufnr, self.lnum, self.col, self.off }) end
|
||||
|
||||
--- @param winnr? integer
|
||||
function Pos:save_to_cursor(winnr)
|
||||
vim.api.nvim_win_set_cursor(winnr or 0, { self.lnum, self.col - 1 })
|
||||
end
|
||||
|
||||
--- @param mark string
|
||||
function Pos:save_to_mark(mark)
|
||||
local p = self:as_real()
|
||||
|
Loading…
x
Reference in New Issue
Block a user