Skip to content

Commit a6dcabf

Browse files
committed
More robust projection highlighting
1 parent e191b24 commit a6dcabf

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

after/syntax/ruby/rails.vim

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,19 @@ syn keyword rubyAttribute thread_cattr_accessor thread_cattr_reader thread_cattr
237237
syn keyword rubyMacro alias_attribute concern concerning delegate delegate_missing_to with_options
238238

239239
let s:special = {
240-
\ '[': '\>\[\@=',
241-
\ ']': '\>[[.]\@!',
242-
\ '{': '\>\%(\s*{\|\s*do\>\)\@=',
243-
\ '}': '\>\%(\s*{\|\s*do\>\)\@!'}
240+
\ '[': '\[\@=',
241+
\ ']': '[[.]\@!',
242+
\ '{': '\%(\s*{\|\s\+do\>\)\@=',
243+
\ '}': '\%(\s*{\|\s\+do\>\)\@!'}
244244
function! s:highlight(group, ...) abort
245245
let value = rails#buffer().projected(a:0 ? a:1 : a:group)
246246
let words = split(join(filter(value, 'type(v:val) == type("")'), ' '))
247-
let special = filter(copy(words), 'type(v:val) == type("") && v:val =~# ''^\h\k*[][{}?!]$''')
248-
let regular = filter(copy(words), 'type(v:val) == type("") && v:val =~# ''^\h\k*$''')
249-
if !empty(special)
247+
call filter(words, 'type(v:val) == type("") && v:val =~# ''^\h\k*[!?]\=[][{}]\=$''')
248+
if !empty(words)
250249
exe 'syn match' a:group substitute(
251-
\ '"\<\%('.join(special, '\|').'\)"',
250+
\ '"\<\%('.join(words, '\|').'\)\%(\k\@<!\|\k\@!:\@!\)"',
252251
\ '[][{}]', '\=get(s:special, submatch(0), submatch(0))', 'g')
253252
endif
254-
if !empty(regular)
255-
exe 'syn keyword' a:group join(regular, ' ')
256-
endif
257253
endfunction
258254

259255
call s:highlight(

0 commit comments

Comments
 (0)