pears.nvim icon indicating copy to clipboard operation
pears.nvim copied to clipboard

small issue in tex files

Open kyazdani42 opened this issue 3 years ago • 24 comments

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.

kyazdani42 avatar Apr 06 '21 19:04 kyazdani42

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.

steelsojka avatar Apr 06 '21 20:04 steelsojka

I also think the issue has to do with the contexts/extmarks. I need better detection for it.

steelsojka avatar Apr 06 '21 20:04 steelsojka

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 :)

kyazdani42 avatar Apr 07 '21 18:04 kyazdani42

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 ;)

steelsojka avatar Apr 08 '21 13:04 steelsojka

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 avatar Apr 08 '21 14:04 theHamsta

@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 avatar Apr 08 '21 14:04 steelsojka

@steelsojka how would I retain ability to confirm compe's selection of completion menu with CR?

gegoune avatar Apr 08 '21 14:04 gegoune

I'm not sure how compe confirmation is triggered. I would have to look into it's api docs.

steelsojka avatar Apr 08 '21 14:04 steelsojka

@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 )

theHamsta avatar Apr 08 '21 14:04 theHamsta

@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.

gegoune avatar Apr 08 '21 14:04 gegoune

@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.

steelsojka avatar Apr 08 '21 16:04 steelsojka

@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.

steelsojka avatar Apr 08 '21 16:04 steelsojka

@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

steelsojka avatar Apr 08 '21 16:04 steelsojka

First option seems simpler, thank you so much!

gegoune avatar Apr 08 '21 16:04 gegoune

No problem. Let me know if something doesn't work.

steelsojka avatar Apr 08 '21 17:04 steelsojka

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:

Untitled

gegoune avatar Apr 08 '21 17:04 gegoune

That should be working already. What does the config look like? What nvim version are you running?

steelsojka avatar Apr 08 '21 17:04 steelsojka

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.

kyazdani42 avatar Apr 08 '21 17:04 kyazdani42

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.

steelsojka avatar Apr 08 '21 17:04 steelsojka

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.

gegoune avatar Apr 08 '21 17:04 gegoune

oh ok. I think it's because it's falling into the should_expand logic to late. I'll take a look.

steelsojka avatar Apr 08 '21 17:04 steelsojka

@cloggier That issue should be fixed now.

steelsojka avatar Apr 08 '21 18:04 steelsojka

It is, thank you!

gegoune avatar Apr 08 '21 18:04 gegoune

@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!

theHamsta avatar Apr 08 '21 19:04 theHamsta