SUSTech-data / wildfire.nvim

wildfire burns treesitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Specify filetypes on which to disable plugin/mappings

niveK77pur opened this issue · comments

Issue

<CR> is by default mapped to starting and incrementing a selection. While this is a great default binding, it causes issues in quickfix windows. In a quickfix, <CR> moves the cursor to the selected entry, but this plugin's binding of <CR> raises an error, and does not move the cursor.

E5108: Error executing lua: /usr/share/nvim/runtime/lua/vim/treesitter.lua:190: attempt to index local 'node_or_r
ange' (a nil value)
stack traceback:
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:190: in function 'get_node_range'
        ...cal/share/nvim/lazy/wildfire.nvim/lua/wildfire/utils.lua:13: in function 'get_range'
        ...ocal/share/nvim/lazy/wildfire.nvim/lua/wildfire/init.lua:30: in function 'unsurround_coordinates'
        ...ocal/share/nvim/lazy/wildfire.nvim/lua/wildfire/init.lua:78: in function 'update_selection_by_node'
        ...ocal/share/nvim/lazy/wildfire.nvim/lua/wildfire/init.lua:96: in function 'init_by_node'
        ...ocal/share/nvim/lazy/wildfire.nvim/lua/wildfire/init.lua:104: in function <...ocal/share/nvim/lazy/wil
dfire.nvim/lua/wildfire/init.lua:101>

Therefore, it would be useful to specify a list of filetypes (i.e. qf for quickfix) on which to not set this mapping (or revert <CR> back to the original)

Workaround

I can manually run the following in a quickfix window, and then things will work as expected again.

:noremap <CR> <CR>

Or I can add an autocommand into my wildfire config as follows:

{
    'sustech-data/wildfire.nvim',
    event = 'VeryLazy',
    dependencies = { 'nvim-treesitter/nvim-treesitter' },
    config = function()
        require('wildfire').setup()

        local augroup_revert_cr = vim.api.nvim_create_augroup('revert_cr', {})

        vim.api.nvim_create_autocmd({ 'FileType' }, {
            group = augroup_revert_cr,
            pattern = { 'qf' },
            desc = "Revert wildfire's <CR> on filetypes",
            callback = function()
                vim.cmd('noremap <CR> <CR>')
            end,
        })
    end,
}

I would argue that the ability to specify filetypes for which to revert/disable the mapping is better than to hardcode the fix for quickfix alone. I can image that one might have already remapped <CR> for certain filetypes, which would require falling back to this autocommand for solving the issue.

On the offhand, one could instead/also specify a list of filetypes for which to enable the mappings.

This here is a perfectly reasonable workaround though, so I understand if there is no interest in addressing this particular issue.

Hello,
Thank you for bringing this to my attention. Could you please check if the linked PR is functioning correctly? I did try other approaches like https://github.com/anuvyklack/keymap-amend.nvim, but it turns out that the keymap system in neovim is somewhat clunky.

Another option is to use key mappings specific to this plugin, which is also the default behavior for treesitter. However, this can lead to conflicts with other plugins, which is, in fact, one of the reasons I created this plugin.

Thank you for addressing the issue! It seems to perfectly address the problem for the quickfix window! Even with the default configuration, which I see excludes qf by default!

{
    'sustech-data/wildfire.nvim',
    branch = 'feat/exclude_filetype',
    event = 'VeryLazy',
    dependencies = { 'nvim-treesitter/nvim-treesitter' },
    config = function()
        require('wildfire').setup()
    end,
}

And thanks for sharing, it's nice to hear you tried to make this plugin such that it stays out of trouble as much as possible! That plus it's simple premise definitely make it a nice addition to my workflow!

Thanks a lot for the work o7

(I'll leave closing the issue up to you once the feature has been merged into the main branch)

Feel free to reopen it if you encounter further issue as I havn't test that very carefully :)