Skip to content

Commit 940d10b

Browse files
author
Gaspar Chilingarov
committed
major cleanup/tidy/bugfix
1 parent 0dd5200 commit 940d10b

File tree

9 files changed

+255
-205
lines changed

9 files changed

+255
-205
lines changed

CHEATSHEET.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ shortcuts/commands:
1515
* `<Ctrl-v>` opens selected files in vertical split
1616
* `<Ctrl-s>` opens selected files in horizontal split
1717

18-
* `<Leader>xt` opens correlative source/test file
19-
* `<Leader>xs` opens correlative source/test file in horizontal split
20-
* `<Leader>xv` opens correlative source/test file in vertical split
21-
* `<Leader>x!` opens correlative source/test, creates directories if necessary
18+
* `<Leader>tt` finds and opens correlative source/test file.
19+
See more shortcuts in **ExUnit** section below.
2220

2321
**In file**
2422
* `<F1>` shows Elixir docs for function under cursor.
@@ -47,6 +45,7 @@ shortcuts/commands:
4745
* `<Enter>` or click on function name takes you to function definition.
4846
* `<p>` on function name takes you to function definition, but focus stays in tagbar.
4947
* `<P>` on function name opens function in preview window.
48+
* `<Ctrl-W><Ctrl-Z>` or `:pc` close preview window.
5049
5150
More on [tagbar page](https://majutsushi.github.io/tagbar/).
5251
@@ -104,8 +103,9 @@ shortcuts/commands:
104103
105104
#### Tracing
106105
* `<Leader>te` execute ExUnit test under cursor with tracing and window with
107-
trace output
108-
* `<Leader>ts` execute selected text with tracing and show trace
106+
trace output (mnemonics: Trace Exunit)
107+
* `<Leader>ty` execute selected text with tracing and show trace (mnemonics:
108+
Trace Yanked).
109109
110110
**In trace window**
111111
* `<Enter>` opens file with module/function under cursor and changes window

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Following commands and shortcuts are available:
248248

249249
* `ErlTraceTest` or `<Leader>te` runs ExUnit test under cursor with tracing
250250
enabled and shows resulting trace in separate window.
251-
* `ErlTraceSelection` or `<Leader>ts` runs selected test with tracing enabled
251+
* `ErlTraceSelection` or `<Leader>ty` runs selected test with tracing enabled
252252
and shows resulting trace in separate window.
253253

254254
In tracing window there are shortcuts available:

ROADMAP.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Items marked with x are done.
1212
* test on our team first ;)))
1313

1414
## Functionality
15-
* make it load w/reasonable defaults in empty vim (top)
15+
x make it load w/reasonable defaults in empty vim (top)
1616
* add tpope/sensibleDefaults plugin
1717
x add indentLine plugin to bundle (top)
1818
x setup Hack font for GUI + size changes
@@ -45,10 +45,10 @@ Items marked with x are done.
4545

4646
## Debuging & developing
4747
* generate trace files and nicely show them
48-
* run test clause and record call/return values/messages trace
49-
* syntax/highlighting for trace file
50-
* allow jumping to functions/clauses in trace/profile files
51-
* shortcuts to trace selection/test
48+
x run test clause and record call/return values/messages trace
49+
x syntax/highlighting for trace file
50+
x allow jumping to functions/clauses in trace/profile files
51+
x shortcuts to trace selection/test
5252
* run test clause and record line-by-line execution trace using debugger (low)
5353
* run test clause and record fprof for it
5454
* syntax highlight for fprof dump file

autoload/vimide.vim

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
let s:VIMIDE_BOOT_FINISHED = 0
66

7+
let s:rootPath = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
8+
let s:bundlePath = s:rootPath . "/bundle"
9+
10+
function! vimide#getRootPath() " {{{
11+
return s:rootPath
12+
endfunction " }}}
13+
14+
function! vimide#getBundlePath() " {{{
15+
return s:bundlePath
16+
endfunction " }}}
17+
718
function! vimide#setDefaults() " {{{
819
call s:setGlobal('g:vimide_global_enable', 0)
920
call s:setGlobal('g:vimide_manage_indents', 1)
@@ -43,6 +54,7 @@ function! vimide#setDefaults() " {{{
4354
call s:setGlobal('g:vimide_install_comment_shortcuts', 1)
4455
call s:setGlobal('g:vimide_install_align_shortcuts', 1)
4556
call s:setGlobal('g:vimide_install_other_shortcuts', 1)
57+
call s:setGlobal('g:vimide_install_elixir_shortcuts', 1)
4658
call s:setGlobal('g:vimide_manage_misc_settings', 1)
4759
call s:setGlobal('g:vimide_install_hack_font', 1)
4860
endfunction " }}}
@@ -56,7 +68,10 @@ function! vimide#init() " {{{
5668
endfunction " }}}
5769

