windwp / nvim-autopairs

autopairs for neovim written in lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pairs execution based on treesitter **context** (i.e. lang parser at cursor)

kamalsacranie opened this issue · comments

Chào anh

Is there any interest in having similar functionality to how for example luasnip or nvim-context-comment carry out functionality based on which treesitter language context you are in? To illustrate how this might work with a rule for autopairs, take for example the following markdown text where we are injecting python highlighting with treesitter between the ```s. Let's say I have a rule to pair "*":

Some random markdown text blah blah. This is *|* where a pair would go:

```python
my_expr = 1 * 4 # I.e. this start should not pair because we are in a python context
```

I have implemented a simple solution where I just get the context under my cursor in insert mode and compare that context to the specified filetypes for the pair rule. If it matches we pair. I wanted to see if anyway was interested in the functionality before putting time in to make a more robust solution and submit a PR. I also wanted to check how @windwp would like the solution to be implemented if at all.

nếu viết thêm 1 cái condition thì dễ .
chứ apply cho tất cả các rule thì hơi khó bởi có trường hợp rule cần mapping key khác với key của file chính.

Sorry anh, Tiếng Việt một chút 😅. Unfortunately, I can only speak English

So would this sort of implementation not be feasible. Fork branch

if it work you can make a PR