Skip to content
Browse files

foom

  • Loading branch information...
1 parent 6ff893c commit 91f2f85008282ee5b0d44e3b9eea897d24f9db0f @Kashomon committed
Showing with 177 additions and 0 deletions.
  1. +177 −0 javac_out.vim
View
177 javac_out.vim
@@ -0,0 +1,177 @@
+" To be used with std out.
+
+let s:tmp_file = "____JavacOutErrorList____"
+let g:javac_out_min_win_height = 5
+let g:javac_out_max_win_height = 10
+
+function! JavacOut_GetJavacErrors(errors)
+ if bufexists(s:tmp_file)
+ exe 'bdelete ' . s:tmp_file
+ endif
+ let errorsl = split(a:errors, '\n')
+
+ let errors = []
+ let cur_error = []
+
+ let pathReg = '^/\w*/\w*/.*'
+ let symbolReg = '^symbol\s*:\s*.*'
+ let locReg = '^location:\s*.*'
+ let linenum = 0
+ let errorline = -1 " mark where the error occurred
+
+ for line in errorsl
+ if match(line, pathReg) != -1
+ if !empty(cur_error)
+ call add(errors, cur_error)
+ let cur_error = []
+ endif
+ let errorline = linenum
+ endif
+ if errorline != -1 && errorline >= (linenum - 4)
+ call add(cur_error, line)
+ endif
+ let linenum += 1
+ endfor
+
+ let s:error_dict = {}
+ let first_lines = []
+ let error_num = 0
+ let spaces = len(string(error_num))
+ for error in errors
+ let str_error_num = string(error_num)
+ let td_space = spaces - len(str_error_num) + 5
+ let error_marker = '{' . str_error_num . '}'
+ for indx in range(td_space)
+ let error_marker .= ' '
+ endfor
+
+ let first_line = error_marker . substitute(error[0], '/\(\w*/\)*', '', '')
+ call add(first_lines, first_line)
+ let s:error_dict[first_line] = error
+ let error_num += 1
+ endfor
+
+ let g:javac_errors_curpos = getpos(".")
+ let g:javac_errors_oldwindow = winnr()
+
+ let winheight = len(first_line)
+ if winheight < g:javac_out_min_win_height
+ let winheight = g:javac_out_min_win_height
+ elseif winheight > g:javac_out_max_win_height
+ let winheight = g:javac_out_max_win_height
+ endif
+
+ let s:javac_winheight = winheight
+
+ call writefile(first_lines, s:tmp_file)
+ exe "bo " . s:javac_winheight . " new " . s:tmp_file
+ call delete(s:tmp_file)
+ call s:InitializeBuffer()
+endfunction
+
+function s:PathShortener(line)
+ let curpath
+endfunction
+
+function! s:InitializeBuffer()
+ cal setpos(".", [0,0,0,0])
+ setlocal nonu
+ setlocal noro
+ setlocal nomodifiable
+ setlocal noswapfile
+ setlocal buftype=nofile
+ setlocal bufhidden=delete
+
+ if v:version >= 700
+ setlocal cursorline
+ endif
+
+ if has('syntax')
+ syn match ErrorNum '{\d*}' contained
+ syn match JavaName '\s\s\w*\.java' contained
+ syn match JavaErrorPrefix '{\d*}*\s*\w*\.java' contains=ErrorNum,JavaName
+
+ syn match SymbolName '\s\ssymbol\s*:'
+ syn match LocName '\s\slocation:'
+ syn match LineNum ':\@<=\d*'
+ syn match ErrorState ':\@<=[^:]*$'
+ hi def link ErrorNum Keyword
+ hi def link JavaName Directory
+ hi def link ErrorState Function
+ hi def link LineNum Keyword
+ hi def link SymbolName Keyword
+ hi def link LocName Keyword
+ endif
+
+ nnoremap <buffer> <CR> :call JavacOut_JumpToError() <CR>
+
+ let s:expanded_groups = {}
+ let s:lines_to_group_key = {}
+ nnoremap <silent> <buffer> <SPACE> :call JavacOut_Expand() <CR>
+
+ exec 'au BufEnter,BufWinEnter,WinEnter <buffer> resize ' . s:javac_winheight
+endfunction
+
+function! JavacOut_Expand()
+ let line = getline(".")
+
+ if has_key(s:lines_to_group_key, line)
+ let group_key = s:lines_to_group_key[line]
+ let group = s:expanded_groups[group_key]
+ setlocal modifiable
+ for gline in group
+ exec 'g/' . substitute(gline, '/', '\/', 'g') . '/d'
+ call remove(s:lines_to_group_key, gline)
+ endfor
+ call remove(s:expanded_groups, group_key)
+ call remove(s:lines_to_group_key, group_key)
+ setlocal nomodifiable
+ return
+ endif
+
+ let nline = substitute(line, '/', '\/', 'g')
+ let prefix = ' ' . substitute(matchstr(line, '^{\d*}\s*'),
+ \ ' $', '', '')
+
+ let full_error = []
+ for oline in copy(s:error_dict[line])
+ call add(full_error, prefix . oline)
+ endfor
+
+ call remove(full_error, 0)
+ call insert(full_error, line)
+ let outstr = substitute(join(full_error, "\r"), '/', '\\/', 'g')
+ let outstr = substitute(outstr, '[&]', '\\&', 'g')
+
+ setlocal modifiable
+ exe '%s/\V' . nline . '/' . outstr . '/'
+ setlocal nomodifiable
+
+ for oline in full_error
+ let s:lines_to_group_key[oline] = full_error[0]
+ endfor
+
+ let key = full_error[0]
+ call remove(full_error, 0)
+ let s:expanded_groups[key] = full_error
+endfunction
+
+function! JavacOut_JumpToError()
+ let line = getline(".")
+ if !has_key(s:error_dict, line)
+ if has_key(s:lines_to_group_key, line)
+ let line = s:lines_to_group_key[line]
+ else
+ return
+ endif
+ endif
+
+ exe g:javac_errors_oldwindow . " wincmd w"
+ let full_error_line = s:error_dict[line][0]
+ let file = matchstr(full_error_line, '^/\(\w*/\)*\w*\.java')
+ let linenum = substitute(matchstr(full_error_line, ':\d*:'), ':', '', 'g')
+ exe 'edit ' . file
+
+ call setpos(".", [0, linenum, 0, 0])
+ normal! zz
+endfunction

0 comments on commit 91f2f85

Please sign in to comment.
Something went wrong with that request. Please try again.