Permalink
Browse files

- Added rec action in cdable.

  • Loading branch information...
Shougo committed Oct 31, 2010
1 parent 500c66b commit 4fba98568d61ba246122feb715a3bc54c6b95968
View
@@ -148,14 +148,14 @@ function! unite#set_dictionary_helper(variable, keys, pattern)"{{{
endfor
endfunction"}}}
function! unite#take_action(action_name, candidate)"{{{
let l:candidate = type(a:candidate) == type([]) ?
let l:candidate_head = type(a:candidate) == type([]) ?
\ a:candidate[0] : a:candidate
let l:action_table = unite#get_action_table(l:candidate.source, l:candidate.kind, 0)
let l:action_table = unite#get_action_table(l:candidate_head.source, l:candidate_head.kind, 0)
let l:action_name =
\ a:action_name ==# 'default' ?
\ unite#get_default_action(l:candidate.source, l:candidate.kind)
\ unite#get_default_action(l:candidate_head.source, l:candidate_head.kind)
\ : a:action_name
if !has_key(l:action_table, a:action_name)
@@ -168,15 +168,17 @@ function! unite#take_action(action_name, candidate)"{{{
\ (has_key(l:action, 'is_selectable') && l:action.is_selectable && type(a:candidate) != type([])) ?
\ [a:candidate] : a:candidate)
endfunction"}}}
function! unite#take_parents_action(action_name, candidate)"{{{
let l:candidate = type(a:candidate) == type([]) ?
\ a:candidate[0] : a:candidate
function! unite#take_parents_action(action_name, candidate, extend_candidate)"{{{
let l:candidate = extend(deepcopy(a:candidate), a:extend_candidate)
let l:candidate_head = type(a:candidate) == type([]) ?
\ l:candidate[0] : l:candidate
let l:action_table = unite#get_action_table(l:candidate.source, l:candidate.kind, 0, 1)
let l:action_table = unite#get_action_table(l:candidate_head.source, l:candidate_head.kind, 0, 1)
let l:action_name =
\ a:action_name ==# 'default' ?
\ unite#get_default_action(l:candidate.source, l:candidate.kind)
\ unite#get_default_action(l:candidate_head.source, l:candidate_head.kind)
\ : a:action_name
if !has_key(l:action_table, a:action_name)
@@ -187,7 +189,7 @@ function! unite#take_parents_action(action_name, candidate)"{{{
" Convert candidates.
call l:action.func(
\ (has_key(l:action, 'is_selectable') && l:action.is_selectable && type(a:candidate) != type([])) ?
\ [a:candidate] : a:candidate)
\ [l:candidate] : l:candidate)
endfunction"}}}
function! unite#is_win()"{{{
return has('win16') || has('win32') || has('win64')
@@ -378,6 +380,9 @@ endfunction"}}}
function! unite#substitute_path_separator(path)"{{{
return unite#is_win() ? substitute(a:path, '\\', '/', 'g') : a:path
endfunction"}}}
function! unite#path2directory(path)"{{{
return isdirectory(a:path) ? a:path : unite#substitute_path_separator(fnamemodify(a:path, ':p:h'))
endfunction"}}}
"}}}
" Command functions.
@@ -32,7 +32,7 @@ let s:kind = {
\ 'name' : 'buffer',
\ 'default_action' : 'open',
\ 'action_table': {},
\ 'parents': ['file'],
\ 'parents': ['file', 'cdable'],
\}
" Actions"{{{
@@ -57,72 +57,11 @@ function! s:kind.action_table.fdelete.func(candidates)"{{{
call s:delete('bdelete!', l:candidate)
endfor
endfunction"}}}
let s:kind.action_table.narrow = {
\ 'is_quit' : 0,
\ }
function! s:kind.action_table.narrow.func(candidate)"{{{
let l:word = s:get_directory(a:candidate)
if l:word !~ '[\\/]$'
let l:word .= '/'
endif
call unite#mappings#narrowing(l:word)
endfunction"}}}
let s:kind.action_table.cd = {
\ }
function! s:kind.action_table.cd.func(candidate)"{{{
let l:dir = s:get_directory(a:candidate)
if &filetype ==# 'vimfiler'
call vimfiler#internal_commands#cd(l:dir)
elseif &filetype ==# 'vimshell'
call vimshell#switch_shell(0, l:dir)
endif
execute g:unite_cd_command '`=l:dir`'
endfunction"}}}
let s:kind.action_table.lcd = {
\ }
function! s:kind.action_table.lcd.func(candidate)"{{{
let l:dir = s:get_directory(a:candidate)
if &filetype ==# 'vimfiler'
call vimfiler#internal_commands#cd(l:dir)
elseif &filetype ==# 'vimshell'
call vimshell#switch_shell(0, l:dir)
endif
execute g:unite_lcd_command '`=l:dir`'
endfunction"}}}
if exists(':VimShell')
let s:kind.action_table.vimshell = {
\ }
function! s:kind.action_table.vimshell.func(candidate)"{{{
let l:dir = s:get_directory(a:candidate)
VimShellCreate `=l:dir`
endfunction"}}}
endif
"}}}
" Misc
function! s:delete(delete_command, candidate)"{{{
execute a:candidate.action__buffer_nr a:delete_command
endfunction"}}}
function! s:get_directory(candidate)"{{{
let l:filetype = getbufvar(a:candidate.action__buffer_nr, '&filetype')
if l:filetype ==# 'vimfiler'
let l:dir = getbufvar(a:candidate.action__buffer_nr, 'vimfiler').current_dir
elseif l:filetype ==# 'vimshell'
let l:dir = getbufvar(a:candidate.action__buffer_nr, 'vimshell').save_dir
else
let l:dir = isdirectory(a:candidate.action__path) ? a:candidate.action__path : unite#substitute_path_separator(fnamemodify(a:candidate.action__path, ':p:h'))
endif
return l:dir
endfunction"}}}
" vim: foldmethod=marker
@@ -35,6 +35,30 @@ let s:kind = {
\}
" Actions"{{{
let s:kind.action_table.cd = {
\ }
function! s:kind.action_table.cd.func(candidate)"{{{
if &filetype ==# 'vimfiler'
call vimfiler#internal_commands#cd(a:candidate.action__directory)
elseif &filetype ==# 'vimshell'
call vimshell#switch_shell(0, a:candidate.action__directory)
endif
execute g:unite_cd_command '`=a:candidate.action__directory`'
endfunction"}}}
let s:kind.action_table.lcd = {
\ }
function! s:kind.action_table.lcd.func(candidate)"{{{
if &filetype ==# 'vimfiler'
call vimfiler#internal_commands#cd(a:candidate.action__directory)
elseif &filetype ==# 'vimshell'
call vimshell#switch_shell(0, a:candidate.action__directory)
endif
execute g:unite_lcd_command '`=a:candidate.action__directory`'
endfunction"}}}
let s:kind.action_table.narrow = {
\ 'is_quit' : 0,
\ }
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: directory.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 30 Oct 2010
" Last Modified: 31 Oct 2010
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
@@ -36,30 +36,6 @@ let s:kind = {
\}
" Actions"{{{
let s:kind.action_table.narrow = {
\ 'is_quit' : 0,
\ }
function! s:kind.action_table.narrow.func(candidate)"{{{
let l:word = a:candidate.action__path . (a:candidate.action__path =~ '[\\/]$' ? '' : '/')
call unite#mappings#narrowing(l:word)
endfunction"}}}
if exists(':VimShell')
let s:kind.action_table.vimshell = {
\ }
function! s:kind.action_table.vimshell.func(candidate)"{{{
let l:dir = isdirectory(a:candidate.action__path) ? a:candidate.action__path : fnamemodify(a:candidate.action__path, ':p:h')
VimShellCreate `=l:dir`
endfunction"}}}
endif
if exists(':VimShellTab')
let s:kind.action_table.tabvimshell = {
\ }
function! s:kind.action_table.tabvimshell.func(candidate)"{{{
let l:dir = isdirectory(a:candidate.action__path) ? a:candidate.action__path : fnamemodify(a:candidate.action__path, ':p:h')
VimShellTab `=l:dir`
endfunction"}}}
endif
"}}}
" vim: foldmethod=marker
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: file.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 30 Oct 2010
" Last Modified: 31 Oct 2010
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
@@ -32,7 +32,7 @@ let s:kind = {
\ 'name' : 'file',
\ 'default_action' : 'open',
\ 'action_table': {},
\ 'parents': ['openable'],
\ 'parents': ['openable', 'cdable'],
\}
" Actions"{{{
@@ -60,46 +60,6 @@ let s:kind.action_table.preview = {
function! s:kind.action_table.preview.func(candidate)"{{{
pedit `=a:candidate.action__path`
endfunction"}}}
let s:kind.action_table.cd = {
\ }
function! s:kind.action_table.cd.func(candidate)"{{{
let l:dir = isdirectory(a:candidate.action__path) ? a:candidate.action__path : fnamemodify(a:candidate.action__path, ':p:h')
if &filetype ==# 'vimfiler'
call vimfiler#internal_commands#cd(l:dir)
elseif &filetype ==# 'vimshell'
call vimshell#switch_shell(0, l:dir)
endif
execute g:unite_cd_command '`=l:dir`'
endfunction"}}}
let s:kind.action_table.lcd = {
\ }
function! s:kind.action_table.lcd.func(candidate)"{{{
let l:dir = isdirectory(a:candidate.action__path) ? a:candidate.action__path : fnamemodify(a:candidate.action__path, ':p:h')
if &filetype ==# 'vimfiler'
call vimfiler#internal_commands#cd(l:dir)
elseif &filetype ==# 'vimshell'
call vimshell#switch_shell(0, l:dir)
endif
execute g:unite_lcd_command '`=l:dir`'
endfunction"}}}
let s:kind.action_table.narrow = {
\ 'is_quit' : 0,
\ }
function! s:kind.action_table.narrow.func(candidate)"{{{
let l:word = fnamemodify(a:candidate.action__path, ':h')
if l:word !~ '[\\/]$'
let l:word .= '/'
endif
call unite#mappings#narrowing(l:word)
endfunction"}}}
"}}}
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: bookmark.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 30 Oct 2010
" Last Modified: 31 Oct 2010
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
@@ -91,8 +91,10 @@ function! s:source.gather_candidates(args, context)"{{{
\ "source" : "bookmark",
\ "kind" : (isdirectory(v:val[1]) ? "directory" : "jump_list"),
\ "bookmark_name" : v:val[0],
\ "line" : v:val[2],
\ "pattern" : v:val[3],
\ "action__path" : v:val[1],
\ "action__line" : v:val[2],
\ "action__pattern" : v:val[3],
\ "action__directory" : unite#path2directory(v:val[1]),
\ }')
endfunction"}}}
@@ -115,6 +117,7 @@ endfunction"}}}
let s:source.action_table.jump_list = s:action_table
let s:source.action_table.directory = s:action_table
unlet! s:action_table
"}}}
" Add custom action table."{{{
@@ -143,6 +146,8 @@ endfunction"}}}
call unite#custom_action('file', 'bookmark', s:file_bookmark_action)
call unite#custom_action('buffer', 'bookmark', s:buffer_bookmark_action)
unlet! s:file_bookmark_action
unlet! s:buffer_bookmark_action
"}}}
" Misc
@@ -76,6 +76,7 @@ function! s:source_buffer_all.gather_candidates(args, context)"{{{
\ "source" : "buffer",
\ "action__path" : unite#substitute_path_separator(bufname(v:val.action__buffer_nr)),
\ "action__buffer_nr" : v:val.action__buffer_nr,
\ "action__directory" : s:get_directory(v:val.action__buffer_nr),
\}')
return l:candidates
@@ -102,6 +103,7 @@ function! s:source_buffer_tab.gather_candidates(args, context)"{{{
\ "source" : "buffer_tab",
\ "action__path" : unite#substitute_path_separator(bufname(v:val.action__buffer_nr)),
\ "action__buffer_nr" : v:val.action__buffer_nr,
\ "action__directory" : s:get_directory(v:val.action__buffer_nr),
\}')
return l:candidates
@@ -123,5 +125,18 @@ endfunction"}}}
function! s:compare(candidate_a, candidate_b)"{{{
return a:candidate_b.source__time - a:candidate_a.source__time
endfunction"}}}
function! s:get_directory(bufnr)"{{{
let l:filetype = getbufvar(a:bufnr, '&filetype')
if l:filetype ==# 'vimfiler'
let l:dir = getbufvar(a:bufnr, 'vimfiler').current_dir
elseif l:filetype ==# 'vimshell'
let l:dir = getbufvar(a:bufnr, 'vimshell').save_dir
else
let l:path = unite#substitute_path_separator(bufname(a:bufnr))
let l:dir = unite#path2directory(l:path)
endif
return l:dir
endfunction"}}}
" vim: foldmethod=marker
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: file.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 30 Oct 2010
" Last Modified: 31 Oct 2010
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
@@ -69,7 +69,10 @@ function! s:source.gather_candidates(args, context)"{{{
let l:candidates_dir = []
let l:candidates_file = []
for l:file in l:candidates
let l:dict = { 'word' : l:file, 'abbr' : l:file, 'source' : 'file', 'action__path' : l:file, }
let l:dict = {
\ 'word' : l:file, 'abbr' : l:file, 'source' : 'file', 'action__path' : l:file,
\ 'action__directory' : unite#path2directory(l:file),
\}
if isdirectory(l:file)
if l:file !~ '^\%(/\|\a\+:/\)$'
@@ -1,7 +1,7 @@
"=============================================================================
" FILE: file_mru.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 30 Oct 2010
" Last Modified: 31 Oct 2010
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
@@ -140,6 +140,7 @@ function! s:convert2dictionary(list) "{{{
\ 'kind' : (isdirectory(a:list[0]) ? 'directory' : 'file'),
\ 'source__time' : a:list[1],
\ 'action__path' : unite#substitute_path_separator(a:list[0]),
\ 'action__directory' : unite#path2directory(unite#substitute_path_separator(a:list[0])),
\ }
endfunction"}}}
function! s:convert2list(dict) "{{{
Oops, something went wrong.

0 comments on commit 4fba985

Please sign in to comment.