Skip to content

Commit

Permalink
Merge branch 'ctrlspace'
Browse files Browse the repository at this point in the history
Conflicts:
	.vimrc.global
	after/plugin/lighthouse.vim
  • Loading branch information
DXist committed Nov 9, 2014
2 parents 552c434 + f135bef commit ad7cfbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 169 deletions.
58 changes: 21 additions & 37 deletions .vimrc.global
Expand Up @@ -78,12 +78,14 @@ if !exists('s:loaded_my_vimrc')
NeoBundleLazy 'othree/html5.vim', {
\ 'autoload': {'filetypes': ['html', 'xhtml', 'css']}}

NeoBundleLazy "wavded/vim-stylus", {
NeoBundleLazy 'wavded/vim-stylus', {
\ 'autoload': {'filetypes': ['styl']}}

NeoBundleLazy "fatih/vim-go", {
NeoBundleLazy 'fatih/vim-go', {
\ 'autoload': {'filetypes': ['go']}}

" NeoBundle 'szw/vim-ctrlspace'

call neobundle#end()

" Required:
Expand Down Expand Up @@ -375,8 +377,6 @@ map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h

" Switch to alternate buffer
nmap <space> <c-^>
set switchbuf=usetab
"}}}

Expand Down Expand Up @@ -419,19 +419,15 @@ endif

nnoremap [unite] <Nop>
nmap <leader>t [unite]
nnoremap <silent> <leader>d :<C-u>Unite
\ -buffer-name=codesearch codesearch<CR>

nnoremap <silent> <leader>f :<C-u>Unite
\ -buffer-name=files buffer file_rec/async file/new<CR>
nnoremap <silent> <leader>d :<C-u>Unite codesearch<CR>
nnoremap <silent> <leader>f :<C-u>Unite buffer file_rec/async file/new<CR>
nnoremap <silent> <leader>r :<C-u>Unite tag<CR>
" nnoremap <silent> <leader>f :<C-u>CtrlSpace O<CR>

nnoremap <silent> <leader>a :<C-u>Unite
\ -buffer-name=grep grep:.<CR>
nnoremap <silent> <leader>a :<C-u>Unite grep:.<CR>

nnoremap <silent> [unite]b :<C-u>Unite
\ -buffer-name=bookmarks bookmark:default<CR>
nnoremap <silent> [unite]r :<C-u>Unite
\ -buffer-name=register register<CR>
nnoremap <silent> [unite]b :<C-u>Unite bookmark:default<CR>
nnoremap <silent> [unite]r :<C-u>Unite register<CR>
nnoremap <silent> [unite]o :<C-u>Unite outline<CR>
nnoremap <silent> [unite]ma
\ :<C-u>Unite mapping<CR>
Expand All @@ -447,10 +443,13 @@ function! s:unite_my_settings()
" Overwrite settings.

imap <buffer> <C-w> <Plug>(unite_delete_backward_path)
imap <silent><buffer><expr> <C-x> unite#do_action('split')
imap <silent><buffer><expr> <C-v> unite#do_action('vsplit')
imap <silent><buffer><expr> <C-t> unite#do_action('tabopen')
imap <silent><buffer><expr> <C-s> unite#do_action('split')
imap <silent><buffer><expr> <C-s> unite#do_action('split')
imap <silent><buffer> <tab> <c-x><c-f>
iunmap <silent><buffer> <c-n>
iunmap <silent><buffer> <c-p>

imap <buffer> <C-w> <Plug>(unite_delete_backward_path)
nmap <buffer> x <Plug>(unite_quick_match_choose_action)
Expand All @@ -471,6 +470,7 @@ endfunction
call unite#custom#profile('default', 'context', {
\ 'prompt': '» ',
\ 'start_insert': 1,
\ 'update_time': 200,
\ 'direction': 'botright',
\ })

Expand All @@ -479,29 +479,13 @@ call unite#custom#source('file_rec/async','sorters','sorter_selecta')
call unite#custom#source('file,file/new,file_rec,file_rec/async',
\ 'matchers', ['matcher_hide_hidden_files', 'converter_relative_word', 'matcher_fuzzy'])

call unite#filters#matcher_default#use(['matcher_fuzzy'])
" call unite#custom#source('buffer,file,file_rec',
" \ 'sorters', 'sorter_rank')
call unite#filters#sorter_default#use(['sorter_rank'])
let project_open = {}
function! project_open.func(candidate)
call unite#take_action('open', a:candidate)

let directory = unite#helper#get_candidate_directory(a:candidate)
if !isdirectory(directory)
echo directory . 'is not a directory'
return
endif

let directory = unite#util#path2project_directory(directory)

if isdirectory(directory)
execute g:unite_kind_cdable_lcd_command fnameescape(directory)
endif
endfunction

call unite#custom#action('file,file/async,file_rec/file_rec/async', 'projectopen', project_open)
unlet project_open
" ctrlspace
let g:ctrlspace_load_last_workspace_on_start = 1
let g:ctrlspace_save_workspace_on_exit = 1
let g:ctrlspace_save_workspace_on_switch = 1
" nmap <space> :<c-u>CtrlSpace<CR>

" vim-surround {{{
let g:surround_{char2nr("b")} = "{% block\1 \r..*\r &\1 %}\r{% endblock %}"
Expand Down
138 changes: 6 additions & 132 deletions after/plugin/lighthouse.vim
Expand Up @@ -22,69 +22,25 @@ function! lighthouse#statusline()
return ''
endfunction

