pears.nvim
pears.nvim copied to clipboard
small issue in tex files
Hey ! not sure why but in tex files when you try to type ' at the end of a line sometimes it does not work. i'll pinpoint the issue myself and fix it if i can.
Yeah this is still very early, so I'm not expecting it to all really work yet. I just did a bunch of refactoring also.... I will add this scenario to my testing.
I also think the issue has to do with the contexts/extmarks. I need better detection for it.
i guess so :) usually the plugin is behaving perfectly on programming language files, but on other files it doesn't (you might not need auto pairs on filetypes where you write prose basically). I'll just disable that in my config, this has nothing to do with your plugin. I haven't seen this error in ts/js/jsx/tsx/lua files though these are behaving very nicely :)
Yeah, I don't have any sort of filetype specific support yet. Once I get the algorithms down, I will add all that fun configuration ;)
Will it be possible to configure to only expand the pair when a whitespace or a EOL is the next character? I sometimes want to surround some ranges with pairs manually and would like to have the auto-pair behavior for new code.
@theHamsta Can you give me an example of what you mean? Right now, all pairs have a should_expand
function that gets called to determine if it should expand. I use this for '
so it won't expand when use in a word like aren't
. You could easily tap into this.... even though the configuration isn't documented yet.
@steelsojka how would I retain ability to confirm compe's selection of completion menu with CR
?
I'm not sure how compe confirmation is triggered. I would have to look into it's api docs.
@steelsojka nice, I guess then I'll just implement this for my personal config.
I would like something like (|
is cursor position)
bla bla bla (|
should expand but
bla (|bla bla
should not since I'm still thinking about where I want to put )
@steelsojka Currently I have:
local npairs = require("nvim-autopairs")
OnEnter = function()
if vim.fn.pumvisible() == 1 then
return vim.fn["compe#confirm"]("<CR>")
else
return npairs.check_break_line_char()
end
end
map("i", "<CR>", "v:lua.OnEnter()", {expr = true})
binding compe and autopairs together.
@theHamsta Yeah that makes sense. I do the same thing for '
. You can do
require "pears".setup(function(conf)
conf.pairs("(", {
should_expand = function(bufnr)
local Utils = require("pears.utils")
local _, after = Utils.get_surrounding_chars(bufnr)
return not after or after == " "
end
})
end)
I'm gonna add some more utils that makes this a little nicer for overridding. This will give you the idea though.
@cloggier You should be able to do
require "pears".setup(function(conf)
conf.on_enter(function(exec)
if vim.fn.pumvisible() == 1 then
vim.fn["compe#confirm"]("<CR>")
else
exec()
end
end)
end)
The exec
function (or whatever you want to name it) just calls the enter handler within pears.
@cloggier Or if you don't want to use the override handler you can just call the method directly
local pears = require("pears")
OnEnter = function()
if vim.fn.pumvisible() == 1 then
return vim.fn["compe#confirm"]("<CR>")
else
pears.handle_enter(vim.api.nvim_get_current_buf())
end
end
map("i", "<CR>", "v:lua.OnEnter()", {expr = true})
but you'll need to disable the override binding by setting conf.expand_on_enter(false)
in the config handler for pears. This prevents pears from setting up the <CR> keymapping
First option seems simpler, thank you so much!
No problem. Let me know if something doesn't work.
Enter works perfectly as far as I can see, but came across insertion of extra pair when closing - would expect it to jump over instead:
That should be working already. What does the config look like? What nvim version are you running?
had a lot of these breakages today too with the latest version of neovim and all plugins. Basically in jsx files everything would break, like typing <
would enter >
which i don't want since i use nvim-autotag x) but i guess this can be configurable too.
Yeah, I've actively been changing stuff through out the day... including breaking some things. Right now, this plugin isn't aware of any syntax regions. That will come next.
That should be working already. What does the config look like? What nvim version are you running?
Everything is latest versions (nvim, pears) - upgraded just now. Still getting that behaviour on '
, but not on "
.
Config is only what you have given me above for CR
.
oh ok. I think it's because it's falling into the should_expand
logic to late. I'll take a look.
@cloggier That issue should be fixed now.
It is, thank you!
@steelsojka just wanted to give a short note that I'm fully happy with
function M.has_trailing_whitespaces(bufnr)
local _, after = M.get_surrounding_chars(bufnr, nil, 1)
return after == '' or string.match(after, "%W")
end
for all pairs. Really nice plugin!