Skip to content

Commit

Permalink
Add back (after the first Great Fuck Up of 2016) vim-elixir.
Browse files Browse the repository at this point in the history
  • Loading branch information
theIV committed Mar 7, 2016
1 parent 8965058 commit e96336d
Show file tree
Hide file tree
Showing 34 changed files with 1,581 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vim/bundle/vim-elixir/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: ruby
rvm:
- 1.9.3
before_install: sudo apt-get install vim-gtk
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
script: "bundle exec rspec --color -f d"
4 changes: 4 additions & 0 deletions vim/bundle/vim-elixir/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rspec'
gem 'vimrunner'
20 changes: 20 additions & 0 deletions vim/bundle/vim-elixir/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.4)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
vimrunner (0.3.1)

PLATFORMS
ruby

DEPENDENCIES
rspec
vimrunner
13 changes: 13 additions & 0 deletions vim/bundle/vim-elixir/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2012 Plataformatec

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
62 changes: 62 additions & 0 deletions vim/bundle/vim-elixir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# vim-elixir

[![Build Status](https://travis-ci.org/elixir-lang/vim-elixir.svg?branch=master)](https://travis-ci.org/elixir-lang/vim-elixir)

[Elixir](http://elixir-lang.org) support for vim. This plugin also adds support
for Elixir's templating language, EEx.

Features included so far:

* Syntax highlighting for Elixir and EEx
* Filetype detection for `.ex`, `.exs` and `.eex` files
* Automatic indentation


## Installation

### Plugin managers

The most common plugin managers include [vim-plug][vim-plug],
[NeoBundle][neobundle], [Vundle][vundle] and [pathogen.vim][pathogen].

With pathogen.vim, just clone this repository inside `~/.vim/bundle`:

```bash
git clone https://github.com/elixir-lang/vim-elixir.git ~/.vim/bundle/vim-elixir
```

With the other plugin managers, just follow the instructions on the homepage of
each plugin. In general, you have to add a line to your `~/.vimrc`:

```viml
" vim-plug
Plug 'elixir-lang/vim-elixir'
" NeoBundle
NeoBundle 'elixir-lang/vim-elixir'
" Vundle
Plugin 'elixir-lang/vim-elixir'
```

### Manual installation

Copy the contents of each directory in the respective directories inside
`~/.vim`.


## Syntastic integration

> :warning: **Warning:** older versions (`<= 3.4.0-106`) of
> [Syntastic][syntastic] check Elixir scripts *by executing them*. In addition
> to being unsafe, this can cause Vim to hang while saving Elixir scripts. This
> is not an error in `vim-elixir`. This issue [can be fixed in
> Syntastic][syntastic-issue-fix] by disabling Elixir checking by default.
>
> **If your version of Syntastic is below `3.4.0-107` (16 July 2014), you should
> update to a newer version.**
[vim-plug]: https://github.com/junegunn/vim-plug
[vundle]: https://github.com/gmarik/Vundle.vim
[neobundle]: https://github.com/Shougo/neobundle.vim
[pathogen]: https://github.com/tpope/vim-pathogen
[syntastic]: https://github.com/scrooloose/syntastic
[syntastic-issue-fix]: https://github.com/scrooloose/syntastic/commit/1d19dff701524ebed90a4fbd7c7cd75ab954b79d
25 changes: 25 additions & 0 deletions vim/bundle/vim-elixir/compiler/exunit.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if exists("current_compiler")
finish
endif
let current_compiler = "exunit"

if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif

let s:cpo_save = &cpo
set cpo-=C
CompilerSet makeprg=mix\ test
CompilerSet errorformat=
\%E\ \ %n)\ %m,
\%+G\ \ \ \ \ **\ %m,
\%+G\ \ \ \ \ stacktrace:,
\%C\ \ \ \ \ %f:%l,
\%+G\ \ \ \ \ \ \ (%\\w%\\+)\ %f:%l:\ %m,
\%+G\ \ \ \ \ \ \ %f:%l:\ %.%#,
\**\ (%\\w%\\+)\ %f:%l:\ %m

let &cpo = s:cpo_save
unlet s:cpo_save

" vim: nowrap sw=2 sts=2 ts=8:
16 changes: 16 additions & 0 deletions vim/bundle/vim-elixir/ftdetect/elixir.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
au BufRead,BufNewFile *.ex,*.exs call s:setf('elixir')
au BufRead,BufNewFile *.eex call s:setf('eelixir')

au FileType elixir,eelixir setl sw=2 sts=2 et iskeyword+=!,?

au BufNewFile,BufRead * call s:DetectElixir()

function! s:setf(filetype) abort
let &filetype = a:filetype
endfunction

function! s:DetectElixir()
if getline(1) =~ '^#!.*\<elixir\>'
call s:setf('elixir')
endif
endfunction
87 changes: 87 additions & 0 deletions vim/bundle/vim-elixir/ftplugin/eelixir.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
if exists("b:did_ftplugin")
finish
endif

let s:save_cpo = &cpo
set cpo-=C

let s:undo_ftplugin = ""
let s:browsefilter = "All Files (*.*)\t*.*\n"
let s:match_words = ""

if !exists("g:eelixir_default_subtype")
let g:eelixir_default_subtype = "html"
endif

if !exists("b:eelixir_subtype")
let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
let b:eelixir_subtype = matchstr(s:lines,'eelixir_subtype=\zs\w\+')
if 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\+$')
endif
if b:eelixir_subtype == 'ex'
let b:eelixir_subtype = 'elixir'
elseif b:eelixir_subtype == 'exs'
let b:eelixir_subtype = 'elixir'
elseif b:eelixir_subtype == 'yml'
let b:eelixir_subtype = 'yaml'
elseif b:eelixir_subtype == 'js'
let b:eelixir_subtype = 'javascript'
elseif b:eelixir_subtype == 'txt'
" Conventional; not a real file type
let b:eelixir_subtype = 'text'
elseif b:eelixir_subtype == ''
let b:eelixir_subtype = g:eelixir_default_subtype
endif
endif

if exists("b:eelixir_subtype") && b:eelixir_subtype != ''
exe "runtime! ftplugin/".b:eelixir_subtype.".vim ftplugin/".b:eelixir_subtype."_*.vim ftplugin/".b:eelixir_subtype."/*.vim"
else
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
endif
unlet! b:did_ftplugin

" Override our defaults if these were set by an included ftplugin.
if exists("b:undo_ftplugin")
let s:undo_ftplugin = b:undo_ftplugin
unlet b:undo_ftplugin
endif
if exists("b:browsefilter")
let s:browsefilter = b:browsefilter
unlet b:browsefilter
endif
if exists("b:match_words")
let s:match_words = b:match_words
unlet b:match_words
endif

runtime! ftplugin/elixir.vim ftplugin/elixir_*.vim ftplugin/elixir/*.vim
let b:did_ftplugin = 1

" Combine the new set of values with those previously included.
if exists("b:undo_ftplugin")
let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin
endif
if exists ("b:browsefilter")
let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter
endif
if exists("b:match_words")
let s:match_words = b:match_words . ',' . s:match_words
endif

" Load the combined list of match_words for matchit.vim
if exists("loaded_matchit")
let b:match_words = s:match_words
endif

setlocal comments=:<%#
setlocal commentstring=<%#\ %s\ %>

let b:undo_ftplugin = "setl cms< "
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin

let &cpo = s:save_cpo
56 changes: 56 additions & 0 deletions vim/bundle/vim-elixir/ftplugin/elixir.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
if (exists("b:did_ftplugin"))
finish
endif
let b:did_ftplugin = 1


" Matchit support
if exists("loaded_matchit") && !exists("b:match_words")
let b:match_ignorecase = 0

let b:match_words = '\:\@<!\<\%(do\|fn\)\:\@!\>' .
\ ':' .
\ '\<\%(else\|elsif\|catch\|after\|rescue\)\:\@!\>' .
\ ':' .
\ '\:\@<!\<end\>' .
\ ',{:},\[:\],(:)'
endif

setlocal comments=:#
setlocal commentstring=#\ %s

function! GetElixirFilename(word)
let word = a:word

" get first thing that starts uppercase, until the first space or end of line
let word = substitute(word,'^\s*\(\u[^ ]\+\).*$','\1','g')

" remove any trailing characters that don't look like a nested module
let word = substitute(word,'\.\U.*$','','g')

" replace module dots with slash
let word = substitute(word,'\.','/','g')

" remove any special chars
let word = substitute(word,'[^A-z0-9-_/]','','g')

" convert to snake_case
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g')
let word = substitute(word,'-','_','g')
let word = tolower(word)

return word
endfunction

let &l:path =
\ join([
\ getcwd().'/lib',
\ getcwd().'/src',
\ getcwd().'/deps/**/lib',
\ getcwd().'/deps/**/src',
\ &g:path
\ ], ',')
setlocal includeexpr=GetElixirFilename(v:fname)
setlocal suffixesadd=.ex,.exs,.eex,.erl,.yrl,.hrl
67 changes: 67 additions & 0 deletions vim/bundle/vim-elixir/indent/eelixir.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
if exists("b:did_indent")
finish
endif

