Compare commits
No commits in common. "2d2d177c5163d233157de9ab0069a5d5d7ac0f05" and "1c1015d95f54d0c5e216193615be3896053b1b4f" have entirely different histories.
2d2d177c51
...
1c1015d95f
7 changed files with 62 additions and 118 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "vim/pack/git/start/packer.nvim"]
|
||||
path = vim/pack/git/start/packer.nvim
|
||||
url = https://github.com/wbthomason/packer.nvim
|
|
@ -1,4 +1,3 @@
|
|||
{
|
||||
"runtime.version": "Lua 5.1",
|
||||
"diagnostics.globals": ["vim"]
|
||||
}
|
||||
|
|
61
vim/lua/matcha.lua
Normal file
61
vim/lua/matcha.lua
Normal file
|
@ -0,0 +1,61 @@
|
|||
local function nextcol(state)
|
||||
local from, to = state.str:find(state.pattern, state.last)
|
||||
if from then
|
||||
state.last = to+1
|
||||
return from, to
|
||||
end
|
||||
end
|
||||
|
||||
local function colmatch(str, pattern)
|
||||
return nextcol, {str=str,pattern=pattern,last=0}
|
||||
end
|
||||
|
||||
local function findLocations(args)
|
||||
local files = vim.fs.find(function(file)
|
||||
if #args>1 then
|
||||
for _, pattern in ipairs(args), args, 1 do
|
||||
if vim.fs.basename(file):find(pattern) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end, {
|
||||
limit=math.huge;
|
||||
type="file";
|
||||
})
|
||||
|
||||
local locations = {}
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
local lnum = 0
|
||||
for line in io.lines(file) do
|
||||
lnum = lnum + 1
|
||||
for from, to in colmatch(line, args[1]) do
|
||||
table.insert(locations, {
|
||||
filename = file;
|
||||
lnum = lnum;
|
||||
col = from;
|
||||
end_col = to;
|
||||
text = line:sub(from, to)
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return locations
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("Matcha", function(params)
|
||||
vim.fn.setqflist(findLocations(params.fargs))
|
||||
vim.cmd("copen")
|
||||
vim.cmd("crewind")
|
||||
end, {nargs="+"})
|
||||
|
||||
vim.api.nvim_create_user_command("MatchaLocal", function(params)
|
||||
vim.fn.setloclist(0, findLocations(params.farts))
|
||||
vim.cmd("lopen")
|
||||
vim.cmd("lrewind")
|
||||
end, {nargs="+"})
|
|
@ -1 +0,0 @@
|
|||
Subproject commit ea0cc3c59f67c440c5ff0bbe4fb9420f4350b9a3
|
|
@ -1,61 +1 @@
|
|||
local function nextcol(state)
|
||||
local from, to = state.str:find(state.pattern, state.last)
|
||||
if from then
|
||||
state.last = to+1
|
||||
return from, to
|
||||
end
|
||||
end
|
||||
|
||||
local function colmatch(str, pattern)
|
||||
return nextcol, {str=str,pattern=pattern,last=0}
|
||||
end
|
||||
|
||||
local function findLocations(args)
|
||||
local files = vim.fs.find(function(file)
|
||||
if #args>1 then
|
||||
for _, pattern in ipairs(args), args, 1 do
|
||||
if vim.fs.basename(file):find(pattern) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end, {
|
||||
limit=math.huge;
|
||||
type="file";
|
||||
})
|
||||
|
||||
local locations = {}
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
local lnum = 0
|
||||
for line in io.lines(file) do
|
||||
lnum = lnum + 1
|
||||
for from, to in colmatch(line, args[1]) do
|
||||
table.insert(locations, {
|
||||
filename = file;
|
||||
lnum = lnum;
|
||||
col = from;
|
||||
end_col = to;
|
||||
text = line:sub(from, to)
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return locations
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("Matcha", function(params)
|
||||
vim.fn.setqflist(findLocations(params.fargs))
|
||||
vim.cmd("copen")
|
||||
vim.cmd("crewind")
|
||||
end, {nargs="+"})
|
||||
|
||||
vim.api.nvim_create_user_command("MatchaLocal", function(params)
|
||||
vim.fn.setloclist(0, findLocations(params.farts))
|
||||
vim.cmd("lopen")
|
||||
vim.cmd("lrewind")
|
||||
end, {nargs="+"})
|
||||
require 'matcha'
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
-- A simple per-session task stack.
|
||||
-- Allows pushing locations with a note and returning to them later.
|
||||
|
||||
local ns = vim.api.nvim_create_namespace("stacc")
|
||||
|
||||
local locations = {}
|
||||
|
||||
local stacc = {}
|
||||
|
||||
--- Pushes a new location to the stack
|
||||
--- @param description string A message to display when returning to this location
|
||||
function stacc.push(description)
|
||||
local bufnr = vim.fn.bufnr()
|
||||
local line, column = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
line = line - 1 -- 0-based :help api-indexing
|
||||
local id = vim.api.nvim_buf_set_extmark(bufnr, ns, line, column, {})
|
||||
table.insert(locations, {bufnr, id, description, vim.fn.line(".")})
|
||||
end
|
||||
|
||||
--- Pops a given number of items from the task stack
|
||||
--- Jumps to the last removed item and displays its description
|
||||
--- @param count number How many items to pop from the stack
|
||||
--- @return string description The description of the current task
|
||||
function stacc.pop(count)
|
||||
if count > #locations then
|
||||
error("stack only has "..#locations.." elements.")
|
||||
end
|
||||
local description
|
||||
local final = vim.api.nvim_win_get_cursor(0)
|
||||
for _=1, count do
|
||||
local bufnr, id
|
||||
bufnr, id, description = unpack(table.remove(locations))
|
||||
final = vim.api.nvim_buf_get_extmark_by_id(bufnr, ns, id, {})
|
||||
vim.api.nvim_buf_del_extmark(bufnr, ns, id)
|
||||
final[1] = final[1] + 1 -- Make line 1-indexed
|
||||
final.bufnr = bufnr
|
||||
end
|
||||
vim.api.nvim_set_current_buf(final.bufnr or 0)
|
||||
final.bufnr = nil
|
||||
vim.api.nvim_win_set_cursor(0, final)
|
||||
return description
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("StaccPush", function(params)
|
||||
stacc.push(params.args)
|
||||
end, {nargs="?"})
|
||||
|
||||
vim.api.nvim_create_user_command("StaccPop", function(params)
|
||||
local message = stacc.pop(tonumber(params.args) or 1)
|
||||
print(message)
|
||||
end, {nargs="?"})
|
1
vimrc
1
vimrc
|
@ -4,7 +4,6 @@
|
|||
" Set up the runtime path
|
||||
set runtimepath=$VIMRUNTIME,$HOME/.config/nvim,$HOME/.vim
|
||||
let &rtp=&rtp.','.expand('<sfile>:p:h').'/vim'
|
||||
let &rtp=&rtp.','.expand('<sfile>:p:h').'/vim/pack/*/start/*'
|
||||
|
||||
if has("nvim")
|
||||
lua require("pack/setup")
|
||||
|
|
Loading…
Reference in a new issue