Skip to content

Commit

Permalink
nvim-wip: Update autopair plugin to fix end_moves_right_when on any end
Browse files Browse the repository at this point in the history
Relevant PR: windwp/nvim-autopairs#357 (by me!)
  • Loading branch information
bew committed May 30, 2023
1 parent 452fd5b commit d997d34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions nvim-wip/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"indent-blankline.nvim": { "branch": "master", "commit": "018bd04d80c9a73d399c1061fa0c3b14a7614399" },
"neo-tree.nvim": { "branch": "v2.x", "commit": "2b2f74828eeb02cf29d6b21aa32eedadadc94ca7" },
"nui.nvim": { "branch": "main", "commit": "1f43b13d133eb4b4f53a4485379d9afa58808389" },
"nvim-autopairs": { "branch": "master", "commit": "6a5faeabdbcc86cfbf1561ae430a451a72126e81" },
"nvim-autopairs": { "branch": "master", "commit": "59df87a84c80a357ca8d8fe86e451b93ac476ccc" },
"nvim-cmp": { "branch": "main", "commit": "7a3b1e76f74934b12fda82158237c6ad8bfd3d40" },
"nvim-fzf": { "branch": "master", "commit": "a8dc4bae4c1e1552e0233df796e512ab9ca65e44" },
"nvim-surround": { "branch": "main", "commit": "ebdd22d2040798d0b5a5e50d72d940e95f308121" },
Expand All @@ -36,4 +36,4 @@
"vim-textobj-user": { "branch": "master", "commit": "41a675ddbeefd6a93664a4dc52f302fe3086a933" },
"which-key.nvim": { "branch": "main", "commit": "5224c261825263f46f6771f1b644cae33cd06995" },
"xterm-color-table.vim": { "branch": "master", "commit": "efa63b4311f6d1328d214bd93149c14c77c9dd7b" }
}
}
14 changes: 7 additions & 7 deletions nvim-wip/lua/mycfg/plugs_for_file_editing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Plug {
-- From: https://github.com/windwp/nvim-autopairs/wiki/Custom-rules#alternative-version
local brackets = { {'(', ')'}, {'[', ']'}, {'{', '}'} }
npairs.add_rule(
Rule({start_pair = " ", end_pair = " "})
Rule{start_pair = " ", end_pair = " "}
:insert_pair_when(function(ctx)
-- get last char & next char, check if it's a known 'expandable' pair
local pair = ctx.line:sub(ctx.col -1, ctx.col) -- inclusive indexing
Expand All @@ -393,9 +393,8 @@ Plug {
:end_moves_right_when(cond.never) -- is this the default? (why not?)
:cr_expands_pair_when(cond.never) -- is this the default? (why not?)
:bs_deletes_pair_when(function(ctx)
local col = vim.api.nvim_win_get_cursor(0)[2]
-- (weird? `col` is one less than what I would have thought..)
local context = ctx.line:sub(col - 1, col + 2) -- inclusive indexing
local col0 = vim.api.nvim_win_get_cursor(0)[2]
local context = ctx.line:sub(col0 - 1, col0 + 2) -- inclusive indexing
return vim.tbl_contains({
brackets[1][1]..' '..brackets[1][2],
brackets[2][1]..' '..brackets[2][2],
Expand All @@ -408,7 +407,7 @@ Plug {
-- languages using angle brackets generics, like Rust (`Foo<T>`)
-- Taken from https://github.com/windwp/nvim-autopairs/issues/330
npairs.add_rule(
Rule({start_pair = "<", end_pair = ">"})
Rule{start_pair = "<", end_pair = ">"}
:insert_pair_when(cond.preceded_by_regex("%a+"))
:end_moves_right_when(cond.always)
)
Expand All @@ -419,7 +418,7 @@ Plug {
-- `" abc | def "` -> press `"` => `" abc "|" def "`
-- (use `<M-">` for only one dquote, see below)
npairs.add_rule(
Rule({start_pair = [["]], end_pair = [["]]})
Rule{start_pair = [["]], end_pair = [["]]}
:insert_pair_when(cond.always)
-- Try to not be smart about dquote insertion, even if in quotes
-- `|"`
Expand All @@ -436,10 +435,11 @@ Plug {
-- '`|`' -> press '`' => '``|``' (instead of '``|')
-- Allows to do 3+ bquote blocks without special logic:
-- '```|```' -> press '`' => '````|````' (instead of weird '````|``````')
-- TODO(issue,impl?): `tabout.nvim`-like feature, see: https://github.com/abecodes/tabout.nvim
npairs.remove_rule("`")
npairs.remove_rule("```")
npairs.add_rule(
Rule({start_pair = "`", end_pair = "`"})
Rule{start_pair = "`", end_pair = "`"}
:insert_pair_when(cond.always)
:end_moves_right_when(cond.never) -- ?
)
Expand Down

0 comments on commit d997d34

Please sign in to comment.