Skip to content

Commit

Permalink
Another take on projectionist config
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinst committed Sep 24, 2020
1 parent 6acef30 commit f8890cf
Showing 1 changed file with 47 additions and 13 deletions.
60 changes: 47 additions & 13 deletions ftplugin/elixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,52 @@ onoremap <buffer> <silent> <expr> [] ':silent keeppatterns ?'.b:block_end .'<CR
let b:undo_ftplugin = 'setlocal sw< sts< et< isk< com< cms< path< inex< sua< def< fo<'.
\ '| unlet! b:match_ignorecase b:match_words b:block_begin b:block_end'

function s:projectionist_detect_elixir()
if filereadable('mix.exs')
let root = simplify(fnamemodify('.', ':p:s?[\/]$??'))
if get(g:, 'loaded_projectionist', 0)
let g:projectionist_heuristics = get(g:, 'projectionist_heuristics', {})

let projections = {}
let projections['lib/*.ex'] = { 'type': 'main', 'alternate': ['test/{}_test.exs'] }
let projections['lib/**/*.ex'] = { 'type': 'main', 'alternate': ['test/{}_test.exs'] }
let projections['test/*_test.exs'] = { 'type': 'test', 'alternate': ['lib/{}.ex'] }
let projections['test/**/*_test.exs'] = { 'type': 'test', 'alternate': ['lib/{}.ex'] }

call projectionist#append(root, projections)
endif
endfunc
call extend(g:projectionist_heuristics, {
\ "&mix.exs":
\ {
\ 'apps/*/mix.exs': { 'type': 'app' },
\ 'lib/*.ex': {
\ 'type': 'lib',
\ 'alternate': 'test/{}_test.exs',
\ 'template': [
\ 'defmodule {camelcase|capitalize|dot} do',
\ 'end'
\ ],
\ },
\ 'test/*_test.exs': {
\ 'type': 'test',
\ 'alternate': 'lib/{}.ex',
\ 'dispatch': "mix test test/{}_test.exs`=v:lnum ? ':'.v:lnum : ''`",
\ 'template': [
\ 'defmodule {camelcase|capitalize|dot}Test do',
\ ' use ExUnit.Case',
\ '',
\ ' alias {camelcase|capitalize|dot}',
\ '',
\ ' doctest {basename|capitalize}',
\ 'end'
\ ],
\ },
\ 'mix.exs': { 'type': 'mix' },
\ 'config/*.exs': { 'type': 'config' },
\ '*.ex': {
\ 'makery': {
\ 'lint': { 'compiler': 'credo' },
\ 'test': { 'compiler': 'exunit' },
\ 'build': { 'compiler': 'mix' }
\ }
\ },
\ '*.exs': {
\ 'makery': {
\ 'lint': { 'compiler': 'credo' },
\ 'test': { 'compiler': 'exunit' },
\ 'build': { 'compiler': 'mix' }
\ }
\ }
\ }
\ }, 'keep')
endif

autocmd User ProjectionistDetect call s:projectionist_detect_elixir()

0 comments on commit f8890cf

Please sign in to comment.