Skip to content

Commit

Permalink
change regex for literal string
Browse files Browse the repository at this point in the history
  • Loading branch information
zztrieuzz committed Sep 5, 2023
1 parent 8b41fe4 commit 022a2b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 0 additions & 1 deletion lua/nvim-autopairs/conds.lua
Expand Up @@ -115,7 +115,6 @@ cond.not_after_text = function(text)
end

cond.not_before_regex = function(regex, length)
log.debug(length)
length = length or 1
if length < 0 then length = nil end
---@param opts CondOpts
Expand Down
11 changes: 10 additions & 1 deletion lua/nvim-autopairs/rules/basic.lua
@@ -1,5 +1,6 @@
local Rule = require("nvim-autopairs.rule")
local cond = require("nvim-autopairs.conds")
local utils = require('nvim-autopairs.utils')

local function quote_creator(opt)
local quote = function(...)
Expand Down Expand Up @@ -40,7 +41,15 @@ local function setup(opt)
Rule("```.*$", "```", { "markdown", "vimwiki", "rmarkdown", "rmd", "pandoc" }):only_cr():use_regex(true),
Rule('"""', '"""', { "python", "elixir", "julia", "kotlin" }):with_pair(cond.not_before_char('"', 3)),
Rule("'''", "'''", { "python" }):with_pair(cond.not_before_char('"', 3)),
quote("'", "'", "-rust"):with_pair(cond.not_before_regex("%w")),
quote("'", "'", "-rust")
:with_pair(function(opts)
-- python literals string
local str = utils.text_sub_char(opts.line, opts.col - 1, 1)
if vim.bo.filetype == 'python' and str:match("[frbuFRBU]") then
return true
end
end)
:with_pair(cond.not_before_regex("%w")),
quote("'", "'", "rust"):with_pair(cond.not_before_regex("[%w<&]")):with_pair(cond.not_after_text(">")),
quote("`", "`"),
quote('"', '"', "-vim"),
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-autopairs/utils.lua
Expand Up @@ -71,7 +71,7 @@ M.is_in_quotes = function (line, pos, quote_type)
--a single quote with a word before is not count unless it is a
-- prefixed string in python (e.g. f'string {with_brackets}')
not (char == "'" and prev_char:match(vim.bo.filetype == "python"
and "[AC-EG-QS-TV-Zac-eg-qs-tv-z0-9]" or "%w"))
and "[^frbuFRBU]" or "%w"))
then
last_char = quote_type or char
result = true
Expand Down

0 comments on commit 022a2b8

Please sign in to comment.