Skip to content

Add Phoenix LiveEEx Template (.leex) file type support. #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion ftplugin/eelixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/elixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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\='

Expand Down
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -145,6 +151,7 @@ def self.new
{
be_elixir_indentation: :ex,
be_eelixir_indentation: :eex
be_leelixir_indentation: :leex
}.each do |matcher, type|
RSpec::Matchers.define matcher do
buffer = Buffer.new(VIM, type)
Expand All @@ -170,6 +177,7 @@ def self.new
{
include_elixir_syntax: :ex,
include_eelixir_syntax: :eex
include_leelixir_syntax: :leex
}.each do |matcher, type|
RSpec::Matchers.define matcher do |syntax, pattern|
buffer = Buffer.new(VIM, type)
Expand Down
4 changes: 4 additions & 0 deletions spec/syntax/sigil_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
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', '""""')
end
end

describe 'lower case' do
Expand Down
5 changes: 4 additions & 1 deletion syntax/eelixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions syntax/elixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down