Skip to content

Add LiveEEx template (.leex) syntax support #484

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 5 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_eelixir_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_eelixir_syntax: :leex
}.each do |matcher, type|
RSpec::Matchers.define matcher do |syntax, pattern|
buffer = Buffer.new(VIM, type)
Expand Down
5 changes: 5 additions & 0 deletions spec/syntax/sigil_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
32 changes: 32 additions & 0 deletions syntax/elixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down