jinh0 / eyeliner.nvim

👀 Move faster with unique f/F indicators.
441 stars 14 forks source link

Feature request: nvim-treesitter-textobjects compatibility #46

Closed mawkler closed 1 month ago

mawkler commented 6 months ago

nvim-treesitter-textobjects lets you repeat moves with ;/,

You can make the movements repeatable like ; and ,.

local ts_repeat_move = require "nvim-treesitter.textobjects.repeatable_move"

-- Repeat movement with ; and ,
-- ensure ; goes forward and , goes backward regardless of the last direction
vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next)
vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous)

-- vim way: ; goes to the direction you were moving.
-- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move)
-- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite)

-- Optionally, make builtin f, F, t, T also repeatable with ; and ,
vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f)
vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F)
vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t)
vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T)

This config clashes with eyeliner.nvim. Would it be possible for eyeliner.nvim to add compatibility for this?

jinh0 commented 1 month ago

Hi @mawkler , (I know this is a really late response) but I've now added the ability to disable eyeliner from automatically mapping f/F/t/T, and I've also exposed eyeliner's highlight function as require("eyeliner").highlight({ forward = true }). I've added more information to the README .

Thanks for the feature request! Let me know if there are any issues!

mawkler commented 1 month ago

Thank you very much @jinh0! However, require('eyeliner').highlight doesn't seem to be properly exposed. When I run :=require('eyeliner').highlight on 2ee9e64d4c8133da1131edf0e64641e32dd16396 i get nil.

Also, your changes seem to have introduced a couple of small regressions:

I noticed that 1d14a3d328f6c44e74e8a335248e50e2a1a15b5f forces the highlights. That overrides my EyelinerPrimary, EyelinerSecondary and EyelinerDimmed highlights that I've set with my colorscheme when eyeliner.nvim gets lazy loaded.

Pressing <Esc> to cancel after pressing t/T/f/F with highlight_on_key = true no longer clears the highlights. I have to move the cursor in order for the highlights to dissappear.

When lazy loading eyeliner.nvim on pressing t/T/f/F it no longer loads properly. Even after pressing one of those keys, the key mappings don't get created (:map f show "No mapping found"). I seeem to have to switch to another buffer and back for the key mappings to appear. Here's a minimal config to reproduce the issue (I'm on Neovim v0.11.0-dev-230+g0231265c8 btw):

Click to expand ```lua local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then vim.fn.system({ 'git', 'clone', '--filter=blob:none', 'https://github.com/folke/lazy.nvim.git', '--branch=stable', -- latest stable release lazypath, }) end vim.opt.rtp:prepend(lazypath) vim.keymap.set('n', '', vim.cmd.quit) vim.api.nvim_set_hl(0, 'LeapBackdrop', { link = 'Comment' }) local mode = { 'n', 'x', 'o' } require('lazy').setup({ 'jinh0/eyeliner.nvim', keys = { { 't', mode = mode }, { 'T', mode = mode }, { 'f', mode = mode }, { 'F', mode = mode }, }, opts = { highlight_on_key = true, } }) ```
jinh0 commented 1 month ago

Hi @mawkler , shoot! I rushed the changes last night, and the highlight function wasn't even exposed properly 🤦 . require("eyeliner").highlight should now work in commit 9fcd97248e05582d896c437f20b1934723481c2d . I promise it should be working now!

Regarding the colorscheme thing, yeah that was me being stupid, thanks for catching that! I've reverted it: 0a7edd0aef409d3a647160eed95e7931ff6e4af8 .

Pressing to cancel after pressing t/T/f/F with highlight_on_key = true no longer clears the highlights. I have to move the cursor in order for the highlights to disappear.

Yeah, I had to change how clearing highlights work: I separated the highlight and clearing highlights functionality from the keypress. "It's a feature, not a bug". It's not ideal.... we should make this a separate issue.

Regarding lazy loading on key press, for now, can you load eyeliner.nvim at event = "BufReadPre"? That's what I've been doing, and that's been working fine. We can raise a separate issue about keypress lazy loading.