From 79ea0bea47300da76522c9f5b38c8784bf1f2511 Mon Sep 17 00:00:00 2001 From: crunchysoul Date: Thu, 21 Mar 2019 18:18:52 +1100 Subject: [PATCH 1/5] add leex support align with eex --- ftplugin/eelixir.vim | 5 ++++- ftplugin/elixir.vim | 2 +- spec/spec_helper.rb | 8 ++++++++ syntax/eelixir.vim | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ftplugin/eelixir.vim b/ftplugin/eelixir.vim index c115429f..83601e15 100644 --- a/ftplugin/eelixir.vim +++ b/ftplugin/eelixir.vim @@ -20,7 +20,10 @@ if !exists("b:eelixir_subtype") let b:eelixir_subtype = matchstr(&filetype,'^eex\.\zs\w\+') endif if b:eelixir_subtype == '' - let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.eelixir\)\+$','',''),'\.\zs\w\+$') + let b:eelixir_subtype = matchstr(&filetype,'^leex\.\zs\w\+') + endif + if b:eelixir_subtype == '' + let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.leex\|\.eelixir\)\+$','',''),'\.\zs\w\+$') endif if b:eelixir_subtype == 'ex' let b:eelixir_subtype = 'elixir' diff --git a/ftplugin/elixir.vim b/ftplugin/elixir.vim index 95858894..c36d8bee 100644 --- a/ftplugin/elixir.vim +++ b/ftplugin/elixir.vim @@ -28,7 +28,7 @@ let &l:path = \ &g:path \ ], ',') setlocal includeexpr=elixir#util#get_filename(v:fname) -setlocal suffixesadd=.ex,.exs,.eex,.erl,.xrl,.yrl,.hrl +setlocal suffixesadd=.ex,.exs,.eex,.leex,.erl,.xrl,.yrl,.hrl let &l:define = 'def\(macro\|guard\|delegate\)\=p\=' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ad4c49d4..46f83910 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -122,6 +122,12 @@ def self.new end end +module EexBuffer + def self.new + Buffer.new(VIM, :leex) + end +end + RSpec::Matchers.define :be_typed_with_right_indent do |syntax| buffer = Buffer.new(VIM, syntax || :ex) @@ -145,6 +151,7 @@ def self.new { be_elixir_indentation: :ex, be_eelixir_indentation: :eex + be_eelixir_indentation: :leex }.each do |matcher, type| RSpec::Matchers.define matcher do buffer = Buffer.new(VIM, type) @@ -170,6 +177,7 @@ def self.new { include_elixir_syntax: :ex, include_eelixir_syntax: :eex + include_eelixir_syntax: :leex }.each do |matcher, type| RSpec::Matchers.define matcher do |syntax, pattern| buffer = Buffer.new(VIM, type) diff --git a/syntax/eelixir.vim b/syntax/eelixir.vim index 18c98635..1ec0ac66 100644 --- a/syntax/eelixir.vim +++ b/syntax/eelixir.vim @@ -20,7 +20,10 @@ if !exists("b:eelixir_subtype") let b:eelixir_subtype = matchstr(&filetype,'^eex\.\zs\w\+') endif if b:eelixir_subtype == '' - let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.eelixir\)\+$','',''),'\.\zs\w\+$') + let b:eelixir_subtype = matchstr(&filetype,'^leex\.\zs\w\+') + endif + if b:eelixir_subtype == '' + let b:eelixir_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.eex\|\.leex\|\.eelixir\)\+$','',''),'\.\zs\w\+$') endif if b:eelixir_subtype == 'ex' let b:eelixir_subtype = 'elixir' From 8dc4f835f40b7baf5e6435d1c1d20e4871b7921d Mon Sep 17 00:00:00 2001 From: crunchysoul Date: Thu, 21 Mar 2019 18:48:31 +1100 Subject: [PATCH 2/5] add live eex sigil syntax --- spec/syntax/sigil_spec.rb | 5 +++++ syntax/eelixir.vim | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/syntax/sigil_spec.rb b/spec/syntax/sigil_spec.rb index 6ef7f9da..80db5936 100644 --- a/spec/syntax/sigil_spec.rb +++ b/spec/syntax/sigil_spec.rb @@ -87,6 +87,11 @@ it 'without escaped parenthesis' do expect('~S(\( )').not_to include_elixir_syntax('elixirRegexEscapePunctuation', '( ') end + + it 'Live EEx' do + expect('~L"""liveview template"""').to include_elixir_syntax('elixirSigilDelimiter', '""""') + expect('~L"""liveview template"""').to include_elixir_syntax('elixirSigilDelimiter', '""""') + end end describe 'lower case' do diff --git a/syntax/eelixir.vim b/syntax/eelixir.vim index 1ec0ac66..0e43834a 100644 --- a/syntax/eelixir.vim +++ b/syntax/eelixir.vim @@ -50,6 +50,9 @@ syn include @elixirTop syntax/elixir.vim syn cluster eelixirRegions contains=eelixirBlock,eelixirExpression,eelixirComment +" Sigils surrounded with heredoc +syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z("""\)+ end=+^\s*\z1+ skip=+\\"+ fold + exe 'syn region eelixirExpression matchgroup=eelixirDelimiter start="<%" end="%\@" contains=@elixirTop containedin=ALLBUT,@eelixirRegions keepend' exe 'syn region eelixirExpression matchgroup=eelixirDelimiter start="<%=" end="%\@" contains=@elixirTop containedin=ALLBUT,@eelixirRegions keepend' exe 'syn region eelixirQuote matchgroup=eelixirDelimiter start="<%%" end="%\@" contains=@elixirTop containedin=ALLBUT,@eelixirRegions keepend' @@ -57,8 +60,10 @@ exe 'syn region eelixirComment matchgroup=eelixirDelimiter start="<%#" end=" " Define the default highlighting. -hi def link eelixirDelimiter PreProc -hi def link eelixirComment Comment +hi def link eelixirDelimiter PreProc +hi def link eelixirComment Comment +hi def link elixirSigilDelimiter Delimiter +hi def link elixirDocSigilDelimiter elixirSigilDelimiter let b:current_syntax = 'eelixir' From 6a32a1d2b9f591c8f6d0acbb3114dd3324e6e594 Mon Sep 17 00:00:00 2001 From: crunchysoul Date: Thu, 21 Mar 2019 19:18:46 +1100 Subject: [PATCH 3/5] update README.md with .leex --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7517242..11cc7113 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Features: * Syntax highlighting for Elixir and EEx files -* Filetype detection for `.ex`, `.exs` and `.eex` files +* Filetype detection for `.ex`, `.exs`, `.eex` and `.leex` files * Automatic indentation * Integration between Ecto projects and [vim-dadbod][] for running SQL queries on defined Ecto repositories From 0e132dbfff3d45577594656aecb7cca71565cf5b Mon Sep 17 00:00:00 2001 From: crunchysoul Date: Thu, 21 Mar 2019 19:32:23 +1100 Subject: [PATCH 4/5] remove ~L sigil from leex --- syntax/eelixir.vim | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/syntax/eelixir.vim b/syntax/eelixir.vim index 0e43834a..1ec0ac66 100644 --- a/syntax/eelixir.vim +++ b/syntax/eelixir.vim @@ -50,9 +50,6 @@ syn include @elixirTop syntax/elixir.vim syn cluster eelixirRegions contains=eelixirBlock,eelixirExpression,eelixirComment -" Sigils surrounded with heredoc -syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z("""\)+ end=+^\s*\z1+ skip=+\\"+ fold - exe 'syn region eelixirExpression matchgroup=eelixirDelimiter start="<%" end="%\@" contains=@elixirTop containedin=ALLBUT,@eelixirRegions keepend' exe 'syn region eelixirExpression matchgroup=eelixirDelimiter start="<%=" end="%\@" contains=@elixirTop containedin=ALLBUT,@eelixirRegions keepend' exe 'syn region eelixirQuote matchgroup=eelixirDelimiter start="<%%" end="%\@" contains=@elixirTop containedin=ALLBUT,@eelixirRegions keepend' @@ -60,10 +57,8 @@ exe 'syn region eelixirComment matchgroup=eelixirDelimiter start="<%#" end=" " Define the default highlighting. -hi def link eelixirDelimiter PreProc -hi def link eelixirComment Comment -hi def link elixirSigilDelimiter Delimiter -hi def link elixirDocSigilDelimiter elixirSigilDelimiter +hi def link eelixirDelimiter PreProc +hi def link eelixirComment Comment let b:current_syntax = 'eelixir' From 0e726f3bdb7824fd50a61847c2443facee702706 Mon Sep 17 00:00:00 2001 From: crunchysoul Date: Fri, 22 Mar 2019 11:27:05 +1100 Subject: [PATCH 5/5] test liveview sigil syntax highlighting --- syntax/elixir.vim | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/syntax/elixir.vim b/syntax/elixir.vim index 0d9ead52..c2d98d06 100644 --- a/syntax/elixir.vim +++ b/syntax/elixir.vim @@ -105,6 +105,36 @@ syn region elixirSigil matchgroup=elixirSigilDelimiter start="\~\l\/" syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z("""\)+ end=+^\s*\z1+ skip=+\\"+ fold syn region elixirSigil matchgroup=elixirSigilDelimiter start=+\~\a\z('''\)+ end=+^\s*\z1+ skip=+\\'+ fold +" TODO +" add LiveView Sigil Support within .ex +function! TextEnableCodeSnip(filetype,start,end,textSnipHl) abort + let ft=toupper(a:filetype) + let group='textGroup'.ft + if exists('b:current_syntax') + let s:current_syntax=b:current_syntax + " Remove current syntax definition, as some syntax files (e.g. cpp.vim) + " do nothing if b:current_syntax is defined. + unlet b:current_syntax + endif + execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim' + try + execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim' + catch + endtry + if exists('s:current_syntax') + let b:current_syntax=s:current_syntax + else + unlet b:current_syntax + endif + execute 'syntax region textSnip'.ft.' + \ matchgroup='.a:textSnipHl.' + \ keepend + \ start="'.a:start.'" end="'.a:end.'" + \ contains=@'.group +endfunction + +call TextEnableCodeSnip('html' ,'~L"""' ,'"""', 'SpecialComment') + " Documentation if exists('g:elixir_use_markdown_for_docs') && g:elixir_use_markdown_for_docs syn include @markdown syntax/markdown.vim @@ -221,6 +251,8 @@ hi def link elixirRegexDelimiter Delimiter hi def link elixirInterpolationDelimiter Delimiter hi def link elixirSigilDelimiter Delimiter hi def link elixirPrivateRecordDeclaration elixirRecordDeclaration +" DOING +" hi def link elixirLiveViewSigilDelimiter elixirLiveViewSigilDelimiter let b:current_syntax = "elixir"