Skip to content

Commit 4d3bc9d

Browse files
author
Gaspar Chilingarov
committed
move code around to file-type specific file + more settings
1 parent 268ae54 commit 4d3bc9d

4 files changed

Lines changed: 415 additions & 139 deletions

File tree

README.md

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,94 @@
1-
21
# vim-ide-elixir
32

4-
Highly opnionated setup of plugins to start programming in Elixir in minutes.
3+
Highly opinionated setup of plugins to start programming in Elixir in minutes.
4+
5+
Aim of the project is to give reasonable preset of defaults for Elixir-based development to
6+
avoid laborious task of finding and tuning of plugins/themes.
7+
8+
## Features
9+
* Navigation
10+
* Jump to module/function definitions
11+
* Module/function/callback window for navigating in single file
12+
* Fuzzy search by function/module name in file
13+
* Fuzzy filename search in project
14+
* Navigation to Elixir/Erlang source code
15+
* Editing
16+
* Line comment/uncomment
17+
* Autocompletion of module/function names
18+
* Autodetection of spacing format in your project (tab/spaces)
19+
* Removal of trailing spaces
20+
* Reformatting code (hashes, assignments, etc)
21+
* Other
22+
* Colorschemes for Elixir programming
23+
* Git integration directly from Vim.
24+
* Viewing of Module/function documentation
25+
* Restore buffer position on load
26+
* Clutter free vim-airline settings
27+
28+
29+
See sections below for usage instructions and shortcuts.
30+
31+
## Installation
32+
33+
Right now only [pathogen](https://github.com/tpope/vim-pathogen) installation is supported.
34+
Manual and Vundle methods are not supported.
35+
Following command with download plugin and all extras it uses.
36+
37+
```sh
38+
cd ~/.vim/bundle
39+
git clone https://github.com/gasparch/vim-ide-elixir.git vim-ide-elixir
40+
cd ~/.vim/bundle/vim-ide-elixir
41+
git submodule update --init --recursive
42+
```
543

6-
Aim of the project is to give reasonable preset of defaults for elixir-based development to
7-
avoid laborous tuning of plugins/themes.
44+
Update your `~/.vimrc` to contain following line instead of just `pathogen#infect`.
845

46+
```vim
47+
execute pathogen#infect("bundle/{}", "bundle/vim-ide-elixir/bundle/{}")
48+
```
949

10-
## Source browsing
50+
### Installing required utilities
1151

12-
Tagbar most of the time shows correct arity on functions and does not report multiple function clauses.
13-
GenServer callbacks moved to separate group.
52+
In order to properly work this plugin requires number of additional programs installed.
1453

15-
## Shortcuts
54+
#### Exuberant Ctags
55+
For now you will need [Exuberant Ctags](http://ctags.sourceforge.net/) in order to get function search & tagbar working.
56+
Version 5.5 or higher is required.
1657

17-
`F4` for opening Tagbar.
18-
`Ctrl-@` to use Ctrl-P search on function names and quick jump on them
19-
`<Leader>l` to fuzzy search text in file
58+
**Ubuntu installation**
2059

21-
## Starting using plugin
22-
Right now initialization from inside the plugin does not work properly.
60+
```sh
61+
sudo apt-get install -y exuberant-ctags
62+
```
2363

24-
If you are using pathogen please replace your `pathogen#infect` line with following.
64+
#### Checking out Elixir and Erlang source code
2565

26-
```vim
27-
execute pathogen#infect("bundle/{}", "bundle/vim-ide-elixir/bundle/{}")
28-
```
66+
In order to be able to just to Elixir/Erlang core libraries sources, you need them checked out from github.
67+
Run provided script to automatically check out matching Erlang/OTP and Elixir versions.
2968

30-
## how to initialize submodules
31-
```
32-
git submodule update --init --recursive
69+
```vim
70+
./get_otp_elixir_sources.sh
3371
```
3472

35-
## how to update submodules
36-
```
73+
## Updating plugin & submodules
74+
```sh
75+
cd ~/.vim/bundle/vim-ide-elixir
76+
git pull
3777
git submodule update --remote --merge
3878
```
3979

80+
## Source browsing
81+
82+
Tagbar most of the time shows correct arity on functions and does not report multiple function clauses.
83+
GenServer callbacks moved to separate group.
84+
85+
## Shortcuts
86+
87+
`F4` for opening Tagbar.
88+
`Ctrl-@` to use Ctrl-P search on function names and quick jump on them
89+
`<Leader>l` to fuzzy search text in file
90+
91+
4092

41-
- needs exuberant-ctags installed
42-
```
43-
apt-get install exuberant-ctags
44-
```
4593

4694

bundle/vim-elixir-fold

ftplugin/elixir.vim

Lines changed: 234 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
let s:path = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
2+
let s:bundle_path = s:path."/bundle"
13

4+
" general vim settings
5+
set updatetime=500
6+
set autoindent
7+
set cindent
8+
set smartindent
9+
set noinfercase
10+
set noerrorbells
211

3-
"set expandtab
4-
"set tabstop=2
5-
"set shiftwidth=2
12+
set incsearch
13+
set nohls
614

15+
" tab formatting settings - automatically provided by vim-sleuth
716

8-
nmap <F1> K
17+
" ####################################################################
18+
" integratino with vim-alchemist
19+
nnoremap <buffer> <silent> F1 :call alchemist#exdoc()<CR>
920
10-
let g:alchemist#elixir_erlang_src = "/home/nm/dev/github"
21+
let g:alchemist#elixir_erlang_src = expand("<sfile>:p:h:h") . "/source"
1122

1223
let g:ConqueTerm_CloseOnEnd=1
1324
let g:alchemist_iex_term_size = 15
@@ -27,6 +38,110 @@ let g:alchemist_iex_term_size = 15
2738
"set bexpr=ErlBalloonExpr()
2839
"set ballooneval
2940

41+
42+
43+
" ####################################################################
44+
" integration with Tagbar
45+
"
46+
function! Tag_transform(tags) " {{{
47+
" remove OTP callbacks from ordinary function list
48+
call filter(a:tags, ' !(v:val.fields.kind == "f" && v:val.name =~ "\\v(handle_call|handle_info|handle_cast|init|terminate)") ')
49+
50+
function! Arity_extract(idx, tag)
51+
if a:tag.fields.kind == 'f' || a:tag.fields.kind == 'g'
52+
let args_string = substitute(a:tag.pattern, "^.*defp\\?[ \t]*".a:tag.name."[ \t]*", "", "")
53+
let args_string = substitute(args_string, "do[ \t]*\\\\[$]$", "", "") " multiline
54+
" TODO: remove
55+
" if a:tag.pattern =~ "defp reply"
56+
" debug echo("asd")
57+
" endif
58+
let args_string = substitute(args_string, ")\\([ \t]*when.*\\)\\?,[ \t]*do.*\\\\[$]$", ")", "")
59+
let args_string = substitute(args_string, "[ \t]*", "", "g")
60+
61+
let args_len = len(args_string)
62+
63+
if args_len == 0
64+
let a:tag.name = a:tag.name."/0"
65+
else
66+
let old_args_len = -10000
67+
while args_len != old_args_len
68+
let args_string = substitute(args_string, "{[^}]*}", "", "g")
69+
let args_string = substitute(args_string, "\\[[^]]*\\]", "", "g")
70+
let old_args_len = args_len
71+
let args_len = len(args_string)
72+
endwhile
73+
74+
let comma_count = len(substitute(args_string, "[^,]", "", "g"))
75+
let a:tag.name = a:tag.name . "/" . (comma_count + 1)
76+
endif
77+
78+
return a:tag
79+
else
80+
return a:tag
81+
endif
82+
endfunction
83+
84+
" replaces function names with function_name/arity notation
85+
call map(a:tags, function('Arity_extract'))
86+
87+
let seen_list = map(copy(a:tags), '[v:val.fields.kind, v:val.name, v:val.fields.line]')
88+
89+
let seen_fnames = {}
90+
for [kind, fname, line] in seen_list
91+
if ! has_key(seen_fnames, kind.fname)
92+
let seen_fnames[kind.fname] = line
93+
endif
94+
endfor
95+
96+
" leaves only first definition of function with same arity
97+
function! Filter_fun(seen_hash, idx, tag)
98+
let key = a:tag.fields.kind . a:tag.name
99+
let line = a:tag.fields.line
100+
101+
return a:seen_hash[key] == line
102+
endfunction
103+
104+
call filter(a:tags, function('Filter_fun', [seen_fnames]))
105+
106+
return a:tags
107+
endfunction " }}}
108+
109+
let g:tagbar_type_elixir = {
110+
\ 'ctagstype' : 'elixir',
111+
\ 'deffile' : s:path . '/extras/elixir-ctags/.ctags',
112+
\ 'transform': function("Tag_transform"),
113+
\ 'kinds' : [
114+
\ 'm:modules:1',
115+
\ 'O:OTP callbacks',
116+
\ 't:tests',
117+
\ 'f:functions (public)',
118+
\ 'g:functions (private)',
119+
\ 'c:callbacks',
120+
\ 'd:delegates',
121+
\ 'e:exceptions',
122+
\ 'i:implementations',
123+
\ 'a:macros',
124+
\ 'o:operators',
125+
\ 's:structs',
126+
\ 'p:protocols',
127+
\ 'r:records',
128+
\ 'T:types',
129+
\ 'z:foo'
130+
\ ]
131+
\ }
132+
133+
134+
" keyboard shortcuts
135+
nmap <F4> :TagbarToggle<CR>
136+
nmap <C-@> :CtrlPTagbar<CR>
137+
nmap <Leader>l :CtrlPLine<CR>
138+
139+
140+
141+
" ####################################################################
142+
" Integration with Tabularize
143+
144+
30145
" tabularize both => and =
31146
map <Leader>= =:Tabularize /=><CR>
32147
map <Leader>eq =:Tabularize /=/<CR>
@@ -35,6 +150,13 @@ map <Leader>- =:Tabularize /-><CR>
35150
" tabularize hashmaps and similar
36151
map <Leader>: =:Tabularize /\v(:)@<=\s/l0<CR>
37152
153+
154+
155+
156+
" ####################################################################
157+
" Elixir commenting/uncommenting shortcuts
158+
159+
38160
" TODO: make it work better with vim-elixir-fold
39161
" and do not break folds of functions, make commend on column where
40162
" indent level is
@@ -53,3 +175,110 @@ map <C-k><C-]> <C-k>]
53175
54176
imap <C-k><C-[> <C-k>[
55177
imap <C-k><C-]> <C-k>]
178+
179+
180+
181+
function! RestorePos()
182+
if line("'.") > 0
183+
if line("'.") <= line("$")
184+
exe("norm `.zz")
185+
if foldclosed('.') >= 0
186+
. foldopen
187+
endif
188+
else
189+
exe "norm $"
190+
endif
191+
else
192+
if line("'\"") > 0
193+
if line("'\"") <= line("$")
194+
exe("norm '\"zz")
195+
if foldclosed('.') >= 0
196+
. foldopen
197+
endif
198+
else
199+
exe "norm $"
200+
endif
201+
endif
202+
endif
203+
endf
204+
205+
au BufReadPost * call RestorePos()
206+
207+
" Toggle fold state between closed and opened with the space bar
208+
" If there is no fold at current line, just moves forward.
209+
" If it is present, reverse it's state.
210+
function! ToggleFold()
211+
if foldlevel('.') == 0
212+
normal! l
213+
else
214+
if foldclosed('.') < 0
215+
. foldclose
216+
else
217+
. foldopen
218+
endif
219+
endif
220+
" Clear status line
221+
echo
222+
endfunction
223+
noremap <F3> :call ToggleFold()<CR>
224+
225+
nmap n nzz
226+
nmap N Nzz
227+
228+
set showmatch
229+
set matchtime=2
230+
231+
map <Leader>trailing :%s/\s*$//<CR>
232+
map <Leader>$ :%s/\s*$//<CR>
233+
234+
set wildignore=*.o,*.obj,*.beam
235+
236+
" save file like in `borland-ides`
237+
nmap <F2> :w<CR>
238+
imap <F2> <Esc>:w<CR>a
239+
240+
" refactoring support
241+
map <C-K><C-w> :%s#\<<c-r><c-w>\>#
242+
map <C-K><C-a> :%s#\<<c-r><c-a>\>#
243+
244+
set diffopt=iwhite
245+
set undofile
246+
set undodir=~/.vimundo/
247+
248+
set backupdir=~/.vimbackup
249+
set writebackup
250+
set backup
251+
252+
" delete buffer and keep split
253+
cab bdd bp\|bd #
254+
255+
" cross reference
256+
"
257+
" mix xref callers Mod
258+
" mix xref callers Mod.Fun
259+
" mix xref callers Mod.Fun/Arity
260+
"
261+
"
262+
" which files are called/included
263+
" mix xref graph --source lib/feed/betco_pusher/stream/api.ex --format pretty
264+
"
265+
" which files call/include this one
266+
" mix xref graph --sink lib/feed/betco_pusher/stream/api.ex --format pretty
267+
"
268+
" mix xref unreachable
269+
" mix xref warnings
270+
"
271+
272+
function! s:ShowXRef()
273+
" does not work well right now :)
274+
let a=alchemist#get_current_module_details()['module']['name']
275+
let b=tagbar#currenttag('%s', '')
276+
let c=a.".".b
277+
exec "Mix xref callers ".c
278+
endfunction
279+
280+
281+
282+
283+
284+

0 commit comments

Comments
 (0)