Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

redesign directory structure.

  • Loading branch information...
commit c50f686b75b92d9bb49215c8955550c7d6ea842d 1 parent fd14f1d
@hrsh7th authored
View
39 autoload/unite/kinds/vcs.vim
@@ -0,0 +1,39 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+" TODO: create vcs kind.
+function! unite#kinds#vcs#define()
+ return unite#kinds#vcs#get_kinds('vcs')
+endfunction
+
+function! unite#kinds#vcs#get_kinds(target)
+ let target = 'autoload/unite/kinds/' . a:target
+ let paths = []
+
+ " target path loop.
+ for path in split(globpath(&runtimepath, target . '/*.vim'))
+ let path = substitute(path, '\/\/', '/', 'g')
+
+ " rtp path loop.
+ for rtp in split(&runtimepath, ',')
+ let rtp = substitute(rtp, '\/\/', '/', 'g') . '/' . target
+
+ if path =~# rtp
+ let l1 = strlen(path)
+ let l2 = strlen(rtp)
+ call add(paths, strpart(path, l2 + 1, l1 - l2 - strlen('.vim') - 1))
+ endif
+ endfor
+ endfor
+
+ " collect kinds.
+ let kinds = []
+ for kind in map(paths, "{'unite#kinds#' . substitute(a:target . '/' . v:val, '/', '#', 'g') . '#define'}()")
+ let kinds += kind
+ endfor
+ return kinds
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
6 autoload/unite/kinds/vcs_file.vim → autoload/unite/kinds/vcs/file.vim
@@ -1,8 +1,8 @@
let s:save_cpo = &cpo
set cpo&vim
-function! unite#kinds#vcs_file#define()
- return s:kind
+function! unite#kinds#vcs#file#define()
+ return [s:kind]
endfunction
let s:kind = {
@@ -13,7 +13,7 @@ let s:kind = {
\ }
let s:kind.action_table.log = {
- \ 'description': 'display candidate log.',
+ \ 'description': 'display vcs log.',
\ 'is_selectable': 1
\ }
function! s:kind.action_table.log.func(candidates)
View
128 autoload/unite/kinds/vcs/log.vim
@@ -0,0 +1,128 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#kinds#vcs#log#define()
+ return [s:kind]
+endfunction
+
+let s:kind = {
+ \ 'name': 'vcs/log',
+ \ 'default_action': 'diff',
+ \ 'action_table': {},
+ \ 'parents': ['vcs/file']
+ \ }
+
+let s:kind.action_table.yank_comment = {
+ \ 'description': 'yank commit message.',
+ \ 'is_selectable': 0,
+ \ }
+function! s:kind.action_table.yank_comment.func(candidates)
+ let candidate = type(a:candidates) == type([]) ? a:candidates[0] : a:candidates
+ let @" = candidate.action__message
+ if has('clipboard')
+ let @* = @"
+ endif
+endfunction
+
+let s:kind.action_table.yank_revision = {
+ \ 'description': 'yank revision.',
+ \ 'is_selectable': 0,
+ \ }
+function! s:kind.action_table.yank_revision.func(candidates)
+ let candidate = type(a:candidates) == type([]) ? a:candidates[0] : a:candidates
+ let @" = candidate.action__revision
+ if has('clipboard')
+ let @* = @"
+ endif
+endfunction
+
+let s:kind.action_table.diff = {
+ \ 'description': 'diff with original.',
+ \ 'is_selectable': 1,
+ \ }
+function! s:kind.action_table.diff.func(candidates)
+ if len(a:candidates) > 2
+ echomsg 'invalid candidates length.'
+ return
+ endif
+
+ " for diff original.
+ let candidate = a:candidates[0]
+ if len(a:candidates) == 1
+ exec 'tabedit ' . candidate.action__path
+ diffthis
+ vnew
+ set bufhidden=delete
+ set nobuflisted
+ set buftype=nofile
+ set noswapfile
+ let lines = split(vcs#vcs('cat', [candidate.action__path, candidate.action__revision]), '\n')
+ call setline(1, lines[0])
+ call append('.', lines[1:-1])
+ exec 'file [' . candidate.action__revision . '] ' . candidate.action__path
+ setlocal nomodifiable
+ diffthis
+ return
+ endif
+
+ tabnew
+ set bufhidden=delete
+ set nobuflisted
+ set buftype=nofile
+ set noswapfile
+ let lines = split(vcs#vcs('cat', [candidate.action__path, candidate.action__revision]), '\n')
+ call setline(1, lines[0])
+ call append('.', lines[1:-1])
+ exec 'file [REMOTE: ' . candidate.action__revision . '] ' . candidate.action__path
+ setlocal nomodifiable
+ diffthis
+
+ let candidate_ = a:candidates[1]
+ vnew
+ set bufhidden=delete
+ set nobuflisted
+ set buftype=nofile
+ set noswapfile
+ let lines = split(vcs#vcs('cat', [candidate_.action__path, candidate_.action__revision]), '\n')
+ call setline(1, lines[0])
+ call append('.', lines[1:-1])
+ exec 'file [REMOTE: ' . candidate_.action__revision . '] ' . candidate_.action__path
+ setlocal nomodifiable
+ diffthis
+endfunction
+
+let s:kind.action_table.diff_prev = {
+ \ 'description': 'diff with previous revision.',
+ \ 'is_selectable': 1,
+ \ }
+function! s:kind.action_table.diff_prev.func(candidates)
+ for candidate in a:candidates
+ tabnew
+ set bufhidden=delete
+ set nobuflisted
+ set buftype=nofile
+ set noswapfile
+ let lines = split(vcs#vcs('cat', [candidate.action__path, candidate.action__revision]), '\n')
+ call setline(1, lines[0])
+ call append('.', lines[1:-1])
+ exec 'file [REMOTE1: ' . candidate.action__revision . '] ' . candidate.action__path
+ setlocal nomodifiable
+ diffthis
+
+ vnew
+ set bufhidden=delete
+ set nobuflisted
+ set buftype=nofile
+ set noswapfile
+ let lines = split(vcs#vcs('cat', [candidate.action__path, candidate.action__prev_revision]), '\n')
+ call setline(1, lines[0])
+ call append('.', lines[1:-1])
+ exec 'file [REMOTE2: ' . candidate.action__prev_revision . '] ' . candidate.action__path
+ setlocal nomodifiable
+ diffthis
+ endfor
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
89 autoload/unite/kinds/vcs/status.vim
@@ -0,0 +1,89 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#kinds#vcs#status#define()
+ return [s:kind] + unite#kinds#vcs#get_kinds('vcs/status')
+endfunction
+
+let s:kind = {
+ \ 'name': 'vcs/status',
+ \ 'default_action': 'open',
+ \ 'action_table': {},
+ \ 'parents': ['vcs/file']
+ \ }
+
+let s:kind.action_table.commit = {
+ \ 'description': 'vcs commit for candidate.',
+ \ 'is_selectable': 1,
+ \ 'is_invalidate_cache': 1,
+ \ 'is_quit': 0,
+ \ }
+function! s:kind.action_table.commit.func(candidates)
+ let candidates = type(a:candidates) == type([]) ? a:candidates : [a:candidates]
+ call vcs#vcs('commit', map(candidates, "v:val.action__path"))
+endfunction
+
+let s:kind.action_table.add = {
+ \ 'description': 'vcs add for candidate.',
+ \ 'is_selectable': 1,
+ \ 'is_invalidate_cache': 1,
+ \ 'is_quit': 0,
+ \ }
+function! s:kind.action_table.add.func(candidates)
+ let candidates = type(a:candidates) == type([]) ? a:candidates : [a:candidates]
+ for message in split(vcs#vcs('add', map(copy(candidates), "v:val.action__path")), '\n')
+ echomsg message
+ endfor
+endfunction
+
+let s:kind.action_table.delete = {
+ \ 'description': 'vcs delete for candidate.',
+ \ 'is_selectable': 1,
+ \ 'is_invalidate_cache': 1,
+ \ 'is_quit': 0,
+ \ }
+function! s:kind.action_table.delete.func(candidates)
+ let candidates = type(a:candidates) == type([]) ? a:candidates : [a:candidates]
+ for message in split(vcs#vcs('delete', map(copy(candidates), "v:val.action__path")), '\n')
+ echomsg message
+ endfor
+endfunction
+
+let s:kind.action_table.revert = {
+ \ 'description': 'vcs revert for candidate.',
+ \ 'is_selectable': 1,
+ \ 'is_invalidate_cache': 1,
+ \ 'is_quit': 0,
+ \ }
+function! s:kind.action_table.revert.func(candidates)
+ let candidates = type(a:candidates) == type([]) ? a:candidates : [a:candidates]
+ for message in split(vcs#vcs('revert', map(copy(candidates), "v:val.action__path")), '\n')
+ echomsg message
+ endfor
+endfunction
+
+let s:kind.action_table.diff = {
+ \ 'description': 'diff with remote.',
+ \ 'is_selectable': 1
+ \ }
+function! s:kind.action_table.diff.func(candidates)
+ for candidate in a:candidates
+ exec 'tabedit ' . candidate.action__path
+ diffthis
+ vnew
+ set bufhidden=delete
+ set nobuflisted
+ set buftype=nofile
+ set noswapfile
+ let lines = split(vcs#vcs('cat', [candidate.action__path]), '\n')
+ call setline(1, lines[0])
+ call append('.', lines[1:-1])
+ exec 'file [REMOTE: HEAD] ' . candidate.action__path
+ setlocal nomodifiable
+ diffthis
+ endfor
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
43 autoload/unite/kinds/vcs/status/svn.vim
@@ -0,0 +1,43 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#kinds#vcs#status#svn#define()
+ return [s:kind]
+endfunction
+
+let s:kind = {
+ \ 'name': 'vcs/status/svn',
+ \ 'default_action': 'open',
+ \ 'action_table': {},
+ \ 'parents': ['vcs/status']
+ \ }
+
+let s:kind.action_table.resolve = {
+ \ 'description': 'vcs resolve for candidate.',
+ \ 'is_selectable': 1,
+ \ 'is_invalidate_cache': 1,
+ \ 'is_quit': 0,
+ \ }
+function! s:kind.action_table.resolve.func(candidates)
+ let candidates = type(a:candidates) == type([]) ? a:candidates : [a:candidates]
+ for message in split(vcs#vcs('resolve', map(copy(candidates), "v:val.action__path")), '\n')
+ echomsg message
+ endfor
+endfunction
+
+let s:kind.action_table.resolved = {
+ \ 'description': 'vcs resolved for candidate.',
+ \ 'is_selectable': 1,
+ \ 'is_invalidate_cache': 1,
+ \ 'is_quit': 0,
+ \ }
+function! s:kind.action_table.resolved.func(candidates)
+ let candidates = type(a:candidates) == type([]) ? a:candidates : [a:candidates]
+ for message in split(vcs#vcs('resolved', map(copy(candidates), "v:val.action__path")), '\n')
+ echomsg message
+ endfor
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
39 autoload/unite/sources/vcs.vim
@@ -0,0 +1,39 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+" TODO: create vcs source.
+function! unite#sources#vcs#define()
+ return unite#sources#vcs#get_sources('vcs')
+endfunction
+
+function! unite#sources#vcs#get_sources(target)
+ let target = 'autoload/unite/sources/' . a:target
+ let paths = []
+
+ " target path loop.
+ for path in split(globpath(&runtimepath, target . '/*.vim'))
+ let path = substitute(path, '\/\/', '/', 'g')
+
+ " rtp path loop.
+ for rtp in split(&runtimepath, ',')
+ let rtp = substitute(rtp, '\/\/', '/', 'g') . '/' . target
+
+ if path =~# rtp
+ let l1 = strlen(path)
+ let l2 = strlen(rtp)
+ call add(paths, strpart(path, l2 + 1, l1 - l2 - strlen('.vim') - 1))
+ endif
+ endfor
+ endfor
+
+ " collect sources.
+ let sources = []
+ for source in map(paths, "{'unite#sources#' . substitute(a:target . '/' . v:val, '/', '#', 'g') . '#define'}()")
+ let sources += source
+ endfor
+ return sources
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
53 autoload/unite/sources/vcs/file_rec.vim
@@ -0,0 +1,53 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#sources#vcs#file_rec#define()
+ return [s:source]
+endfunction
+
+let s:source = {
+ \ 'name': 'vcs/file_rec',
+ \ 'description': 'vcs repository files.'
+ \ }
+
+function! s:source.gather_candidates(args, context)
+ if !a:context.is_redraw
+ let path = vcs#target(a:args)
+ if vcs#detect(path) == ''
+ call unite#print_message('[vcs/file_rec] vcs not detected: ' . path)
+ return []
+ endif
+ let path = len(a:args) > 0 ? path : vcs#vcs('root', [path])
+ let a:context.source__path = path
+ else
+ let path = a:context.source__path
+ endif
+
+ let statuses = vcs#vcs('status', [path])
+ let status_map = {}
+ for status in statuses
+ let status_map[status.path] = status.status
+ endfor
+
+ let statuslen = max(map(statuses, 'strlen(v:val.status)'))
+ return map(unite#get_candidates([['file_rec', path]]), "{
+ \ 'word': s:padding(exists('status_map[v:val.action__path]') ? status_map[v:val.action__path] : '', statuslen) . ' | ' . v:val.word,
+ \ 'action__path': v:val.action__path,
+ \ 'kind': exists('status_map[v:val.action__path]') ? 'vcs/status' : 'vcs/file'
+ \ }")
+endfunction
+
+function! s:padding(str, num)
+ let strlen = strlen(a:str)
+ let num = a:num
+ let pad = ''
+ while num - strlen > 0
+ let pad = pad . ' '
+ let num = num - 1
+ endwhile
+ return a:str . pad
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
56 autoload/unite/sources/vcs/log.vim
@@ -0,0 +1,56 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#sources#vcs#log#define()
+ return [s:source]
+endfunction
+
+let s:source = {
+ \ 'name': 'vcs/log',
+ \ 'description': 'vcs repository or file log.'
+ \ }
+
+function! s:source.gather_candidates(args, context)
+ if !a:context.is_redraw
+ let path = vcs#target(a:args)
+ if vcs#detect(path) == ''
+ call unite#print_message('[vcs/status] vcs not detected: ' . path)
+ return []
+ endif
+ let a:context.source__path = path
+ else
+ let path = a:context.source__path
+ endif
+
+ let root = vcs#vcs('root', [path])
+ call unite#print_message('[vcs/log] root: ' . root)
+ call unite#print_message('[vcs/log] target: ' . path[strlen(root) + 1:-1])
+
+ let logs = vcs#vcs('log', [path])
+ let revisionlen = max(map(copy(logs), "strlen(v:val.revision)"))
+ let authorlen = max(map(copy(logs), "strlen(split(v:val.author, ' ')[0])"))
+ return map(logs, "{
+ \ 'word': s:padding(v:val.revision, revisionlen) . ' | '. s:padding(split(v:val.author, ' ')[0], authorlen) . ' | ' . v:val.message,
+ \ 'action__path': v:val.path,
+ \ 'action__revision': v:val.revision,
+ \ 'action__prev_revision': v:val.prev_revision,
+ \ 'action__author': v:val.author,
+ \ 'action__message': v:val.message,
+ \ 'kind': 'vcs/log'
+ \ }")
+endfunction
+
+function! s:padding(str, num)
+ let strlen = strlen(a:str)
+ let num = a:num
+ let pad = ''
+ while num - strlen > 0
+ let pad = pad . ' '
+ let num = num - 1
+ endwhile
+ return a:str . pad
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
49 autoload/unite/sources/vcs/status.vim
@@ -0,0 +1,49 @@
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! unite#sources#vcs#status#define()
+ return [s:source]
+endfunction
+
+let s:source = {
+ \ 'name': 'vcs/status',
+ \ 'description': 'vcs repository status.'
+ \ }
+
+function! s:source.gather_candidates(args, context)
+ if !a:context.is_redraw
+ let path = vcs#target(a:args)
+ let type = vcs#detect(path)
+ if type == ''
+ call unite#print_message('[vcs/status] vcs not detected: ' . path)
+ return []
+ endif
+ let path = len(a:args) > 0 ? path : vcs#vcs('root', [path])
+ let a:context.source__path = path
+ let a:context.source__type = type
+ else
+ let path = a:context.source__path
+ let type = a:context.source__type
+ endif
+
+ let root = vcs#vcs('root', [path])
+ call unite#print_message('[vcs/status] type: ' . type)
+ call unite#print_message('[vcs/status] root: ' . root)
+ call unite#print_message('[vcs/status] target: ' . path[strlen(root) + 1:-1])
+
+ let kind = 'vcs/status'
+ if len(keys(unite#get_kinds(kind . '/' . type))) > 0
+ let kind = kind . '/' . type
+ endif
+ return map(vcs#vcs('status', [path]), "{
+ \ 'word': v:val.status . ' | '. v:val.path[strlen(vcs#vcs('root', [v:val.path])) + 1:-1],
+ \ 'source__path': path,
+ \ 'action__path': v:val.path,
+ \ 'action__status': v:val.status,
+ \ 'kind': kind
+ \ }")
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
View
14 autoload/vcs/git/status.vim
@@ -33,11 +33,19 @@ endfunction
function! s:parse(target, list)
let root = vcs#vcs('root', [a:target])
- return map(a:list, "{
- \ 'path': root . '/' . v:val[3:-1],
+ return map(a:list, "s:format(root, {
+ \ 'path': v:val[3:-1],
\ 'status': v:val[0:2],
\ 'line': v:val
- \ }")
+ \ })")
+endfunction
+
+function! s:format(root, status)
+ if a:status.status =~# 'R'
+ let a:status.path = substitute(split(a:status.path, '->')[1], '^\s*\|\s*$', '', 'g')
+ endif
+ let a:status.path = a:root . '/' . a:status.path
+ return a:status
endfunction
let &cpo = s:save_cpo
Please sign in to comment.
Something went wrong with that request. Please try again.