diff options
| author | Jacob McDonnell <jacob@simplelittledream.com> | 2022-07-16 18:13:16 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@simplelittledream.com> | 2022-07-16 18:13:16 -0400 |
| commit | 8fad9a5ecddc88d57a531e4b0084544984f23d25 (patch) | |
| tree | 84954bc8219942aa56bc899330ccd0007bbe0ef0 /.config/coc/extensions/node_modules/coc-pairs | |
| parent | 2887af7fcfb4d618dd13cf66ec2fbdbd84c7527c (diff) | |
Added profile and other missing configs
Diffstat (limited to '.config/coc/extensions/node_modules/coc-pairs')
3 files changed, 340 insertions, 0 deletions
diff --git a/.config/coc/extensions/node_modules/coc-pairs/Readme.md b/.config/coc/extensions/node_modules/coc-pairs/Readme.md new file mode 100644 index 0000000..461e20e --- /dev/null +++ b/.config/coc/extensions/node_modules/coc-pairs/Readme.md @@ -0,0 +1,46 @@ +# coc-pairs + +Auto pair extension for [coc.nvim](https://github.com/neoclide/coc.nvim). + +**Note** you can use other vim auto pairs plugins with coc.nvim, it's a +simplified implementation to make auto pairs work like in VSCode. + +**Note** `b:coc_paires` have renamed to `b:coc_pairs` + +For enhanced `<CR>` experience, checkout `:h coc#on_enter()`. + +## Tips + +- You should disable/remove other auto pair plugins for this extension work as expected. +- When you type a paired character which is just the next character, it would just move to the right by one column. +- When the previous content ends with two inserting characters, the characters would just be inserted without inserting the paired character. This makes inserting triple quotes easier. +- `'` only pairs when the character before is not a word character. +- for `<` to insert paired `>`, the previous character should not be an empty space. + +## Install + +In vim/neovim, run this command: + +``` +:CocInstall coc-pairs +``` + +## Features + +- Insert pair characters automatically. +- Buffer local pairs, ex: `autocmd FileType tex let b:coc_pairs = [["$", "$"]]` + +## Options + +- `pairs.disableLanguages`, list of language ids to disable this extension, default: `[]`. +- `pairs.enableCharacters`, list of enabled characters, default: `` ["(", "[", "{", "<", "'", "\"", "`"] ``. +- `pairs.enableBackspace`, enable imap for backspace to remove paired characters, + default: `true`, won't work when `<bs>` is already mapped. + +To disable characters for a specified filetypes, you can use `b:coc_pairs_disabled`, ex: + + autocmd FileType markdown let b:coc_pairs_disabled = ['`'] + +## License + +MIT diff --git a/.config/coc/extensions/node_modules/coc-pairs/lib/index.js b/.config/coc/extensions/node_modules/coc-pairs/lib/index.js new file mode 100644 index 0000000..b2d78ff --- /dev/null +++ b/.config/coc/extensions/node_modules/coc-pairs/lib/index.js @@ -0,0 +1,215 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isWord = exports.wait = exports.byteSlice = exports.activate = void 0; +const coc_nvim_1 = require("coc.nvim"); +const pairs = new Map(); +pairs.set('{', '}'); +pairs.set('[', ']'); +pairs.set('(', ')'); +pairs.set('<', '>'); +pairs.set('"', '"'); +pairs.set("'", "'"); +pairs.set('`', '`'); +async function activate(context) { + let { subscriptions } = context; + const config = coc_nvim_1.workspace.getConfiguration('pairs'); + const disableLanguages = config.get('disableLanguages'); + const characters = config.get('enableCharacters'); + const alwaysPairCharacters = config.get('alwaysPairCharacters', []); + let enableBackspace = config.get('enableBackspace'); + if (enableBackspace) { + let map = (await coc_nvim_1.workspace.nvim.call('maparg', ['<bs>', 'i'])); + if (map && !map.startsWith('coc#_insert_key')) + enableBackspace = false; + } + if (characters.length == 0) + return; + const { nvim, isVim } = coc_nvim_1.workspace; + const localParis = new Map(); + // remove paired characters when possible + async function onBackspace() { + let { nvim } = coc_nvim_1.workspace; + let res = await nvim.eval('[getline("."),col("."),synIDattr(synID(line("."), col(".") - 2, 1), "name"),bufnr("%")]'); + if (res) { + let [line, col, synname, bufnr] = res; + if (col > 1 && !/string/i.test(synname)) { + let buf = Buffer.from(line, 'utf8'); + if (col - 1 < buf.length) { + let pre = buf.slice(col - 2, col - 1).toString('utf8'); + let next = buf.slice(col - 1, col).toString('utf8'); + let local = localParis.get(bufnr); + if (local && local.find(arr => arr[0] == pre && arr[1] == next)) { + await nvim.eval(`feedkeys("\\<C-G>U\\<right>\\<bs>\\<bs>", 'in')`); + if (isVim) + nvim.command('redraw', true); + return; + } + if (characters.includes(pre) && pairs.get(pre) == next) { + await nvim.eval(`feedkeys("\\<C-G>U\\<right>\\<bs>\\<bs>", 'in')`); + if (isVim) + nvim.command('redraw', true); + return; + } + } + } + } + await nvim.eval(`feedkeys("\\<bs>", 'in')`); + if (isVim) + nvim.command('redraw', true); + return ''; + } + async function insertPair(character, pair) { + let samePair = character == pair; + let arr = await nvim.eval(`[bufnr("%"),get(b:,"coc_pairs_disabled",[]),coc#util#cursor(),&filetype,getline("."),mode(),get(get(g:,'context_filetype#filetypes',{}),&filetype,v:null)]`); + let filetype = arr[3]; + if (disableLanguages.indexOf(filetype) !== -1) + return character; + let line = arr[4]; + let mode = arr[5]; + if (mode.startsWith('R')) + return character; + let chars = arr[1]; + let context = arr[6]; + if (chars && chars.length && chars.indexOf(character) !== -1) + return character; + let pos = { line: arr[2][0], character: arr[2][1] }; + let pre = line.slice(0, pos.character); + let rest = line.slice(pos.character); + let previous = pre.length ? pre[pre.length - 1] : ''; + if (alwaysPairCharacters.indexOf(character) == -1 && rest && isWord(rest[0])) + return character; + if (character == '<' && (previous == ' ' || previous == '<')) { + return character; + } + if (samePair && rest[0] == character && rest[1] != character) { + // move position + await nvim.eval(`feedkeys("\\<C-G>U\\<Right>", 'in')`); + return ''; + } + if (samePair && pre && (isWord(previous) || previous == character)) + return character; + // Only pair single quotes if previous character is not word. + if (character === "'" && pre.match(/.*\w$/)) { + return character; + } + if (context) { + try { + let res = await nvim.call('context_filetype#get'); + if (res && res.filetype) { + filetype = res.filetype; + } + } + catch (e) { + // ignore error + } + } + // Rust: don't pair single quotes that are part of lifetime annotations such as `Foo::<'a, 'b>` or `bar: &'a str` + if (filetype === 'rust' && character === "'" && + (pre.endsWith('<') || rest.startsWith('>') || pre.endsWith('&'))) { + return character; + } + if ((filetype === 'vim' || filetype === 'help') && character === '"' && pos.character === 0) { + return character; + } + if (samePair && pre.length >= 2 && previous == character && pre[pre.length - 2] == character) { + if (pre[pre.length - 3] == character) { + if (character == '"') { + nvim.command(`call feedkeys('"""'."${'\\<C-G>U\\<Left>'.repeat(3)}", 'in')`, true); + } + else { + nvim.command(`call feedkeys("${character.repeat(3)}${'\\<C-G>U\\<Left>'.repeat(3)}", 'in')`, true); + } + return; + } + return character; + } + if (character == '"') { + nvim.command(`call feedkeys('""'."\\<C-G>U\\<Left>", 'in')`, true); + } + else { + nvim.command(`call feedkeys("${character}${pair}${'\\<C-G>U\\<Left>'.repeat(pair.length)}", 'in')`, true); + } + return ''; + } + async function closePair(character) { + let [cursor, filetype, line] = await nvim.eval('[coc#util#cursor(),&filetype,getline(".")]'); + if (disableLanguages.indexOf(filetype) !== -1) + return character; + let rest = line.slice(cursor[1]); + if (rest[0] == character) { + nvim.command(`call feedkeys("\\<C-G>U\\<Right>", 'in')`, true); + return ''; + } + return character; + } + nvim.pauseNotification(); + for (let character of characters) { + if (pairs.has(character)) { + subscriptions.push(coc_nvim_1.workspace.registerExprKeymap('i', character, insertPair.bind(null, character, pairs.get(character)), false)); + } + let matched = pairs.get(character); + if (matched != character) { + subscriptions.push(coc_nvim_1.workspace.registerExprKeymap('i', matched, closePair.bind(null, matched), false)); + } + } + if (enableBackspace) { + subscriptions.push(coc_nvim_1.workspace.registerExprKeymap('i', '<bs>', onBackspace, false)); + } + // tslint:disable-next-line: no-floating-promises + nvim.resumeNotification(false, true); + async function createBufferKeymap(doc) { + if (!doc) + return; + let pairs = doc.getVar('pairs', null); + if (!pairs || !pairs.length) + return; + localParis.set(doc.bufnr, pairs); + nvim.pauseNotification(); + for (let p of pairs) { + if (Array.isArray(p) && p.length == 2) { + let [character, matched] = p; + subscriptions.push(coc_nvim_1.workspace.registerExprKeymap('i', character, insertPair.bind(null, character, matched), true)); + if (matched != character) { + subscriptions.push(coc_nvim_1.workspace.registerExprKeymap('i', matched, closePair.bind(null, matched), true)); + } + } + } + // tslint:disable-next-line: no-floating-promises + nvim.resumeNotification(false, true); + } + const buf = await coc_nvim_1.workspace.nvim.buffer; + await createBufferKeymap(coc_nvim_1.workspace.getDocument(buf.id)); + coc_nvim_1.workspace.onDidOpenTextDocument(async (e) => { + await createBufferKeymap(coc_nvim_1.workspace.getDocument(e.uri)); + }); +} +exports.activate = activate; +function byteSlice(content, start, end) { + let buf = Buffer.from(content, 'utf8'); + return buf.slice(start, end).toString('utf8'); +} +exports.byteSlice = byteSlice; +function wait(ms) { + return new Promise(resolve => { + setTimeout(() => { + resolve(undefined); + }, ms); + }); +} +exports.wait = wait; +function isWord(character) { + let code = character.charCodeAt(0); + if (code > 128) + return false; + if (code == 95) + return true; + if (code >= 48 && code <= 57) + return true; + if (code >= 65 && code <= 90) + return true; + if (code >= 97 && code <= 122) + return true; + return false; +} +exports.isWord = isWord; +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/.config/coc/extensions/node_modules/coc-pairs/package.json b/.config/coc/extensions/node_modules/coc-pairs/package.json new file mode 100644 index 0000000..5ca4f21 --- /dev/null +++ b/.config/coc/extensions/node_modules/coc-pairs/package.json @@ -0,0 +1,79 @@ +{ + "name": "coc-pairs", + "version": "1.3.2", + "description": "Auto pair extension for coc.nvim", + "main": "lib/index.js", + "publisher": "chemzqm", + "repository": { + "type": "git", + "url": "https://github.com/neoclide/coc-pairs.git" + }, + "keywords": [ + "coc.nvim", + "autopair" + ], + "engines": { + "coc": "^0.0.80" + }, + "scripts": { + "clean": "rimraf lib", + "build": "tsc -p tsconfig.json", + "prepare": "tsc -p tsconfig.json" + }, + "activationEvents": [ + "*" + ], + "contributes": { + "configuration": { + "type": "object", + "properties": { + "pairs.disableLanguages": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "A list of languages IDs to disable this extension on" + }, + "pairs.enableCharacters": { + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "(", + "[", + "{", + "<", + "'", + "\"", + "`" + ], + "description": "Enabled character list for keymap." + }, + "pairs.alwaysPairCharacters": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "Characters that should be paired without check for next character." + }, + "pairs.enableBackspace": { + "type": "boolean", + "description": "Remap your backspce to delete paired characters when necessary, won't work when <bs> already mapped.", + "default": true + } + } + } + }, + "author": "chemzqm@gmail.com", + "license": "MIT", + "devDependencies": { + "@chemzqm/tsconfig": "^0.0.3", + "@types/node": "^12.12.0", + "coc.nvim": "^0.0.81-next.8", + "typescript": "^4.1.3" + }, + "dependencies": {} +} |
