rebrand to u.nvim
All checks were successful
NeoVim tests / plenary-tests (push) Successful in 8s

This commit is contained in:
Jonathan Apodaca 2024-10-23 17:01:12 -06:00
parent f3e352ceda
commit 121e0c0f7a
13 changed files with 52 additions and 33 deletions

View File

@ -1,8 +1,8 @@
# Text Tools (TT) # u.nvim
Welcome to **Text Tools (TT)** a powerful Lua library designed to enhance your text manipulation experience in NeoVim, focusing primarily on a context-aware "Range" utility. This utility allows you to work efficiently with text selections based on various conditions, in a variety of contexts, making coding and editing more intuitive and productive. Welcome to **u.nvim** a powerful Lua library designed to enhance your text manipulation experience in NeoVim, focusing primarily on a context-aware "Range" utility. This utility allows you to work efficiently with text selections based on various conditions, in a variety of contexts, making coding and editing more intuitive and productive.
This is meant to be used as a **library**, not a plugin. On its own, `text-tools.nvim` does nothing on its own. It is meant to be used by plugin authors, to make their lives easier based on the variety of utilities I found I needed while growing my NeoVim config. This is meant to be used as a **library**, not a plugin. On its own, `u.nvim` does nothing on its own. It is meant to be used by plugin authors, to make their lives easier based on the variety of utilities I found I needed while growing my NeoVim config.
## Features ## Features
@ -16,8 +16,8 @@ This is meant to be used as a **library**, not a plugin. On its own, `text-tools
Lazy: Lazy:
```lua ```lua
-- Setting `lazy = true` ensures that the library is only loaded -- Setting `lazy = true` ensures that the library is only loaded
-- when `require 'tt.<utility>' is called. -- when `require 'u.<utility>' is called.
{ 'jrop/text-tools.nvim', lazy = true } { 'jrop/u.nvim', lazy = true }
``` ```
## Usage ## Usage
@ -31,7 +31,7 @@ I love NeoVim. I am coming to love Lua. I don't like 1-based indices; perhaps I
The `Range` utility is the main feature upon which most other things in this library are built, aside from a few standalone utilities. Ranges can be constructed manually, or preferably, obtained based on a variety of contexts. The `Range` utility is the main feature upon which most other things in this library are built, aside from a few standalone utilities. Ranges can be constructed manually, or preferably, obtained based on a variety of contexts.
```lua ```lua
local Range = require 'tt.range' local Range = require 'u.range'
local start = Pos.new(0, 0, 0) -- Line 1, first column local start = Pos.new(0, 0, 0) -- Line 1, first column
local stop = Pos.new(0, 2, 0) -- Line 3, first column local stop = Pos.new(0, 2, 0) -- Line 3, first column
@ -109,7 +109,7 @@ range:replace(nil)
Define custom (dot-repeatable) key mappings for text objects: Define custom (dot-repeatable) key mappings for text objects:
```lua ```lua
local opkeymap = require 'tt.opkeymap' local opkeymap = require 'u.opkeymap'
-- invoke this function by typing, for example, `<leader>riw`: -- invoke this function by typing, for example, `<leader>riw`:
-- `range` will contain the bounds of the motion `iw`. -- `range` will contain the bounds of the motion `iw`.
@ -123,7 +123,7 @@ end)
To write code with indentation, use the `CodeWriter` class: To write code with indentation, use the `CodeWriter` class:
```lua ```lua
local CodeWriter = require 'tt.codewriter' local CodeWriter = require 'u.codewriter'
local cw = CodeWriter.new() local cw = CodeWriter.new()
cw:write('{') cw:write('{')
cw:indent(function(innerCW) cw:indent(function(innerCW)
@ -139,8 +139,8 @@ cw:write('}')
Simply by returning a `Range` or a `Pos`, you can easily and quickly define your own text objects: Simply by returning a `Range` or a `Pos`, you can easily and quickly define your own text objects:
```lua ```lua
local utils = require 'tt.utils' local utils = require 'u.utils'
local Range = require 'tt.range' local Range = require 'u.range'
-- Select whole file: -- Select whole file:
utils.define_text_object('ag', function() utils.define_text_object('ag', function()
@ -153,7 +153,7 @@ end)
Access and manipulate buffers easily: Access and manipulate buffers easily:
```lua ```lua
local Buffer = require 'tt.buffer' local Buffer = require 'u.buffer'
local buf = Buffer.current() local buf = Buffer.current()
buf:line_count() -- the number of lines in the current buffer buf:line_count() -- the number of lines in the current buffer
buf:get_option '...' buf:get_option '...'

View File

@ -1,4 +1,4 @@
local Range = require 'tt.range' local Range = require 'u.range'
---@class Buffer ---@class Buffer
---@field buf number ---@field buf number

View File

@ -1,4 +1,4 @@
local Buffer = require 'tt.buffer' local Buffer = require 'u.buffer'
---@class CodeWriter ---@class CodeWriter
---@field lines string[] ---@field lines string[]

View File

@ -1,21 +1,21 @@
local Range = require 'tt.range' local Range = require 'u.range'
local vim_repeat = require 'tt.repeat' local vim_repeat = require 'u.repeat'
---@type fun(range: Range): nil|(fun():any) ---@type fun(range: Range): nil|(fun():any)
local __TT__OpKeymapOpFunc_rhs = nil local __U__OpKeymapOpFunc_rhs = nil
--- This is the global utility function used for operatorfunc --- This is the global utility function used for operatorfunc
--- in opkeymap --- in opkeymap
---@type nil|fun(range: Range): fun():any|nil ---@type nil|fun(range: Range): fun():any|nil
---@param ty 'line'|'char'|'block' ---@param ty 'line'|'char'|'block'
-- selene: allow(unused_variable) -- selene: allow(unused_variable)
function __TT__OpKeymapOpFunc(ty) function __U__OpKeymapOpFunc(ty)
if __TT__OpKeymapOpFunc_rhs ~= nil then if __U__OpKeymapOpFunc_rhs ~= nil then
local range = Range.from_op_func(ty) local range = Range.from_op_func(ty)
local repeat_inject = __TT__OpKeymapOpFunc_rhs(range) local repeat_inject = __U__OpKeymapOpFunc_rhs(range)
vim_repeat.set(function() vim_repeat.set(function()
vim.o.operatorfunc = 'v:lua.__TT__OpKeymapOpFunc' vim.o.operatorfunc = 'v:lua.__U__OpKeymapOpFunc'
if repeat_inject ~= nil and type(repeat_inject) == 'function' then repeat_inject() end if repeat_inject ~= nil and type(repeat_inject) == 'function' then repeat_inject() end
vim_repeat.native_repeat() vim_repeat.native_repeat()
end) end)
@ -34,8 +34,8 @@ end
---@param opts? vim.keymap.set.Opts ---@param opts? vim.keymap.set.Opts
local function opkeymap(mode, lhs, rhs, opts) local function opkeymap(mode, lhs, rhs, opts)
vim.keymap.set(mode, lhs, function() vim.keymap.set(mode, lhs, function()
__TT__OpKeymapOpFunc_rhs = rhs __U__OpKeymapOpFunc_rhs = rhs
vim.o.operatorfunc = 'v:lua.__TT__OpKeymapOpFunc' vim.o.operatorfunc = 'v:lua.__U__OpKeymapOpFunc'
return 'g@' return 'g@'
end, vim.tbl_extend('force', opts or {}, { expr = true })) end, vim.tbl_extend('force', opts or {}, { expr = true }))
end end

View File

@ -1,5 +1,5 @@
local Pos = require 'tt.pos' local Pos = require 'u.pos'
local State = require 'tt.state' local State = require 'u.state'
local orig_on_yank = vim.highlight.on_yank local orig_on_yank = vim.highlight.on_yank
local on_yank_enabled = true; local on_yank_enabled = true;

View File

@ -24,7 +24,7 @@ local M = {}
---@param cmd string | fun(args: CmdArgs): any ---@param cmd string | fun(args: CmdArgs): any
---@param opts? { nargs?: 0|1|'*'|'?'|'+'; range?: boolean|'%'|number; count?: boolean|number, addr?: string; completion?: string } ---@param opts? { nargs?: 0|1|'*'|'?'|'+'; range?: boolean|'%'|number; count?: boolean|number, addr?: string; completion?: string }
function M.ucmd(name, cmd, opts) function M.ucmd(name, cmd, opts)
local Range = require 'tt.range' local Range = require 'u.range'
opts = opts or {} opts = opts or {}
local cmd2 = cmd local cmd2 = cmd
@ -41,8 +41,8 @@ end
---@param fn fun(key_seq: string):Range|Pos|nil ---@param fn fun(key_seq: string):Range|Pos|nil
---@param opts? { buffer: number|nil } ---@param opts? { buffer: number|nil }
function M.define_text_object(key_seq, fn, opts) function M.define_text_object(key_seq, fn, opts)
local Range = require 'tt.range' local Range = require 'u.range'
local Pos = require 'tt.pos' local Pos = require 'u.pos'
if opts ~= nil and opts.buffer == 0 then opts.buffer = vim.api.nvim_get_current_buf() end if opts ~= nil and opts.buffer == 0 then opts.buffer = vim.api.nvim_get_current_buf() end
@ -60,7 +60,7 @@ function M.define_text_object(key_seq, fn, opts)
vim.keymap.set({ 'x' }, key_seq, handle_visual, opts and { buffer = opts.buffer } or nil) vim.keymap.set({ 'x' }, key_seq, handle_visual, opts and { buffer = opts.buffer } or nil)
local function handle_normal() local function handle_normal()
local State = require 'tt.state' local State = require 'u.state'
-- enter visual mode: -- enter visual mode:
vim.cmd { cmd = 'normal', args = { 'v' }, bang = true } vim.cmd { cmd = 'normal', args = { 'v' }, bang = true }
@ -86,6 +86,25 @@ function M.define_text_object(key_seq, fn, opts)
vim.keymap.set({ 'o' }, key_seq, handle_normal, opts and { buffer = opts.buffer } or nil) vim.keymap.set({ 'o' }, key_seq, handle_normal, opts and { buffer = opts.buffer } or nil)
end end
---@type fun(): nil|(fun():any)
local __U__RepeatableOpFunc_rhs = nil
--- This is the global utility function used for operatorfunc
--- in repeatablemap
---@type nil|fun(range: Range): fun():any|nil
-- selene: allow(unused_variable)
function __U__RepeatableOpFunc()
if __U__RepeatableOpFunc_rhs ~= nil then __U__RepeatableOpFunc_rhs() end
end
function M.repeatablemap(mode, lhs, rhs, opts)
vim.keymap.set(mode, lhs, function()
__U__RepeatableOpFunc_rhs = rhs
vim.o.operatorfunc = 'v:lua.__U__RepeatableOpFunc'
return 'g@ '
end, vim.tbl_extend('force', opts or {}, { expr = true }))
end
function M.get_editor_dimensions() function M.get_editor_dimensions()
local w = 0 local w = 0
local h = 0 local h = 0

View File

@ -1,4 +1,4 @@
local Buffer = require 'tt.buffer' local Buffer = require 'u.buffer'
local withbuf = loadfile './spec/withbuf.lua'() local withbuf = loadfile './spec/withbuf.lua'()
describe('Buffer', function() describe('Buffer', function()

View File

@ -1,4 +1,4 @@
local CodeWriter = require 'tt.codewriter' local CodeWriter = require 'u.codewriter'
describe('CodeWriter', function() describe('CodeWriter', function()
it('should write with indentation', function() it('should write with indentation', function()

View File

@ -1,4 +1,4 @@
local Pos = require 'tt.pos' local Pos = require 'u.pos'
local withbuf = loadfile './spec/withbuf.lua'() local withbuf = loadfile './spec/withbuf.lua'()
describe('Pos', function() describe('Pos', function()

View File

@ -1,5 +1,5 @@
local Range = require 'tt.range' local Range = require 'u.range'
local Pos = require 'tt.pos' local Pos = require 'u.pos'
local withbuf = loadfile './spec/withbuf.lua'() local withbuf = loadfile './spec/withbuf.lua'()
describe('Range', function() describe('Range', function()