From da55addbb1f4f63ab2e93916ab4308458357a744 Mon Sep 17 00:00:00 2001 From: crunchysoul Date: Fri, 22 Mar 2019 16:29:32 +1100 Subject: [PATCH 1/3] Add Phoenix LiveEEx Template (.leex) file type support. Add LiveView sigil (~L"""LiveView""") support in .ex. Update README.md --- README.md | 2 +- ftplugin/eelixir.vim | 5 ++++- ftplugin/elixir.vim | 2 +- spec/spec_helper.rb | 8 ++++++++ spec/syntax/sigil_spec.rb | 5 +++++ syntax/eelixir.vim | 5 ++++- syntax/elixir.vim | 6 ++++++ 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 414942fc..3dac7da0 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 ## Installation 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/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 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' diff --git a/syntax/elixir.vim b/syntax/elixir.vim index 41c1a3b6..40e796dd 100644 --- a/syntax/elixir.vim +++ b/syntax/elixir.vim @@ -105,6 +105,12 @@ 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 + +" LiveView Sigils surrounded with ~L""" +syntax include @HTML syntax/html.vim +syntax region elixirLiveViewSigil matchgroup=elixirSigilDelimiter keepend start=+\~L\z("""\)+ end=+^\s*\z1+ skip=+\\"+ contains=@HTML fold + + " Documentation if exists('g:elixir_use_markdown_for_docs') && g:elixir_use_markdown_for_docs syn include @markdown syntax/markdown.vim From fce73017291625d350056b6b226d8ef5603ed242 Mon Sep 17 00:00:00 2001 From: crunchysoul Date: Mon, 25 Mar 2019 17:31:59 +1100 Subject: [PATCH 2/3] update leex indentation and syntax specs removed duplicated live view sigil spec --- spec/spec_helper.rb | 4 ++-- spec/syntax/sigil_spec.rb | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 46f83910..ab21a3b0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -151,7 +151,7 @@ def self.new { be_elixir_indentation: :ex, be_eelixir_indentation: :eex - be_eelixir_indentation: :leex + be_leelixir_indentation: :leex }.each do |matcher, type| RSpec::Matchers.define matcher do buffer = Buffer.new(VIM, type) @@ -177,7 +177,7 @@ def self.new { include_elixir_syntax: :ex, include_eelixir_syntax: :eex - include_eelixir_syntax: :leex + include_leelixir_syntax: :leex }.each do |matcher, type| RSpec::Matchers.define matcher do |syntax, pattern| buffer = Buffer.new(VIM, type) diff --git a/spec/syntax/sigil_spec.rb b/spec/syntax/sigil_spec.rb index 80db5936..8c088dd0 100644 --- a/spec/syntax/sigil_spec.rb +++ b/spec/syntax/sigil_spec.rb @@ -90,7 +90,6 @@ it 'Live EEx' do expect('~L"""liveview template"""').to include_elixir_syntax('elixirSigilDelimiter', '""""') - expect('~L"""liveview template"""').to include_elixir_syntax('elixirSigilDelimiter', '""""') end end From fc79320fc391696bd78d25192bd8b69927e39a2b Mon Sep 17 00:00:00 2001 From: Josh Bodah Date: Wed, 17 Apr 2019 11:08:17 -0400 Subject: [PATCH 3/3] fix leex test bugs --- spec/spec_helper.rb | 4 ++-- spec/syntax/sigil_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ab21a3b0..aad0220f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -150,7 +150,7 @@ def self.new { be_elixir_indentation: :ex, - be_eelixir_indentation: :eex + be_eelixir_indentation: :eex, be_leelixir_indentation: :leex }.each do |matcher, type| RSpec::Matchers.define matcher do @@ -176,7 +176,7 @@ def self.new { include_elixir_syntax: :ex, - include_eelixir_syntax: :eex + include_eelixir_syntax: :eex, include_leelixir_syntax: :leex }.each do |matcher, type| RSpec::Matchers.define matcher do |syntax, pattern| diff --git a/spec/syntax/sigil_spec.rb b/spec/syntax/sigil_spec.rb index 8c088dd0..380b0fb0 100644 --- a/spec/syntax/sigil_spec.rb +++ b/spec/syntax/sigil_spec.rb @@ -89,7 +89,7 @@ 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