Giter Site home page Giter Site logo

Comments (5)

telemachus avatar telemachus commented on June 7, 2024

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.

m4xshen avatar m4xshen commented on June 7, 2024

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.

telemachus avatar telemachus commented on June 7, 2024

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.

m4xshen avatar m4xshen commented on June 7, 2024

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.

telemachus avatar telemachus commented on June 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.