5870
function! vimide#boot(setGlobal) " {{{
59-
if !s:VIMIDE_BOOT_FINISHED
71+
let bootVarName = (a:setGlobal ? "s:VIMIDE_BOOT_FINISHED" : "b:VIMIDE_BOOT_FINISHED")
72+
let bootFinished = s:VIMIDE_BOOT_FINISHED || (exists(bootVarName) && execute("echo ".bootVarName) == 1)
73+
74+
if !bootFinished
6075
if g:vimide_colorscheme != '' | call vimide#setColorscheme(a:setGlobal) | endif
6176
if g:vimide_manage_encoding | call vimide#setVimEncodingSettings(a:setGlobal) | endif
6277
if g:vimide_manage_indents | call vimide#setIndentSettings(a:setGlobal) | endif
@@ -74,10 +89,12 @@ function! vimide#boot(setGlobal) " {{{
7489
if g:vimide_install_other_shortcuts | call vimide#setOtherShortcuts(a:setGlobal) | endif
7590
if g:vimide_install_hack_font | call vimide#setHackFont(a:setGlobal) | endif
7691
if g:vimide_manage_misc_settings | call vimide#setMiscSettings(a:setGlobal) | endif
77-
let s:VIMIDE_BOOT_FINISHED = 1
92+
execute("let " . bootVarName . "= 1")
7893
endif
7994

8095
if &filetype == 'elixir'
96+
" filetype specific initialization goes here, but it is basically very
97+
" small piece of code
8198
call vimide#elixir#boot()
8299
endif
83100

@@ -231,9 +248,7 @@ function! vimide#setIndentLineSettigns(setGlobal) "{{{
231248
" let g:indentLine_char = '⎥' straigh line
232249
" let g:indentLine_char = '⎸' (needs FreeSerif)
233250
else
234-
" TODO: add BufferEnter/Exit logic to toggle indentLine only in elixir
235-
" buffers
236-
let pass = 1
251+
nnoremap <silent> <buffer> <C-K><C-I> :IndentLinesToggle<CR>
237252
endif
238253
endfunction "}}}
239254

@@ -295,6 +310,8 @@ function! vimide#setCommentShortcuts(setGlobal) " {{{
295310
" we want comments to be nicely aligned under each other and not follow
296311
" indentation
297312
let g:NERDDefaultAlign = "left"
313+
let g:NERDCommentEmptyLines = 1
314+
298315
" TODO: think of possibility leaving commented area in visual selected mode
299316
" (if it is good idea at all :)
300317
if a:setGlobal
@@ -330,22 +347,41 @@ function! vimide#setTabularizeShortcuts(setGlobal) " {{{
330347
" ####################################################################
331348
" Integration with Tabularize
332349

350+
" TODO: may be remove all indenting funcitonality alltogether, as it may be
351+
" extremely annoying
352+
333353
if a:setGlobal
334354
" tabularize both => and =
335-
map <Leader>= =:Tabularize /=><CR>
336-
map <Leader>eq =:Tabularize /=/<CR>
355+
nmap <Leader>= ==:Tabularize /=><CR>
356+
nmap <Leader>eq ==:Tabularize /=/<CR>
337357
" tabularize case clauses
338-
map <Leader>- =:Tabularize /-><CR>
358+
nmap <Leader>- ==:Tabularize /-><CR>
339359
" tabularize : in hashmaps and similar
340-
map <Leader>: =:Tabularize /\v(:)@<=\s/l0<CR>
360+
nmap <Leader>: ==:Tabularize /\v(:)@<=\s/l0<CR>
361+
362+
" tabularize both => and =
363+
vmap <Leader>= =:'<,'>Tabularize /=><CR>
364+
vmap <Leader>eq =:'<,'>Tabularize /=/<CR>
365+
" tabularize case clauses
366+
vmap <Leader>- =:'<,'>Tabularize /-><CR>
367+
" tabularize : in hashmaps and similar
368+
vmap <Leader>: =:'<,'>Tabularize /\v(:)@<=\s/l0<CR>
341369
else
342370
" tabularize both => and =
343-
map <buffer> <Leader>= =:Tabularize /=><CR>
344-
map <buffer> <Leader>eq =:Tabularize /=/<CR>
371+
nmap <buffer> <Leader>= ==:Tabularize /=><CR>
372+
nmap <buffer> <Leader>eq ==:Tabularize /=/<CR>
345373
" tabularize case clauses
346-
map <buffer> <Leader>- =:Tabularize /-><CR>
374+
nmap <buffer> <Leader>- ==:Tabularize /-><CR>
347375
" tabularize : in hashmaps and similar
348-
map <buffer> <Leader>: =:Tabularize /\v(:)@<=\s/l0<CR>
376+
nmap <buffer> <Leader>: ==:Tabularize /\v(:)@<=\s/l0<CR>
377+
378+
" tabularize both => and =
379+
vmap <buffer> <Leader>= =:'<,'>Tabularize /=><CR>
380+
vmap <buffer> <Leader>eq =:'<,'>Tabularize /=/<CR>
381+
" tabularize case clauses
382+
vmap <buffer> <Leader>- =:'<,'>Tabularize /-><CR>
383+
" tabularize : in hashmaps and similar
384+
vmap <buffer> <Leader>: =:'<,'>Tabularize /\v(:)@<=\s/l0<CR>
349385
endif
350386
endfunction " }}}
351387

