altermo / ultimate-autopair.nvim

A treesitter supported autopairing plugin with extensions, and much more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Triggers with backslashes

haoming-li-ling opened this issue · comments

I would like to add a pair \( \) for tex. However, { "\\(", "\\)", ft = { "tex" } }, does not work. Inputting \( does nothing; but inputting \\( produces \\(\). Why is this happening?

It is because ext.escape treats multi-character pairs as a single character, this issue will be solved in the next release.
Until then, you can disable escape with { "\\(", "\\)", ft = { "tex" } , noescape = true }

Thank you, that works!
However, I have another question. Now, when the pair is in place, and the cursor is at |, i.e., \(|\), pressing \ will bring me out of the pair. I want to disable this behavior, as in latex, it is often the case that I will input a command that starts with \ when I am in that position. How can I do that?

Currently, that is not easily possible.
Will implement it in the next release.

Ok, fixed, and the feature added in v0.6.0 (for more info read the Q&A)
(Note: To update to v0.6.0, remove the plugin totally and reinstall)

The problem with the new version now is that the rule you provided does not even work. In fact, the default quotes map for tex also doesn't work.

Fixed; the problem was that treesitter uses latex and not tex as languagetree:lang().
So replace {ft={'text'}} with {ft={'text','latex'}}`

I commented out the double quotes rule for tex from internal pairs, and tried to add this rule:

{ "`", "'", fly = true, ft = { "tex", "latex" } }

but this one doesn't work; why?

That's weird, cause it works with the minimal config:

vim.fn.system{'git','clone','--depth=1','https://github.com/altermo/ultimate-autopair.nvim',vim.fn.stdpath('data')..'/ultimate-autopair'}
vim.opt.runtimepath:append(vim.fn.stdpath('data')..'/ultimate-autopair')
require'ultimate-autopair'.setup{{'`',"'",fly=true,ft={'tex','latex'}}}
vim.cmd.setf'tex'

I located the plugin causing the issue. It is actually vimtex. Whenever vimtex is enabled, the ` rule does not work. However, I already disabled the auto-expanding snippets from vimtex that start with `, so I don't know why this is still happening. Working alongside vimtex would be ideal, since virtually everyone writing latex on vim uses it.

Additionally,

{ "`", "`", nft = { "tex", "latex" }, multiline = false }

and

{ "`", "'", fly = true, ft = { "tex", "latex" } }

cannot coexist. The former breaks the backspace behavior of the latter, despite the filetype specifications.

For the vimtex, I need a config to be able to search for what causes what.
And for the backspace, in what way does it break?

For the broken backspace, it deletes two `s at once, without deleting any 's. So

``|'' --backspace--> |''

Fixed; the problem was that only a select cases of backspace(/newline) ran through the filter and the rest ignored it.

Indeed fixed. Thanks!

Something more drastic I noticed with vimtex. It is not that the backtick rule doesn't work; it works, but it interprets the single quotes not on the current line as the ending character. And so, it does not insert the single quote on the same line. Then, when I delete the backtick, a single quote that is very far away from the backtick (on the lines below) gets deleted. I think the multiline behavior is erroneously enabled for this rule when vimtex is enabled.

Ok, setting multiline to false explicitly fixes it. It is still puzzling; what is the default setting for multiline? Why vimtex enabled means multiline on, and vimtex disabled means multiline off, even though I didn't set the multiline option at all in the original rule? Is it perhaps the timing of the filtetype detection that is affected by vimtex, which in turn affects whether the explicit multiline = false option from the nft = { "tex", "latex" } backtick rule gets transferred to the ft = { "tex", "latex" } backtick rule?

The default for multiline is true.
Can you give a minimal config so that I can also research it?