function! lighthouse#tablabel(n)
let label = ''
let buflist = tabpagebuflist(a:n)

" Имя файла и номер вкладки -->
if !empty(gettabvar(a:n, "current_project"))
let label = gettabvar(a:n, "current_project")
else
let label = substitute(bufname(buflist[tabpagewinnr(a:n) - 1]), '.*/', '', '')
endif

if label == ''
let label = '[No Name]'
endif

let label .= ' ' . a:n
" Имя файла и номер вкладки <--

" Определяем, есть ли во вкладке хотя бы один
" модифицированный буфер.
" -->
for i in range(len(buflist))
if getbufvar(buflist[i], "&modified")
let label = '[+] ' . label
break
endif
endfor
" <--

return label
endfunction

function! lighthouse#filesearch(...)
if exists("a:1")
let l:path = s:ProjectPath(a:1)
call s:SwitchToProjectTab(a:1)
call s:SetCurrentProject(a:1)
else
let l:path = s:ProjectPath()
endif
exec ":" . "Unite -buffer-name=files buffer file_rec/async:" . l:path . " file/new"
exec ":" . "Unite buffer file_rec/async:" . l:path . " file/new"
endfunction

function! lighthouse#ack_grep(...)
function! lighthouse#grep(...)
if exists("a:1")
let l:path = s:ProjectPath(a:1)
call s:SwitchToProjectTab(a:1)
call s:SetCurrentProject(a:1)
else
let l:path = s:ProjectPath()
endif
let l:pattern = input("Ack: ")
if !empty(l:pattern)
let l:cmd = ":Ack! " . l:pattern
if empty(l:path)
let l:cmd = l:cmd . " " . l:path
endif
exec l:cmd
else
echo
endif
endfunction

function! lighthouse#getdjangoapp()
return expand('%:p:h:t')
exec ":" . "Unite grep:" . l:path
endfunction

function! lighthouse#closeproject(name)
Expand Down Expand Up @@ -113,16 +69,10 @@ endfunction
function! s:SetCurrentProject(project)
if !empty(a:project)
let b:current_project = a:project
if !exists("t:current_project")
let t:current_project = a:project
endif
else
if exists("b:current_project")
unlet b:current_project
endif
if exists("t:current_project")
unlet t:current_project
endif
endif
endfunction

Expand Down Expand Up @@ -201,81 +151,9 @@ function! s:ProjectPath(...)
return ''
endfunction

" get tab number by project name
function! s:ProjectTabNr(project)
let l:ntabs = tabpagenr('$')
for n in range(1, l:ntabs)
if gettabvar(n, "current_project") == a:project
return n
endif
endfor
return 0
endfunction

function! s:SwitchToProjectTab(project)
let l:n = s:ProjectTabNr(a:project)
if l:n
exec ":tabn " . l:n
else
if exists("t:current_project")
:tabnew
call s:SetCurrentProject(a:project)
endif
endif
endfunction

function! s:BufferToProjectTab()
let l:current_project = getbufvar(bufname('%'), "current_project")
if !empty(l:current_project)
call s:SwitchToProjectTab(l:current_project)
endif
endfunction

function! s:ArrangeByProjects()
:bufdo call s:BufferToProjectTab()
endfunction

" Задаем собственные функции для назначения имен заголовкам табов -->
function lighthouse#tabline()
let tabline = ''

" Формируем tabline для каждой вкладки -->
for i in range(tabpagenr('$'))
" Подсвечиваем заголовок выбранной в данный момент вкладки.
if i + 1 == tabpagenr()
let tabline .= '%#TabLineSel#'
else
let tabline .= '%#TabLine#'
endif

" Устанавливаем номер вкладки
let tabline .= '%' . (i + 1) . 'T'

" Получаем имя вкладки
let tabline .= ' %{lighthouse#tablabel(' . (i + 1) . ')} |'
endfor
" Формируем tabline для каждой вкладки <--

" Заполняем лишнее пространство
let tabline .= '%#TabLineFill#%T'

" Выровненная по правому краю кнопка закрытия вкладки
if tabpagenr('$') > 1
let tabline .= '%=%#TabLine#%999XX'
endif

return tabline
endfunction

function lighthouse#guitablabel()
return '%{lighthouse#tablabel(' . tabpagenr() . ')}'
endfunction

" set tabline=%!lighthouse#tabline()
" set guitablabel=%!lighthouse#guitablabel()

command! -nargs=? -complete=customlist,s:Completion LightHouseSearch :call lighthouse#filesearch('<args>')
command! -nargs=? -complete=customlist,s:Completion LightHouseGrep :call lighthouse#ack_grep('<args>')
command! -nargs=? -complete=customlist,s:Completion LightHouseGrep :call lighthouse#grep('<args>')
command! -nargs=? -complete=customlist,s:Completion LightHouseClose :call lighthouse#closeproject('<args>')
command! LightHouseArrange :call s:ArrangeByProjects()

Expand All @@ -291,7 +169,3 @@ endif
if !hasmapto(':LightHouseClose<SPACE>')
silent! nmap <unique> <Leader>lc :LightHouseClose<SPACE>
endif

if !hasmapto(':LightHouseArrange')
silent! nmap <unique> <Leader>la :LightHouseArrange<CR>
endif

0 comments on commit ad7cfbc

Please sign in to comment.