Comments (5)
Just in case I did something else wrong, here's the setup code I was using.
require("autoclose").setup({
keys = {
["“"] = {
close = true,
escape = false,
pair = "“”",
enabled_filetypes = { "markdown", "text", "mail" },
},
["”"] = {
close = false,
escape = true,
pair = "“”",
enabled_filetypes = { "markdown", "text", "mail" },
},
},
})
from autoclose.nvim.
I also think that my problem is somewhat related to issues #39 and #23.
Yeah you are right.
I prefer this new way to config pair:
pair = { "(", ")" }
It would be great if you can open a PR to solve this! Just remember to add breaking change into commit messages (see conventional commit) so that user can know the change when updating plugins.
from autoclose.nvim.
It would be great if you can open a PR to solve this!
I apologize, but I was overly optimistic. After working on this for the past week, I've realized that the problems are a lot more complicated than I thought at first. So much of the current code relies on one character being equal to one byte, LuaJIT has no built-in way to deal with multibyte characters, and Neovim doesn't offer much support either.
I was able to get entering and escaping multibyte pairs to work, but I could not get deletion to work. (The problem is that if the key entered is, e.g., <BS>
, you can't know how many bytes to grab relative to the cursor position in order to get "two characters." I tried using vim.str_utf_pos
, but I couldn't get that to work for all positions on a line.) I may be missing something obvious, but I'm going to stop for now.
As for the other two issues, the more I thought about those, the harder they seemed to me. Those involve not individual characters (of whatever width), but truly multi-character groups. Since users will type those one character at a time, I can't see how to escape or delete those without changing this plugin almost entirely. (I think you'd need to track state and/or use regexes heavily in order to do that. Consider, e.g., multi-line comments inside of multi-character surroundings.)
tl;dr — this plugin is simple and works remarkably well for single-character ASCII pairs. Since that's most of what programmers need from an autoclose plugin, I'm going to try to stop worrying about multibyte or multi-character cases for now. I'll leave this open if you want, and I'll probably keep thinking about it (despite myself), but I doubt I'll work on it right now.
from autoclose.nvim.
Thanks for the attempts to solve this issue! It sounds complicated and this also not aligned with the philosophy of this plugin as I want to keep it minimal. I'll close the related issues and set them as wontfix.
from autoclose.nvim.
Naturally, after I said that I would stop thinking about the problem, I thought about it nonstop. After another day working on this, I have a version that supports multibyte characters. I will use this version for a week or two while I continue to try to clean up the code (which is ugly and may have edge cases I haven't thought of yet).
There is one problem with my solution. In documents with very long lines (e.g., in a markdown document where entire paragraphs are written as one line), then the code may repeatedly call vim.str_utf_pos
and build a lookup table of characters by their positions in the line. This is inefficient compared with line:sub(col, col + 1)
, but I can't see an alternative. Edit: since first making this comment, I was able to make the function that builds the lookup table cleaner. It's still less simple and efficient than line:sub(col, col + 1)
, but it's not terrible anymore. On the other hand, it now only works for insert mode. I think that's a reasonable trade-off since people probably don't need autoclosing for multibyte characters on the command line!
You're under no obligation, of course, but if you have thoughts about my current solution, please comment there or make suggestions. I will submit my solution as a PR after I've tested it further and used it for a few weeks.
from autoclose.nvim.
Related Issues (20)
- Changes that use autoclose break single-repeat (dot repeat) HOT 1
- Add an option to only trigger auto-close when Enter is pressed. HOT 1
- Support deleting with `<C-h>` HOT 2
- Pairing characters and strings HOT 1
- Disable identation HOT 1
- Disable autoclose in certain situations HOT 2
- Option to double space HOT 2
- Code formatter HOT 3
- Ignore specific keys for filetype HOT 2
- Make touch regex configurable HOT 1
- Does it possiable to add an option `enabled_filetypes`? HOT 1
- `<CR>` keybind is enabled in command mode by default HOT 2
- Backspace? HOT 1
- Consider documenting a short comparison to nvim-autopairs HOT 1
- Make disable_command_mode also a global option
- Make it possible to correct close the double string like /* HOT 1
- Need ability to assign a single keybinding to all escape situations HOT 1
- autoclose inserts a closing bracket even when editing a string HOT 2
- Add versioning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autoclose.nvim.