runtime! indent/elixir.vim
unlet! b:did_indent
setlocal indentexpr=

if exists("b:eelixir_subtype")
exe "runtime! indent/".b:eelixir_subtype.".vim"
else
runtime! indent/html.vim
endif
unlet! b:did_indent

if &l:indentexpr == ''
if &l:cindent
let &l:indentexpr = 'cindent(v:lnum)'
else
let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
endif
endif
let b:eelixir_subtype_indentexpr = &l:indentexpr

let b:did_indent = 1

setlocal indentexpr=GetEelixirIndent()
setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=catch,=after,=rescue

" Only define the function once.
if exists("*GetEelixirIndent")
finish
endif

function! GetEelixirIndent(...)
if a:0 && a:1 == '.'
let v:lnum = line('.')
elseif a:0 && a:1 =~ '^\d'
let v:lnum = a:1
endif
let vcol = col('.')
call cursor(v:lnum,1)
let inelixir = searchpair('<%','','%>','W')
call cursor(v:lnum,vcol)
if inelixir && getline(v:lnum) !~ '^<%\|^\s*%>'
let ind = GetElixirIndent()
else
exe "let ind = ".b:eelixir_subtype_indentexpr
endif
let lnum = prevnonblank(v:lnum-1)
let line = getline(lnum)
let cline = getline(v:lnum)
if cline =~# '^\s*<%\s*\%(end\|else\|elsif\|catch\|after\|rescue\)\>.*%>'
let ind = ind - &sw
elseif line =~# '\S\s*<%\s*end\s*%>'
let ind = ind - &sw
endif
if line =~# '<%[=%]\=\s*.*\<do\s*%>'
let ind = ind + &sw
elseif line =~# '<%\s*\%(else\|elsif\|catch\|after\|rescue\)\>.*%>'
let ind = ind + &sw
endif
if cline =~# '^\s*%>\s*$'
let ind = ind - &sw
endif
return ind
endfunction
Loading

0 comments on commit e96336d

Please sign in to comment.