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
1223let g: ConqueTerm_CloseOnEnd= 1
1324let 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 =
31146map <Leader> = =:Tabularize /=><CR>
32147map <Leader> eq =:Tabularize /=/<CR>
@@ -35,6 +150,13 @@ map <Leader>- =:Tabularize /-><CR>
35150" tabularize hashmaps and similar
36151map <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
54176imap <C-k><C-[> <C-k> [
55177imap <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