Telling DelimitMate to ignore lifetimes (tooling, Vim)

I’ve been trying to get delimitMate to not match the ' in a lifetime, so you end up with something like &'a'. In the Rust syntax file, I can see lifetimes are defined with two (?) regions:

" For the benefit of delimitMate
syn region rustLifetimeCandidate display start=/&'\%(\([^'\\]\|\\\(['nrt0\\\"]\|x\x\{2}\|u{\x\{1,6}}\)\)'\)\@!/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime
syn region rustGenericRegion display start=/<\%('\|[^[cntrl:][:space:][:punct:]]\)\@=')\S\@=/ end=/>/ contains=rustGenericLifetimeCandidate
syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime

I then tried to add each of these to the delimitMate_excluded_regions option:

au FileType rust let b:delimitMate_excluded_regions="rustGenericLifetimeCandidate"

I tried with both of the regions defined in the syntax file, but neither make a difference to how delimitMate acts.

Has anyone managed to get this to work / what am I doing wrong here?

This has been broken for a long time. There’s actually some code in the rust.vim plugin that should prevent delimitMate from placing the extra ' when it detects you’re writing a lifetime, but it’s broken and I can’t figure out how to fix it. I ended up just putting this workaround this my vimrc, which disables autobracketing for all '. I end up typing lifetimes way more than I type character literals, so I’ll take the hit of having to manually close characters.

1 Like

Damn :neutral_face:

Thanks for the workaround tho!