-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vim: Tab in Present hops between links
Due to nvim-treesitter/nvim-treesitter-textobjects#479, I can't use nvim-treesitter-textobjects, but this is actually quite simple… :-)
- Loading branch information
Showing
6 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
...fig/nvim/lua/init/lib/follow-md-links.lua → ...fig/nvim/lua/init/lib/follow_md_links.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
local ts_lib = require'init.lib.treesitter' | ||
|
||
local M = {} | ||
M.opts = {} | ||
|
||
local function text_objects(captures) | ||
local objects = ts_lib.text_objects() | ||
local jump_targets = {} | ||
|
||
for _, object in ipairs(objects or {}) do | ||
if not captures or vim.tbl_contains(captures, object.capture) then | ||
for _, node in ipairs(object.nodes) do | ||
local row, col = node:range() | ||
local jump_target = { | ||
window = 0, | ||
buffer = 0, | ||
cursor = { | ||
row = row + 1, | ||
col = col, | ||
}, | ||
length = 0, | ||
} | ||
table.insert(jump_targets, jump_target) | ||
-- FIXME: filter out duplicates and invisible targets | ||
end | ||
end | ||
end | ||
|
||
return { | ||
jump_targets = jump_targets, | ||
} | ||
end | ||
|
||
function M.text_objects(captures, opts) | ||
local hop = require'hop' | ||
|
||
opts = setmetatable(opts or {}, { __index = M.opts }) | ||
hop.hint_with(function(_opts) | ||
return text_objects(captures) | ||
end, opts) | ||
end | ||
|
||
function M.register(opts) | ||
M.opts = opts | ||
vim.api.nvim_create_user_command('HopTextObjects', function() | ||
M.text_objects() | ||
end, {}) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local ts = vim.treesitter | ||
|
||
local M = {} | ||
|
||
function M.parse() | ||
local ok, parser = pcall(ts.get_parser) | ||
if ok then | ||
local syntax_trees = parser:parse(true) | ||
return parser, syntax_trees[1]:root() | ||
end | ||
end | ||
|
||
local function text_objects(root_parser) | ||
local objects = {} | ||
|
||
root_parser:for_each_tree(function(tree, parser) | ||
local query = ts.query.get(parser:lang(), 'textobjects') | ||
for _, match, _metadata in query:iter_matches(tree:root(), 0, nil, nil, { all = true }) do | ||
for id, nodes in pairs(match) do | ||
table.insert(objects, { | ||
capture = query.captures[id], | ||
nodes = nodes, | ||
}) | ||
end | ||
end | ||
end) | ||
|
||
return objects | ||
end | ||
|
||
function M.text_objects() | ||
local parser = M.parse() | ||
if parser then | ||
return text_objects(parser) | ||
else | ||
return {} | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
require'hop'.setup { | ||
extensions = { | ||
'hop-yank', | ||
'hop-treesitter', | ||
'init.lib.hop_treesitter_objects' | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters