Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6521bab7f6 | |||
| 44a97b5baa | |||
| 7fb60add94 | |||
| 79499e898c | |||
| de01a95cdc | |||
| c87cc7c387 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.src.rock
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
# u.nvim
|
# u.nvim
|
||||||
|
|
||||||
|
🚨🚨 **BRANCH NOTICE: further development is happening on the `v3` branch. In the future, `v3` will be merged into `master`. If you want to pin to an older version of this library, please refer to a specific commit, or the `v1` branch.** 🚨🚨
|
||||||
|
|
||||||
|
🚨🚨[CLICK HERE FOR v3](https://github.com/jrop/u.nvim/tree/v3)🚨🚨
|
||||||
|
|
||||||
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.
|
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, `u.nvim` does nothing. 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. 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.
|
||||||
|
|||||||
@@ -108,14 +108,24 @@ function M.setup()
|
|||||||
if from_cn < 32 or from_cn > 126 then return end
|
if from_cn < 32 or from_cn > 126 then return end
|
||||||
local from_c = vim.fn.nr2char(from_cn)
|
local from_c = vim.fn.nr2char(from_cn)
|
||||||
local from = surrounds[from_c] or { left = from_c, right = from_c }
|
local from = surrounds[from_c] or { left = from_c, right = from_c }
|
||||||
|
local function get_fresh_arange()
|
||||||
local arange = Range.from_text_object('a' .. from_c, { user_defined = true })
|
local arange = Range.from_text_object('a' .. from_c, { user_defined = true })
|
||||||
if arange == nil then return nil end
|
if arange == nil then return nil end
|
||||||
|
if from_c == 'q' then
|
||||||
|
from.left = arange.start:char()
|
||||||
|
from.right = arange.stop:char()
|
||||||
|
end
|
||||||
|
return arange
|
||||||
|
end
|
||||||
|
|
||||||
|
local arange = get_fresh_arange()
|
||||||
|
if arange == nil then return nil end
|
||||||
|
|
||||||
local hl_info1 = Range.new(arange.start, arange.start, 'v'):highlight('IncSearch', { priority = 999 })
|
local hl_info1 = Range.new(arange.start, arange.start, 'v'):highlight('IncSearch', { priority = 999 })
|
||||||
local hl_info2 = Range.new(arange.stop, arange.stop, 'v'):highlight('IncSearch', { priority = 999 })
|
local hl_info2 = Range.new(arange.stop, arange.stop, 'v'):highlight('IncSearch', { priority = 999 })
|
||||||
local hl_clear = function()
|
local hl_clear = function()
|
||||||
hl_info1.clear()
|
if hl_info1 then hl_info1.clear() end
|
||||||
hl_info2.clear()
|
if hl_info2 then hl_info2.clear() end
|
||||||
end
|
end
|
||||||
|
|
||||||
local to = prompt_for_bounds()
|
local to = prompt_for_bounds()
|
||||||
@@ -123,6 +133,10 @@ function M.setup()
|
|||||||
if to == nil then return end
|
if to == nil then return end
|
||||||
|
|
||||||
vim_repeat.run(function()
|
vim_repeat.run(function()
|
||||||
|
-- Re-fetch the arange, just in case this action is being repeated:
|
||||||
|
arange = get_fresh_arange()
|
||||||
|
if arange == nil then return nil end
|
||||||
|
|
||||||
if from_c == 't' then
|
if from_c == 't' then
|
||||||
-- For tags, we want to replace the inner text, not the tag:
|
-- For tags, we want to replace the inner text, not the tag:
|
||||||
local irange = Range.from_text_object('i' .. from_c, { user_defined = true })
|
local irange = Range.from_text_object('i' .. from_c, { user_defined = true })
|
||||||
@@ -219,11 +233,11 @@ function M.setup()
|
|||||||
bounds = _G.my_surround_bounds
|
bounds = _G.my_surround_bounds
|
||||||
else
|
else
|
||||||
local prompted_bounds = prompt_for_bounds()
|
local prompted_bounds = prompt_for_bounds()
|
||||||
if prompted_bounds == nil then return hl_info.clear() end
|
if prompted_bounds == nil and hl_info then return hl_info.clear() end
|
||||||
bounds = prompted_bounds
|
if prompted_bounds then bounds = prompted_bounds end
|
||||||
end
|
end
|
||||||
|
|
||||||
hl_info.clear()
|
if hl_info then hl_info.clear() end
|
||||||
do_surround(range, bounds)
|
do_surround(range, bounds)
|
||||||
-- selene: allow(global_usage)
|
-- selene: allow(global_usage)
|
||||||
_G.my_surround_bounds = nil
|
_G.my_surround_bounds = nil
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ function Range.from_text_object(text_obj, opts)
|
|||||||
|
|
||||||
local prev_on_yank_enabled = on_yank_enabled
|
local prev_on_yank_enabled = on_yank_enabled
|
||||||
on_yank_enabled = false
|
on_yank_enabled = false
|
||||||
vim.cmd.normal {
|
vim.cmd {
|
||||||
cmd = 'normal',
|
cmd = 'normal',
|
||||||
bang = not opts.user_defined,
|
bang = not opts.user_defined,
|
||||||
args = { '""y' .. text_obj },
|
args = { '""y' .. text_obj },
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function _normal(cmd) vim.cmd.normal { cmd = 'normal', args = { cmd }, bang = true } end
|
local function _normal(cmd) vim.cmd { cmd = 'normal', args = { cmd }, bang = true } end
|
||||||
|
|
||||||
M.native_repeat = function() _normal '.' end
|
M.native_repeat = function() _normal '.' end
|
||||||
M.native_undo = function() _normal 'u' end
|
M.native_undo = function() _normal 'u' end
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ function State:track_mark(mark) self.marks[mark] = vim.api.nvim_buf_get_mark(sel
|
|||||||
function State:track_pos(pos) self.positions[pos] = vim.fn.getpos(pos) end
|
function State:track_pos(pos) self.positions[pos] = vim.fn.getpos(pos) end
|
||||||
|
|
||||||
---@param nm string
|
---@param nm string
|
||||||
function State:track_global_option(nm) self.global_options[nm] = vim.g[nm] end
|
function State:track_global_option(nm) self.global_options[nm] = vim.go[nm] end
|
||||||
|
|
||||||
function State:track_winview() self.win_view = vim.fn.winsaveview() end
|
function State:track_winview() self.win_view = vim.fn.winsaveview() end
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ function State:restore()
|
|||||||
vim.keymap.set(map.mode, map.lhs, map.rhs, { buffer = map.buffer })
|
vim.keymap.set(map.mode, map.lhs, map.rhs, { buffer = map.buffer })
|
||||||
end
|
end
|
||||||
for nm, val in pairs(self.global_options) do
|
for nm, val in pairs(self.global_options) do
|
||||||
vim.g[nm] = val
|
vim.go[nm] = val
|
||||||
end
|
end
|
||||||
if self.win_view ~= nil then vim.fn.winrestview(self.win_view) end
|
if self.win_view ~= nil then vim.fn.winrestview(self.win_view) end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ function M.define_text_object(key_seq, fn, opts)
|
|||||||
local p = range_or_pos --[[@as Pos]]
|
local p = range_or_pos --[[@as Pos]]
|
||||||
State.run(0, function(s)
|
State.run(0, function(s)
|
||||||
s:track_global_option 'eventignore'
|
s:track_global_option 'eventignore'
|
||||||
vim.opt_global.eventignore = 'all'
|
vim.go.eventignore = 'all'
|
||||||
|
|
||||||
-- insert a single space, so we can select it:
|
-- insert a single space, so we can select it:
|
||||||
vim.api.nvim_buf_set_text(0, p.lnum, p.col, p.lnum, p.col, { ' ' })
|
vim.api.nvim_buf_set_text(0, p.lnum, p.col, p.lnum, p.col, { ' ' })
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local function withbuf(lines, f)
|
local function withbuf(lines, f)
|
||||||
vim.opt_global.swapfile = false
|
vim.go.swapfile = false
|
||||||
|
|
||||||
vim.cmd.new()
|
vim.cmd.new()
|
||||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
|
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
|
||||||
|
|||||||
24
u.nvim-0.2.0-1.rockspec
Normal file
24
u.nvim-0.2.0-1.rockspec
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package = "u.nvim"
|
||||||
|
version = "0.2.0-1"
|
||||||
|
source = {
|
||||||
|
url = "git+https://github.com/jrop/u.nvim"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
summary = "nvim – a powerful Lua library designed to enhance your text manipulation experience in NeoVim, focusing primarily on a context-aware \"Range\" utility.",
|
||||||
|
detailed = "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.",
|
||||||
|
homepage = "https://github.com/jrop/u.nvim",
|
||||||
|
license = "MIT"
|
||||||
|
}
|
||||||
|
build = {
|
||||||
|
type = "builtin",
|
||||||
|
modules = {
|
||||||
|
["u.buffer"] = "lua/u/buffer.lua",
|
||||||
|
["u.codewriter"] = "lua/u/codewriter.lua",
|
||||||
|
["u.opkeymap"] = "lua/u/opkeymap.lua",
|
||||||
|
["u.pos"] = "lua/u/pos.lua",
|
||||||
|
["u.range"] = "lua/u/range.lua",
|
||||||
|
["u.repeat"] = "lua/u/repeat.lua",
|
||||||
|
["u.state"] = "lua/u/state.lua",
|
||||||
|
["u.utils"] = "lua/u/utils.lua"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user