@@ -382,7 +418,6 @@ function! vimide#setOtherShortcuts(setGlobal) " {{{
382418
map <C-K><C-l> :exec 'match NonText /\<' . expand("<cword>") . '\>/'<CR>
383419
384420
" delete buffer and keep split
385-
" cannot have it local
386421
cab bdd bp\|bd #
387422

388423
" refactoring support
@@ -435,6 +470,9 @@ function! vimide#setOtherShortcuts(setGlobal) " {{{
435470
nmap <buffer> <F2> :w<CR>
436471
imap <buffer> <F2> <Esc>:w<CR>a
437472
473+
" delete buffer and keep split
474+
cab <buffer> bdd bp\|bd #
475+
438476
" lookup item under the cursor in file and show the list of
439477
" entries
440478
"
@@ -529,6 +567,7 @@ function! vimide#stripTrailingWhitespace() " {{{
529567
call winrestview(l:save)
530568
endfunction " }}}
531569

570+
" TODO: consolidate in lib
532571
function! s:setGlobal(name, default) " {{{
533572
if !exists(a:name)
534573
if type(a:name) == 0 || type(a:name) == 5

autoload/vimide/elixir.vim

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,164 @@
1+
function! vimide#elixir#boot()
2+
call s:setGlobal('g:alchemist#elixir_erlang_src', vimide#getRootPath() . "/sources")
13

2-
function vimide#elixir#boot()
34
setlocal wildignore+=*.beam
5+
if g:vimide_install_elixir_shortcuts | call vimide#elixir#setOtherShortcuts() | endif
6+
7+
call vimide#elixir#installTagbarIntegration()
8+
endfunction
9+
10+
function! vimide#elixir#setOtherShortcuts()
11+
" ####################################################################
12+
" integration with vim-alchemist
13+
nnoremap <buffer> <silent> <F1> :call alchemist#exdoc()<CR>
14+
endfunction
15+
16+
"let g:ConqueTerm_CloseOnEnd=1
17+
"let g:alchemist_iex_term_size = 15
18+
19+
function! vimide#elixir#tagbarFilter(tags) " {{{
20+
" remove OTP callbacks from ordinary function list
21+
call filter(a:tags, ' !(v:val.fields.kind == "f" && v:val.name =~ "\\v(handle_call|handle_info|handle_cast|init|terminate)") ')
22+
23+
function! Arity_extract(idx, tag)
24+
if a:tag.fields.kind == 'f' || a:tag.fields.kind == 'g'
25+
let args_string = substitute(a:tag.pattern, "^.*defp\\?[ \t]*".a:tag.name."[ \t]*", "", "")
26+
let args_string = substitute(args_string, "do[ \t]*\\\\[$]$", "", "") " multiline
27+
" TODO: remove
28+
" if a:tag.pattern =~ "defp reply"
29+
" debug echo("asd")
30+
" endif
31+
let args_string = substitute(args_string, ")\\([ \t]*when.*\\)\\?,[ \t]*do.*\\\\[$]$", ")", "")
32+
let args_string = substitute(args_string, "[ \t]*", "", "g")
33+
34+
let args_len = len(args_string)
35+
36+
if args_len == 0
37+
let a:tag.name = a:tag.name."/0"
38+
else
39+
let old_args_len = -10000
40+
while args_len != old_args_len
41+
let args_string = substitute(args_string, "{[^}]*}", "", "g")
42+
let args_string = substitute(args_string, "\\[[^]]*\\]", "", "g")
43+
let old_args_len = args_len
44+
let args_len = len(args_string)
45+
endwhile
46+
47+
let comma_count = len(substitute(args_string, "[^,]", "", "g"))
48+
let a:tag.name = a:tag.name . "/" . (comma_count + 1)
49+
endif
50+
51+
return a:tag
52+
else
53+
return a:tag
54+
endif
55+
endfunction
56+
57+
" replaces function names with function_name/arity notation
58+
call map(a:tags, function('Arity_extract'))
59+
60+
let seen_list = map(copy(a:tags), '[v:val.fields.kind, v:val.name, v:val.fields.line]')
61+
62+
let seen_fnames = {}
63+
for [kind, fname, line] in seen_list
64+
if ! has_key(seen_fnames, kind.fname)
65+
let seen_fnames[kind.fname] = line
66+
endif
67+
endfor
68+
69+
" leaves only first definition of function with same arity
70+
function! Filter_fun(seen_hash, idx, tag)
71+
let key = a:tag.fields.kind . a:tag.name
72+
let line = a:tag.fields.line
73+
74+
return a:seen_hash[key] == line
75+
endfunction
76+
77+
call filter(a:tags, function('Filter_fun', [seen_fnames]))
78+
79+
return a:tags
80+
endfunction " }}}
81+
82+
function! vimide#elixir#installTagbarIntegration()
83+
" ####################################################################
84+
" integration with Tagbar
85+
"
86+
87+
let g:tagbar_type_elixir = {
88+
\ 'ctagstype' : 'elixir',
89+
\ 'deffile' : vimide#getRootPath() . '/extras/elixir-ctags/.ctags',
90+
\ 'transform': function("vimide#elixir#tagbarFilter"),
91+
\ 'kinds' : [
92+
\ 'm:modules:1',
93+
\ 'O:OTP callbacks',
94+
\ 't:tests',
95+
\ 'f:functions (public)',
96+
\ 'g:functions (private)',
97+
\ 'c:callbacks',
98+
\ 'd:delegates',
99+
\ 'e:exceptions',
100+
\ 'i:implementations',
101+
\ 'a:macros',
102+
\ 'o:operators',
103+
\ 's:structs',
104+
\ 'p:protocols',
105+
\ 'r:records',
106+
\ 'T:types',
107+
\ 'z:foo'
108+
\ ]
109+
\ }
110+
4111
endfunction
112+
113+
114+
"function! ErlBalloonExpr()
115+
" " return 'Cursor is at line ' . v:beval_lnum .
116+
" " \', column ' . v:beval_col .
117+
" " \ ' of file ' . bufname(v:beval_bufnr) .
118+
" " \ ' on word "' . v:beval_text . '"'
119+
"
120+
" let text = alchemist#get_doc(v:beval_text)
121+
" return text
122+
"endfunction
123+
"
124+
"set bexpr=ErlBalloonExpr()
125+
"set ballooneval
126+
127+
"map <F12> :IEx<CR>
128+
129+
" TODO: for future work
130+
" ####################################################################
131+
" Elixir cross reference
132+
"
133+
" mix xref callers Mod
134+
" mix xref callers Mod.Fun
135+
" mix xref callers Mod.Fun/Arity
136+
"
137+
" which files are called/included
138+
" mix xref graph --source lib/feed/betco_pusher/stream/api.ex --format pretty
139+
"
140+
" which files call/include this one
141+
" mix xref graph --sink lib/feed/betco_pusher/stream/api.ex --format pretty
142+
"
143+
" mix xref unreachable
144+
" mix xref warnings
145+
"
146+
147+
function! s:ShowXRef()
148+
" does not work well right now :)
149+
let a=alchemist#get_current_module_details()['module']['name']
150+
let b=tagbar#currenttag('%s', '')
151+
let c=a.".".b
152+
exec "Mix xref callers ".c
153+
endfunction
154+
155+
" TODO: consolidate in lib
156+
function! s:setGlobal(name, default) " {{{
157+
if !exists(a:name)
158+
if type(a:name) == 0 || type(a:name) == 5
159+
exec "let " . a:name . " = " . a:default
160+
elseif type(a:name) == 1
161+
exec "let " . a:name . " = '" . escape(a:default, "\'") . "'"
162+
endif
163+
endif
164+
endfunction " }}}

bundle/vim-elixir-exunit

0 commit comments

Comments
 (0)