Skip to content

Commit d2cf292

Browse files
committed
auto merge of #7742 : chris-morgan/rust/delimitmate-support, r=cmr
When it's a lifetime, a single quotation mark shouldn't have a matching single quotation mark inserted after it, as delimitMate does by default. Note that this is not without problems; a char literal coming after an odd number of lifetime markers will have its quotation marks behave a little strangely. That, however, is not my fault, but delimitMate's: Raimondi/delimitMate#135
2 parents 1ee54a8 + 4f67ed5 commit d2cf292

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/etc/vim/ftplugin/rust.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ if exists("g:ftplugin_rust_source_path")
3333
let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
3434
endif
3535

36-
let b:undo_ftplugin = "setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<"
36+
if exists("g:loaded_delimitMate")
37+
if exists("b:delimitMate_excluded_regions")
38+
let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions
39+
endif
40+
let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate'
41+
endif
42+
43+
let b:undo_ftplugin = "setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd< | if exists('b:rust_original_delimitMate_excluded_regions') | let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions | unlet b:rust_original_delimitMate_excluded_regions | elseif exists('b:delimitMate_excluded_regions') | unlet b:delimitMate_excluded_regions | endif"

src/etc/vim/syntax/rust.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\(f\|f32\|f64\)\>
113113
syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\>"
114114
syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\(f\|f32\|f64\)\>"
115115

116+
" For the benefit of delimitMate
117+
syn region rustLifetimeCandidate display start=/&'\%(\([^'\\]\|\\\(['nrt\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'\)\@!/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustLifetime
118+
syn region rustGenericRegion display start=/<\%('\|[^[cntrl:][:space:][:punct:]]\)\@=')\S\@=/ end=/>/ contains=rustGenericLifetimeCandidate
119+
syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustLifetime
120+
116121
"rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting
117122
syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"
118123
syn match rustCharacter "'\([^'\\]\|\\\(['nrt\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'"

0 commit comments

Comments
 (0)