dot-files

Dot files managed with stow
git clone http://milesalan.com/git/dot-files
Log | Files | Refs | Mirror | README

commit 6bfe5cc920278a024b590fee40c54a1596ed4e9e
parent 034da0da09c2e6cd0c7eb0c127ad62e6cd9c45de
Author: mil <miles@userbound.com>
Date:   Thu, 12 Jan 2017 19:55:23 -0600

Add vimclasspath

Diffstat:
Avim/.vim/bundle/vim-classpath/.gitignore | 1+
Avim/.vim/bundle/vim-classpath/README.markdown | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avim/.vim/bundle/vim-classpath/autoload/classpath.vim | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avim/.vim/bundle/vim-classpath/doc/classpath.txt | 19+++++++++++++++++++
Avim/.vim/bundle/vim-classpath/plugin/classpath.vim | 20++++++++++++++++++++
5 files changed, 249 insertions(+), 0 deletions(-)

diff --git a/vim/.vim/bundle/vim-classpath/.gitignore b/vim/.vim/bundle/vim-classpath/.gitignore @@ -0,0 +1 @@ +/doc/tags diff --git a/vim/.vim/bundle/vim-classpath/README.markdown b/vim/.vim/bundle/vim-classpath/README.markdown @@ -0,0 +1,63 @@ +# classpath.vim + +This plugin sets the `'path'` for JVM languages to match the class path of +your current Java project. This lets commands like `:find` and `gf` work as +designed. I originally wrote it for Clojure, but I see no reason why it +wouldn't be handy for other languages as well. + +Currently, [Maven][] and [Leiningen][] are supported, with a fallback to +`$CLASSPATH` if neither applies. [Open an issue][GitHub issues] if you have +ideas for supporting another project management system. + +Included is a `:Java` command, which executes `java` (or `$JAVA_CMD`) with the +current buffer's `'path'` as the class path. + +[Maven]: http://maven.apache.org/ +[Leiningen]: https://github.com/technomancy/leiningen +[GitHub issues]: https://github.com/tpope/vim-classpath/issues + +## Installation + +If you don't have a preferred installation method, I recommend +installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and +then simply copy and paste: + + cd ~/.vim/bundle + git clone git://github.com/tpope/vim-classpath.git + +Once help tags have been generated, you can view the manual with +`:help classpath`. + +## FAQ + +> Why does it take so long for Vim to startup? + +The short answer is because the JVM is slow. + +The first time you load a Clojure file from any given project, classpath.vim +sets about trying to determine your class path, leveraging either +`lein classpath` or `mvn dependency:build-classpath`. This takes a couple of +seconds or so in the best case scenario, and potentially much longer if it +decides to hit the network. + +Because the class path is oh-so-expensive to retrieve, classpath.vim caches it +in `~/.cache/vim/classpath`. The cache is expired when the timestamp on +`project.clj` or `pom.xml` changes. + +## Contributing + +See the contribution guidelines for +[pathogen.vim](https://github.com/tpope/vim-pathogen#readme). + +## Self-Promotion + +Like classpath.vim? Follow the repository on +[GitHub](https://github.com/tpope/vim-classpath). And if +you're feeling especially charitable, follow [tpope](http://tpo.pe/) on +[Twitter](http://twitter.com/tpope) and +[GitHub](https://github.com/tpope). + +## License + +Copyright © Tim Pope. Distributed under the same terms as Vim itself. +See `:help license`. diff --git a/vim/.vim/bundle/vim-classpath/autoload/classpath.vim b/vim/.vim/bundle/vim-classpath/autoload/classpath.vim @@ -0,0 +1,146 @@ +" autoload/classpath.vim +" Maintainer: Tim Pope <http://tpo.pe> + +if exists("g:autoloaded_classpath") + finish +endif +let g:autoloaded_classpath = 1 + +if !exists('g:classpath_cache') + let g:classpath_cache = '~/.cache/vim/classpath' +endif + +if !isdirectory(expand(g:classpath_cache)) + call mkdir(expand(g:classpath_cache), 'p') +endif + +function! classpath#separator() abort + return has('win32') ? ';' : ':' +endfunction + +function! classpath#file_separator() abort + return exists('shellslash') && !&shellslash ? '\' : '/' +endfunction + +function! classpath#split(cp) abort + return split(a:cp, classpath#separator()) +endfunction + +function! classpath#to_vim(cp) abort + let path = [] + for elem in classpath#split(a:cp) + let path += [elem ==# '.' ? '' : elem] + endfor + if a:cp =~# '\(^\|:\)\.$' + let path += [''] + endif + return join(map(path, 'escape(v:val, ", ")'), ',') +endfunction + +function! classpath#from_vim(path) abort + if a:path =~# '^,\=$' + return '.' + endif + let path = [] + for elem in split(substitute(a:path, ',$', '', ''), ',') + if elem ==# '' + let path += ['.'] + else + let path += split(glob(substitute(elem, '\\\ze[\\ ,]', '', 'g'), 1), "\n") + endif + endfor + return join(path, classpath#separator()) +endfunction + +function! classpath#detect(...) abort + let sep = classpath#file_separator() + + let buffer = a:0 ? a:1 : '%' + let default = $CLASSPATH ==# '' ? ',' : classpath#to_vim($CLASSPATH) + let root = getbufvar(buffer, 'java_root') + if root ==# '' + let root = simplify(fnamemodify(bufname(buffer), ':p:s?[\/]$??')) + endif + + if !isdirectory(fnamemodify(root, ':h')) + return default + endif + + let previous = "" + while root !=# previous + if filereadable(root . '/project.clj') && join(readfile(root . '/project.clj', '', 50), "\n") =~# '(\s*defproject' + let file = 'project.clj' + let cmd = 'lein classpath' + let pattern = "[^\n]*\\ze\n*$" + let default = join(map(['test', 'src', 'dev-resources', 'resources', 'target'.sep.'classes'], 'escape(root . sep . v:val, ", ")'), ',') + let base = '' + break + endif + if filereadable(root . '/pom.xml') + let file = 'pom.xml' + let cmd = 'mvn dependency:build-classpath' + let pattern = '\%(^\|classpath:\n\)\zs[^[].\{-\}\ze\n' + let base = '' + for line in filter(readfile(root . '/pom.xml'), 'v:val =~# "<directory>.*</directory>"') + let base .= escape(root.sep.matchstr(line, '<directory>\zs.*\ze</directory>'), ', ').',' + endfor + if empty(base) + let base = escape(root.sep.'src'.sep.'*'.sep.'*', ', ') . ',' + endif + let default = base . default + break + endif + let previous = root + let root = fnamemodify(root, ':h') + endwhile + + if !exists('cmd') || !executable(matchstr(cmd, '^\S\+')) + if a:0 > 1 && a:2 ==# 'keep' + return '' + else + return default + endif + endif + + let cache = expand(g:classpath_cache . '/') . substitute(root, '[:\/]', '%', 'g') + let disk = getftime(root . sep . file) + + if getftime(cache) >= disk + return join(readfile(cache), classpath#separator()) + else + try + if &verbose + echomsg 'Determining class path with '.cmd.' ...' + endif + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' + let dir = getcwd() + try + execute cd . fnameescape(root) + let out = system(cmd) + finally + execute cd . fnameescape(dir) + endtry + catch /^Vim:Interrupt/ + return default + endtry + let match = matchstr(out, pattern) + if !v:shell_error && exists('out') && out !=# '' + let path = base . classpath#to_vim(match) + else + echohl WarningMSG + echomsg "Couldn't determine class path." + echohl NONE + echo out + let path = default + endif + call writefile([path], cache) + return path + endif +endfunction + +function! classpath#java_cmd(...) + let path = classpath#from_vim(a:0 ? a:1 : &path) + return (exists('$JAVA_CMD') ? $JAVA_CMD : 'java') . ' -cp '.shellescape(path) +endfunction + +" vim:set et sw=2: diff --git a/vim/.vim/bundle/vim-classpath/doc/classpath.txt b/vim/.vim/bundle/vim-classpath/doc/classpath.txt @@ -0,0 +1,19 @@ +*classpath.txt* Set 'path' from the Java class path + +Author: Tim Pope <http://tpo.pe/> +Repo: https://github.com/tpope/vim-classpath +License: Same terms as Vim itself (see |license|) + +This plugin is only available if 'compatible' is not set. + +INTRODUCTION *classpath* + +This plugin automatically adjusts 'path' for languages that run on the JVM: +Java, Clojure, Scala, and Groovy. Said path is determined by querying Maven +or Leiningen for the class path. If neither is available, $CLASSPATH is used. + + *classpath-:Java* +:Java [args] Execute $JAVA_CMD (default: java) with a class path + derived from the current buffer's path. + + vim:tw=78:et:ft=help:norl: diff --git a/vim/.vim/bundle/vim-classpath/plugin/classpath.vim b/vim/.vim/bundle/vim-classpath/plugin/classpath.vim @@ -0,0 +1,20 @@ +" classpath.vim - Set 'path' from the Java class path +" Maintainer: Tim Pope <http://tpo.pe/> + +if exists("g:loaded_classpath") || v:version < 700 || &cp + finish +endif +let g:loaded_classpath = 1 + +augroup classpath + autocmd! + autocmd FileType clojure,groovy,java,scala + \ if expand('%:p') =~# '^zipfile:' | + \ let &l:path = getbufvar('#', '&path') | + \ else | + \ let &l:path = classpath#detect() | + \ endif | + \ command! -buffer -nargs=+ -complete=file Java execute '!'.classpath#java_cmd().' '.<q-args> +augroup END + +" vim:set et sw=2: