Giter VIP home page Giter VIP logo

Comments (7)

altermo avatar altermo commented on August 25, 2024

Okay, so I quickly updated the plugin to make this possible.
If you don't like the solution, then pleas give me feedback on how I could make it easier, as I don't know how to make it easier.

local ua_core=require'ultimate-autopair.core'
local ua=require'ultimate-autopair'
--For keycode:
---Make sure to pass them through `vim.api.nvim_replace_termcodes(key,true,true,true)` (or `vim.keycode(key)` if using neovim 0.10)
ua_core.dont_map={keycodes}
ua.setup(config)
vim.keymap.set('i',key,function()
    return ua_core.run(keycode)
end,{expr=true,noremap=true,replace_keycodes=false})
Example
local ua_core=require'ultimate-autopair.core'
local ua=require'ultimate-autopair'
ua_core.dont_map={vim.api.nvim_replace_termcodes('<bs>',true,true,true)}
ua.setup({})
vim.keymap.set('i','<C-h>',function()
    return ua_core.run(vim.api.nvim_replace_termcodes('<bs>',true,true,true))
end,{expr=true,noremap=true,replace_keycodes=false})

from ultimate-autopair.nvim.

brglng avatar brglng commented on August 25, 2024

Thank you for your reply! I'm going to try it.

from ultimate-autopair.nvim.

brglng avatar brglng commented on August 25, 2024

I have succeeded with your example. Moreover, I found the following code also works:

require('ultimate-autopair').setup({
    cr = {
        map = '<Plug>UltimateAutopairCR' -- or any other keys
    }
})
function s:expand_ultimate_autopair_cr()
    return luaeval("require('ultimate-autopair.core').run(vim.api.nvim_replace_termcodes('<CR>', true, true, true))")
endfunction
inoremap <silent> <expr> <CR> <SID>expand_ultimate_autopair_cr()

That seems a little bit simpler to me, because I have other vim plugins who provide mappings in VimL and should be added to the inoremap line.

I think it is simpler if I can write something like:

require('ultimate-autopair').setup({
    cr = {
        map = nil -- disable the keymap but allows custom expansion with ua_core.run()
    }
})

Thanks!

from ultimate-autopair.nvim.

altermo avatar altermo commented on August 25, 2024

Might I enquire why you reopened this issue?

from ultimate-autopair.nvim.

brglng avatar brglng commented on August 25, 2024

As I mentioned in the previous post, might I ask for a API like this?:

require('ultimate-autopair').setup({
    cr = {
        map = nil -- disable the keymap but allows custom expansion with ua_core.run()
    }
})

Please feel free to close the issue if this is not your consideration. Thank you!

from ultimate-autopair.nvim.

altermo avatar altermo commented on August 25, 2024

Okay; added map='' to just initialize modulo without any mappings and '' which will activate all default mappings.

If you want to run for example newline, you can use:

local core=require'ultimate-autopair.core'
local default=require'ultimate-autopair.profile.default.utils'
vim.keymap.set('i','\r',function ()
    local o=core.get_o_value('') --get information about the position; use key=='' which will activate all modules
    for _,v in pairs(default.filter_for_opt({'newline'})) do --filter for specifically newline modules
        local ret=v.check(vim.deepcopy(o))
        if ret then return core.I.activate_iabbrev(ret) end
    end
    return '\x1d\r' --\x1d > :help i_CTRL-]
end,{expr=true,replace_keycodes=false})

from ultimate-autopair.nvim.

brglng avatar brglng commented on August 25, 2024

Thanks. That solves my problem.

from ultimate-autopair.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.