diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..2f726938 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Version(s) (please complete the following information):** + - OS: [e.g. linux, win95, osx mojave] + - Version [e.g. vim 8.1.1172 *or* nvim v0.3.4 *or* macvim *or* gvim *or* ....] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..127a2152 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. + +**Version(s) (please complete the following information):** + - OS: [e.g. linux, win95, osx mojave] + - Version [e.g. vim 8.1.1172 *or* nvim v0.3.4 *or* macvim *or* gvim *or* ....] diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..b0804697 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,45 @@ +# Current version changes can be found in the + +# Version 5 + +Vim-CtrlSpace started over 6 years ago as a fork of [another +plugin](https://github.com/roblillack/vim-bufferlist) and the Version +**5** is the result of the experience gained during that period and +cooperation with the community. + +Version 5 is the biggest upgrade in the plugin history. All plugin code +has been rewritten from scratch taking user feedback as a great resource +of ideas and challenges into account. Thanks to users the plugin has +configurable key mappings and allows you to handle projects with **100 +000** files! + +In case you're curious, Vim-CtrlSpace 5 took *@szw* 5 months of spare evenings +to complete :). + +The most exciting **Vim-CtrlSpace 5** features are: + + * better, modular, and extensible code base + * simplified, well thought-out, and clear design + * new fuzzy search engine for files (written in Go) + * more effective and responsive behavior + * fine-grained configuration + +Version 5 is not backward compatible. All configuration variables and API +functions have been renamed. Please check Vim help for more info: +```VimL +:help ctrlspace-configuration +``` +--- + +If you like the plugin please don't forget to leave a :star: for this +project! This will help me to estimate the plugin popularity and plan +further development :). + +If you have already starred this repo, thank you! Thanks to you it's my +pet project now :). If you have a question, a feature request, or a new +idea, don't hesitate to post new issues or pull requests. Collaboration is +the most awesome thing in the open source community! + +--- + +Copyright (c) 2013-2020 Szymon Wrozynski and Contributors diff --git a/README.md b/README.md index f8b57d0b..3eedf071 100644 --- a/README.md +++ b/README.md @@ -1,177 +1,251 @@ +
+
+
-
-
to close") - call add(s:textBuffer, "") + call add(s:textBuffer, header . " - pressto close") + call add(s:textBuffer, "") - for info in b:helpKeyDescriptions - call add(s:textBuffer, info.key . " | " . info.description) - endfor + for info in b:helpKeyDescriptions + call add(s:textBuffer, info.key . " | " . info.description) + endfor - call ctrlspace#window#Kill(0, 1) - call ctrlspace#help#CloseExternalWindow() + call ctrlspace#window#Kill(0, 1) + call ctrlspace#help#CloseExternalWindow() - if winnr("$") > 1 - new - wincmd K - wincmd _ - else - enew - endif + if winnr("$") > 1 + new + wincmd K + wincmd _ + else + enew + endif - let s:externalBufnr = bufnr("%") + let s:externalBufnr = bufnr("%") - silent! exe "file " . fname + silent! exe "file " . fname - setlocal noswapfile - setlocal buftype=nofile - setlocal bufhidden=hide - setlocal buflisted - setlocal filetype=ctrlspace_help + setlocal noswapfile + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal buflisted + setlocal filetype=ctrlspace_help - setlocal modifiable + setlocal modifiable - silent! put! =s:flushTextBuffer() - normal! GkJ - normal! 0 - normal! gg + silent! put! =s:flushTextBuffer() + normal! GkJ + normal! 0 + normal! gg - noremapq :call ctrlspace#help#CloseExternalWindow() + noremap q :call ctrlspace#help#CloseExternalWindow() - setlocal nomodifiable + setlocal nomodifiable endfunction -function! ctrlspace#help#DisplayHelp(fill) - if s:modes.Nop.Enabled - let mapName = "Nop" - elseif s:modes.Search.Enabled - let mapName = "Search" - else - let mapName = ctrlspace#modes#CurrentListView().Name - endif +function! ctrlspace#help#DisplayHelp(fill) abort + if s:modes.Nop.Enabled + let mapName = "Nop" + elseif s:modes.Search.Enabled + let mapName = "Search" + else + let mapName = ctrlspace#modes#CurrentListView().Name + endif - call s:collectKeysInfo(mapName) + call s:collectKeysInfo(mapName) - let mi = s:modeInfo() - let header = "Key Reference for " . mi[0] . " LIST" + let mi = s:modeInfo() + let header = "Key Reference for " . mi[0] . " LIST" - if len(mi) > 1 - let header .= " (" . join(mi[1:], ", ") . ")" - endif + if len(mi) > 1 + let header .= " (" . join(mi[1:], ", ") . ")" + endif - call s:puts(s:config.Symbols.CS . " CtrlSpace 5.0.7 (engine: " . s:config.FileEngineName . ")") - call s:puts(header . " - press to expand") - call s:puts("") + call s:puts(s:config.Symbols.CS . " CtrlSpace 5.0.7 (engine: " . s:config.FileEngineName . ")") + call s:puts(header . " - press to expand") + call s:puts("") - for info in b:helpKeyDescriptions - call s:puts(info.key . " | " . info.description) - endfor + for info in b:helpKeyDescriptions + call s:puts(info.key . " | " . info.description) + endfor - call s:puts("") - call s:puts("Copyright (c) 2013-2015 Szymon Wrozynski and Contributors") + call s:puts("") + call s:puts("Copyright (c) 2013-2020 Szymon Wrozynski and Contributors") - setlocal modifiable + setlocal modifiable - let b:size = len(s:textBuffer) + let b:size = len(s:textBuffer) - if b:size > s:config.Height - let maxHeight = ctrlspace#window#MaxHeight() + if b:size > s:config.Height + let maxHeight = ctrlspace#window#MaxHeight() - if b:size < maxHeight - silent! exe "resize " . b:size - else - silent! exe "resize " . maxHeight - endif - endif + if b:size < maxHeight + silent! exe "resize " . b:size + else + silent! exe "resize " . maxHeight + endif + endif - silent! put! =s:flushTextBuffer() - normal! GkJ + silent! put! =s:flushTextBuffer() + normal! GkJ - while winheight(0) > line(".") - silent! put =a:fill - endwhile + while winheight(0) > line(".") + silent! put =a:fill + endwhile - normal! 0 - normal! gg + normal! 0 + normal! gg - setlocal nomodifiable + setlocal nomodifiable endfunction -function! s:puts(str) - let str = " " . a:str +function! s:puts(str) abort + let str = " " . a:str - if &columns < (strwidth(str) + 2) - let str = strpart(str, 0, &columns - 2 - s:sizes.Dots) . s:config.Symbols.Dots - endif + if &columns < (strwidth(str) + 2) + let str = strpart(str, 0, &columns - 2 - s:sizes.Dots) . s:config.Symbols.Dots + endif - while strwidth(str) < &columns - let str .= " " - endwhile + while strwidth(str) < &columns + let str .= " " + endwhile - call add(s:textBuffer, str) + call add(s:textBuffer, str) endfunction -function! s:flushTextBuffer() - let text = join(s:textBuffer, "\n") - let s:textBuffer = [] - return text +function! s:flushTextBuffer() abort + let text = join(s:textBuffer, "\n") + let s:textBuffer = [] + return text endfunction -function! s:keyHelp(key, description) - if !exists("b:helpKeyDescriptions") - let b:helpKeyDescriptions = [] - let b:helpKeyWidth = 0 - endif - - call add(b:helpKeyDescriptions, { "key": a:key, "description": a:description }) - - if strwidth(a:key) > b:helpKeyWidth - let b:helpKeyWidth = strwidth(a:key) - else - for keyInfo in b:helpKeyDescriptions - while strwidth(keyInfo.key) < b:helpKeyWidth - let keyInfo.key .= " " - endwhile - endfor - endif +function! s:keyHelp(key, description) abort + if !exists("b:helpKeyDescriptions") + let b:helpKeyDescriptions = [] + let b:helpKeyWidth = 0 + endif + + call add(b:helpKeyDescriptions, { "key": a:key, "description": a:description }) + + if strwidth(a:key) > b:helpKeyWidth + let b:helpKeyWidth = strwidth(a:key) + else + for keyInfo in b:helpKeyDescriptions + while strwidth(keyInfo.key) < b:helpKeyWidth + let keyInfo.key .= " " + endwhile + endfor + endif endfunction -function! s:collectKeysInfo(mapName) - for key in sort(keys(s:helpMap[a:mapName])) - let fn = s:helpMap[a:mapName][key] +function! s:sortKeyHelp(key1, key2) dict + let l:desc1 = get(s:descriptions, self[a:key1], "") + let l:desc2 = get(s:descriptions, self[a:key2], "") + return l:desc1 == l:desc2 ? 0 : l:desc1 > l:desc2 ? 1 : -1 +endfunction - if has_key(s:descriptions, fn) && !empty(s:descriptions[fn]) - call s:keyHelp(key, s:descriptions[fn]) - endif - endfor +function! s:collectKeysInfo(mapName) abort + let l:keys = keys(s:helpMap[a:mapName]) + if s:config.SortHelp + let l:keys = sort(l:keys, "s:sortKeyHelp", s:helpMap[a:mapName]) + endif + for key in l:keys + let FnKey = s:helpMap[a:mapName][key] + + " Due to the way 'ctrlspace#keys#nop#_ExecDbmdexAction' is called (as + " a Partial, in order to capture runtime info), it is keyed as a + " Funcref, instead of a string like other functions, in s:helpMap + " TODO: please improve if better implementation allowing use of string key is known + if type(FnKey) == v:t_func && get(FnKey, 'name') == "ctrlspace#keys#nop#_ExecDbmdexAction" + let [md, fn] = get(FnKey, 'args') + let fn = s:modes[md].Enabled ? fn : '' " only generate help if the appropriate mode is enabled + elseif type(FnKey) == v:t_string + let fn = FnKey + endif + + if has_key(s:descriptions, fn) && !empty(s:descriptions[fn]) + call s:keyHelp(key, s:descriptions[fn]) + endif + endfor endfunction -function! s:modeInfo() - let info = [] - let clv = ctrlspace#modes#CurrentListView() - - if clv.Name ==# "Workspace" - call add(info, "WORKSPACE") - if clv.Data.SubMode ==# "load" - call add(info, "LOAD") - elseif clv.Data.SubMode ==# "save" - call add(info, "SAVE") - endif - elseif clv.Name ==# "Tab" - call add(info, "TAB") - elseif clv.Name ==# "Bookmark" - call add(info, "BOOKMARK") - else - if clv.Name ==# "File" - call add(info, "FILE") - elseif clv.Name ==# "Buffer" - call add(info, "BUFFER") - if clv.Data.SubMode ==# "visible" - call add(info, "VISIBLE") - elseif clv.Data.SubMode ==# "single" - call add(info, "SINGLE") - elseif clv.Data.SubMode ==# "all" - call add(info, "ALL") - endif - endif - - if s:modes.NextTab.Enabled - call add(info, "NEXT TAB") - endif - endif - - if s:modes.Search.Enabled - call add(info, "SEARCH") - endif - - if s:modes.Zoom.Enabled - call add(info, "ZOOM") - endif - - if s:modes.Nop.Enabled - call add(info, "NOP") - endif - - return info +function! s:modeInfo() abort + let info = [] + let clv = ctrlspace#modes#CurrentListView() + + if clv.Name ==# "Workspace" + call add(info, "WORKSPACE") + if clv.Data.SubMode ==# "load" + call add(info, "LOAD") + elseif clv.Data.SubMode ==# "save" + call add(info, "SAVE") + endif + elseif clv.Name ==# "Tab" + call add(info, "TAB") + elseif clv.Name ==# "Bookmark" + call add(info, "BOOKMARK") + else + if clv.Name ==# "File" + call add(info, "FILE") + elseif clv.Name ==# "Buffer" + call add(info, "BUFFER") + if clv.Data.SubMode ==# "visible" + call add(info, "VISIBLE") + elseif clv.Data.SubMode ==# "single" + call add(info, "SINGLE") + elseif clv.Data.SubMode ==# "all" + call add(info, "ALL") + endif + endif + + if s:modes.NextTab.Enabled + call add(info, "NEXT TAB") + endif + endif + + if s:modes.Search.Enabled + call add(info, "SEARCH") + endif + + if s:modes.Zoom.Enabled + call add(info, "ZOOM") + endif + + if s:modes.Nop.Enabled + call add(info, "NOP") + endif + + return info endfunction diff --git a/autoload/ctrlspace/init.vim b/autoload/ctrlspace/init.vim index b1bb8397..f41dcce9 100644 --- a/autoload/ctrlspace/init.vim +++ b/autoload/ctrlspace/init.vim @@ -1,79 +1,100 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#init#Init() - if s:config.UseTabline - set tabline=%!ctrlspace#api#Tabline() - - if has("gui_running") && (&go =~# "e") - set guitablabel=%{ctrlspace#api#Guitablabel()} - - " Fix MacVim issues: - " http://stackoverflow.com/questions/11595301/controlling-tab-names-in-vim - au BufEnter * set guitablabel=%{ctrlspace#api#Guitablabel()} - endif - endif - - command! -nargs=* -range CtrlSpace :call ctrlspace#window#Toggle(0) | :call feedkeys( ) - command! -nargs=0 -range CtrlSpaceGoUp :call ctrlspace#window#GoToBufferListPosition("up") - command! -nargs=0 -range CtrlSpaceGoDown :call ctrlspace#window#GoToBufferListPosition("down") - command! -nargs=0 -range CtrlSpaceTabLabel :call ctrlspace#tabs#NewTabLabel(0) - command! -nargs=0 -range CtrlSpaceClearTabLabel :call ctrlspace#tabs#RemoveTabLabel(0) - command! -nargs=* -range CtrlSpaceSaveWorkspace :call ctrlspace#workspaces#SaveWorkspace( ) - command! -nargs=0 -range CtrlSpaceNewWorkspace :call ctrlspace#workspaces#NewWorkspace() - command! -nargs=* -range -bang CtrlSpaceLoadWorkspace :call ctrlspace#workspaces#LoadWorkspace( 0, ) - command! -nargs=* -range -complete=dir CtrlSpaceAddProjectRoot :call ctrlspace#roots#AddProjectRoot( ) - command! -nargs=* -range -complete=dir CtrlSpaceRemoveProjectRoot :call ctrlspace#roots#RemoveProjectRoot( ) - - hi def link CtrlSpaceNormal PMenu - hi def link CtrlSpaceSelected PMenuSel - hi def link CtrlSpaceSearch Search - hi def link CtrlSpaceStatus StatusLine - - if s:config.SetDefaultMapping - call ctrlspace#keys#SetDefaultMapping(s:config.DefaultMappingKey, ":CtrlSpace ") - endif - - call s:initProjectRootsAndBookmarks() - call ctrlspace#keys#Init() - - au BufEnter * call ctrlspace#buffers#AddBuffer() - au VimEnter * call ctrlspace#buffers#Init() - au TabEnter * let t:CtrlSpaceTabJumpCounter = ctrlspace#jumps#IncrementJumpCounter() - - if s:config.SaveWorkspaceOnExit - au VimLeavePre * if ctrlspace#workspaces#ActiveWorkspace().Status | call ctrlspace#workspaces#SaveWorkspace("") | endif - endif - - if s:config.LoadLastWorkspaceOnStart - au VimEnter * nested if (argc() == 0) && !empty(ctrlspace#roots#FindProjectRoot()) | call ctrlspace#workspaces#LoadWorkspace(0, "") | endif - endif +function! ctrlspace#init#Init() abort + augroup CtrlSpaceInit + autocmd! + augroup END + + if s:config.UseTabline + set tabline=%!ctrlspace#api#Tabline() + + if has('gui_running') && (&guioptions =~# 'e') + set guitablabel=%{ctrlspace#api#Guitablabel()} + + " Fix MacVim issues: + " http://stackoverflow.com/questions/11595301/controlling-tab-names-in-vim + if has('gui_macvim') + autocmd CtrlSpaceInit BufWinEnter * set guitablabel=%{ctrlspace#api#Guitablabel()} + endif + endif + endif + + command! -nargs=* -range CtrlSpace :call ctrlspace#window#Toggle(0) | :call feedkeys( ) + command! -nargs=0 -range CtrlSpaceGoUp :call ctrlspace#window#GoToBufferListPosition("up") + command! -nargs=0 -range CtrlSpaceGoDown :call ctrlspace#window#GoToBufferListPosition("down") + command! -nargs=0 -range CtrlSpaceTabLabel :call ctrlspace#tabs#NewTabLabel(0) + command! -nargs=0 -range CtrlSpaceClearTabLabel :call ctrlspace#tabs#RemoveTabLabel(0) + command! -nargs=* -range CtrlSpaceSaveWorkspace :call ctrlspace#workspaces#SaveWorkspace( ) + command! -nargs=0 -range CtrlSpaceNewWorkspace :call ctrlspace#workspaces#NewWorkspace() + command! -nargs=* -range -bang CtrlSpaceLoadWorkspace :call ctrlspace#workspaces#LoadWorkspace( 0, ) + command! -nargs=* -range -complete=dir CtrlSpaceAddProjectRoot :call ctrlspace#roots#AddProjectRoot( ) + command! -nargs=* -range -complete=dir CtrlSpaceRemoveProjectRoot :call ctrlspace#roots#RemoveProjectRoot( ) + + hi def link CtrlSpaceNormal PMenu + hi def link CtrlSpaceSelected PMenuSel + hi def link CtrlSpaceSearch Search + hi def link CtrlSpaceStatus StatusLine + + if s:config.SetDefaultMapping + call ctrlspace#keys#SetDefaultMapping(s:config.DefaultMappingKey, ":CtrlSpace ") + endif + + call s:initProjectRootsAndBookmarks() + call ctrlspace#keys#Init() + + autocmd CtrlSpaceInit BufEnter * call ctrlspace#buffers#AddBuffer() + + if argc() > 1 && !&diff + autocmd CtrlSpaceInit VimEnter * ++nested exe 'silent argdo call ctrlspace#buffers#AddBuffer()' | rewind | exe exists('syntax_off') ? 'syntax on' : '' + endif + " Since view session files do not set v:this_session and keep the global + " current working directory, we skip those for reloading viminfo. + let v:this_session = '' + let s:last_session = '' + autocmd CtrlSpaceInit SessionLoadPost * ++nested + \ if v:this_session !=# s:last_session | let s:last_session = v:this_session | + \ if fnamemodify(v:this_session, ':t') !=# 'CS_SESSION' | + \ exe 'silent bufdo call ctrlspace#buffers#AddBuffer()' | exe exists('syntax_off') ? 'syntax on' : '' | + \ endif | + \ endif + + autocmd CtrlSpaceInit VimEnter * call ctrlspace#buffers#Init() + autocmd CtrlSpaceInit TabEnter * let t:CtrlSpaceTabJumpCounter = ctrlspace#jumps#IncrementJumpCounter() + + if s:config.SaveWorkspaceOnExit + autocmd CtrlSpaceInit VimLeavePre * if ctrlspace#workspaces#ActiveWorkspace().Status | call ctrlspace#workspaces#SaveWorkspace("") | endif + endif + + if s:config.LoadLastWorkspaceOnStart + autocmd CtrlSpaceInit VimEnter * nested if (argc() == 0) && !empty(ctrlspace#roots#FindProjectRoot()) | call ctrlspace#workspaces#LoadWorkspace(0, "") | endif + endif endfunction -function! s:initProjectRootsAndBookmarks() - let cacheFile = s:config.CacheDir . "/.cs_cache" - let projectRoots = {} - let bookmarks = [] - - if filereadable(cacheFile) - for line in readfile(cacheFile) - if line =~# "CS_PROJECT_ROOT: " - let projectRoots[line[17:]] = 1 - endif - - if line =~# "CS_BOOKMARK: " - let parts = split(line[13:], ctrlspace#context#Separator()) - let bookmark = { - \ "Name": ((len(parts) > 1) ? parts[1] : parts[0]), - \ "Directory": parts[0], - \ "JumpCounter": 0 - \ } - call add(bookmarks, bookmark) - let projectRoots[bookmark.Directory] = 1 - endif - endfor - endif - - call ctrlspace#roots#SetProjectRoots(projectRoots) - call ctrlspace#bookmarks#SetBookmarks(bookmarks) +function! s:initProjectRootsAndBookmarks() abort + let cacheFile = s:config.CacheDir . "/.cs_cache" + let projectRoots = {} + let bookmarks = [] + + if filereadable(cacheFile) + for line in readfile(cacheFile) + if line =~# "CS_PROJECT_ROOT: " + let projectRoots[line[17:]] = 1 + endif + + if line =~# "CS_BOOKMARK: " + let parts = split(line[13:], ctrlspace#context#Separator()) + let bookmark = { + \ "Name": ((len(parts) > 1) ? parts[1] : parts[0]), + \ "Directory": parts[0], + \ "JumpCounter": 0 + \ } + call add(bookmarks, bookmark) + let projectRoots[bookmark.Directory] = 1 + endif + endfor + endif + + call ctrlspace#roots#SetProjectRoots(projectRoots) + call ctrlspace#bookmarks#SetBookmarks(bookmarks) endfunction diff --git a/autoload/ctrlspace/jumps.vim b/autoload/ctrlspace/jumps.vim index 84e936c4..3206d6c5 100644 --- a/autoload/ctrlspace/jumps.vim +++ b/autoload/ctrlspace/jumps.vim @@ -2,84 +2,84 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() let s:jumpCounter = 0 -function! ctrlspace#jumps#IncrementJumpCounter() - let s:jumpCounter += 1 - return s:jumpCounter +function! ctrlspace#jumps#IncrementJumpCounter() abort + let s:jumpCounter += 1 + return s:jumpCounter endfunction -function! s:compareJumps(a, b) - if a:a.counter > a:b.counter - return -1 - elseif a:a.counter < a:b.counter - return 1 - else - return 0 - endif +function! s:compareJumps(a, b) abort + if a:a.counter > a:b.counter + return -1 + elseif a:a.counter < a:b.counter + return 1 + else + return 0 + endif endfunction -function! s:createTabJumps() - let b:jumplines = [] - let b:jumplinesLen = tabpagenr("$") +function! s:createTabJumps() abort + let b:jumplines = [] + let b:jumplinesLen = tabpagenr("$") - for t in range(1, b:jumplinesLen) - let counter = ctrlspace#util#GettabvarWithDefault(t, "CtrlSpaceTabJumpCounter", 0) - call add(b:jumplines, { "line": t, "counter": counter }) - endfor + for t in range(1, b:jumplinesLen) + let counter = ctrlspace#util#GettabvarWithDefault(t, "CtrlSpaceTabJumpCounter", 0) + call add(b:jumplines, { "line": t, "counter": counter }) + endfor endfunction -function! s:createBookmarkJumps() - let b:jumplines = [] - let b:jumplinesLen = b:size - let bookmarks = ctrlspace#bookmarks#Bookmarks() +function! s:createBookmarkJumps() abort + let b:jumplines = [] + let b:jumplinesLen = b:size + let bookmarks = ctrlspace#bookmarks#Bookmarks() - for l in range(1, b:jumplinesLen) - let counter = bookmarks[b:indices[l - 1]].JumpCounter - call add(b:jumplines, { "line": l, "counter": counter }) - endfor + for l in range(1, b:jumplinesLen) + let counter = bookmarks[b:indices[l - 1]].JumpCounter + call add(b:jumplines, { "line": l, "counter": counter }) + endfor endfunction -function! s:createBufferJumps() - let b:jumplines = [] - let b:jumplinesLen = b:size +function! s:createBufferJumps() abort + let b:jumplines = [] + let b:jumplinesLen = b:size - for l in range(1, b:jumplinesLen) - let counter = ctrlspace#util#GetbufvarWithDefault(b:indices[l - 1], "CtrlSpaceJumpCounter", 0) - call add(b:jumplines, { "line": l, "counter": counter }) - endfor + for l in range(1, b:jumplinesLen) + let counter = ctrlspace#util#GetbufvarWithDefault(b:indices[l - 1], "CtrlSpaceJumpCounter", 0) + call add(b:jumplines, { "line": l, "counter": counter }) + endfor endfunction -function! ctrlspace#jumps#Jump(direction) - if !exists("b:jumplines") - let clv = ctrlspace#modes#CurrentListView() +function! ctrlspace#jumps#Jump(direction) abort + if !exists("b:jumplines") + let clv = ctrlspace#modes#CurrentListView() - if clv.Name ==# "Tab" - call s:createTabJumps() - elseif clv.Name ==# "Bookmark" - call s:createBookmarkJumps() - else - call s:createBufferJumps() - endif + if clv.Name ==# "Tab" + call s:createTabJumps() + elseif clv.Name ==# "Bookmark" + call s:createBookmarkJumps() + else + call s:createBufferJumps() + endif - call sort(b:jumplines, function("s:compareJumps")) - endif + call sort(b:jumplines, function("s:compareJumps")) + endif - if !exists("b:jumppos") - let b:jumppos = 0 - endif + if !exists("b:jumppos") + let b:jumppos = 0 + endif - if a:direction == "previous" - let b:jumppos += 1 + if a:direction ==# "previous" + let b:jumppos += 1 - if b:jumppos == b:jumplinesLen - let b:jumppos = b:jumplinesLen - 1 - endif - elseif a:direction == "next" - let b:jumppos -= 1 + if b:jumppos == b:jumplinesLen + let b:jumppos = b:jumplinesLen - 1 + endif + elseif a:direction ==# "next" + let b:jumppos -= 1 - if b:jumppos < 0 - let b:jumppos = 0 - endif - endif + if b:jumppos < 0 + let b:jumppos = 0 + endif + endif - call ctrlspace#window#MoveSelectionBar(string(b:jumplines[b:jumppos]["line"])) + call ctrlspace#window#MoveSelectionBar(string(b:jumplines[b:jumppos]["line"])) endfunction diff --git a/autoload/ctrlspace/keys.vim b/autoload/ctrlspace/keys.vim index 6bd1914e..1620e203 100644 --- a/autoload/ctrlspace/keys.vim +++ b/autoload/ctrlspace/keys.vim @@ -5,165 +5,171 @@ let s:keyMap = {} let s:characters = {} let s:keyEscSequence = 0 -function! ctrlspace#keys#KeyNames() - return s:keyNames +function! ctrlspace#keys#KeyNames() abort + return s:keyNames endfunction -function! ctrlspace#keys#CharacterClasses() - return s:characters +function! ctrlspace#keys#CharacterClasses() abort + return s:characters endfunction -function! ctrlspace#keys#KeyMap() - return s:keyMap +function! ctrlspace#keys#KeyMap() abort + return s:keyMap endfunction -function! ctrlspace#keys#MarkKeyEscSequence() - let s:keyEscSequence = 1 +function! ctrlspace#keys#MarkKeyEscSequence() abort + let s:keyEscSequence = 1 endfunction -function! ctrlspace#keys#Init() - call s:initKeyNames() - call s:initKeyMap() - call ctrlspace#keys#common#Init() - call ctrlspace#keys#help#Init() - call ctrlspace#keys#nop#Init() - call ctrlspace#keys#search#Init() - call ctrlspace#keys#buffer#Init() - call ctrlspace#keys#file#Init() - call ctrlspace#keys#tab#Init() - call ctrlspace#keys#workspace#Init() - call ctrlspace#keys#bookmark#Init() - call s:initCustomMappings() +function! ctrlspace#keys#Init() abort + call s:initKeyNames() + call s:initKeyMap() + call ctrlspace#keys#common#Init() + call ctrlspace#keys#help#Init() + call ctrlspace#keys#nop#Init() + call ctrlspace#keys#search#Init() + call ctrlspace#keys#buffer#Init() + call ctrlspace#keys#file#Init() + call ctrlspace#keys#tab#Init() + call ctrlspace#keys#workspace#Init() + call ctrlspace#keys#bookmark#Init() + call s:initCustomMappings() + call ctrlspace#keys#nop#DbmdexInit() endfunction -function! s:initCustomMappings() - for m in ["Search", "Help", "Nop", "Buffer", "File", "Tab", "Workspace", "Bookmark"] - if has_key(s:config.Keys, m) - for [k, fn] in items(s:config.Keys[m]) - call ctrlspace#keys#AddMapping(fn, m, [k]) - endfor - endif - endfor +function! s:initCustomMappings() abort + for m in ["Search", "Help", "Nop", "Buffer", "File", "Tab", "Workspace", "Bookmark"] + if has_key(s:config.Keys, m) + for [k, fn] in items(s:config.Keys[m]) + " normalize synomymous keynames Enter, Return and CR all to CR + let k = (k ==? 'return' || k ==? 'enter' ? 'CR' : k) + call ctrlspace#keys#AddMapping(fn, m, [k]) + endfor + endif + endfor endfunction -function! s:initKeyNames() - let lowercase = "q w e r t y u i o p a s d f g h j k l z x c v b n m" - let uppercase = toupper(lowercase) +function! s:initKeyNames() abort + let lowercase = "q w e r t y u i o p a s d f g h j k l z x c v b n m" + let uppercase = toupper(lowercase) - let controlList = [] + let controlList = [] - for l in split(lowercase, " ") - call add(controlList, "C-" . l) - endfor + for l in split(lowercase, " ") + call add(controlList, "C-" . l) + endfor - call add(controlList, "C-^") - call add(controlList, "C-]") + call add(controlList, "C-^") + call add(controlList, "C-]") - let controls = join(controlList, " ") + let controls = join(controlList, " ") - let numbers = "1 2 3 4 5 6 7 8 9 0" - let specials = "Space CR BS Tab S-Tab / ? ; : , . < > [ ] { } ( ) ' ` ~ + - _ = ! @ # $ % ^ & * C-f C-b C-u C-d C-h C-w " . - \ "Bar BSlash MouseDown MouseUp LeftDrag LeftRelease 2-LeftMouse " . - \ "Down Up Home End Left Right PageUp PageDown " . - \ 'F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 "' + let numbers = "1 2 3 4 5 6 7 8 9 0" + let punctuation = "; : , . < > [ ] { } ( ) ' ` ~ + - _ = ! @ # $ % ^ & * / \ " . + \ '"' + let specials = "Space CR BS Tab S-Tab / ? C-f C-b C-u C-d C-h C-w " . + \ "Bar BSlash MouseDown MouseUp LeftDrag LeftRelease 2-LeftMouse " . + \ "Down Up Home End Left Right PageUp PageDown " . + \ "F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12" - if !s:config.UseMouseAndArrowsInTerm || has("gui_running") - let specials .= " Esc" - endif + if !s:config.UseMouseAndArrowsInTerm || has("gui_running") + let specials .= " Esc" + endif - let specials .= (has("gui_running") || has("win32")) ? " C-Space" : " Nul" + let specials .= (has("gui_running") || has("win32")) ? " C-Space" : " Nul" - let keyNames = split(join([lowercase, uppercase, controls, numbers, specials], " "), " ") + let keyNames = split(join([lowercase, uppercase, controls, numbers, punctuation, specials], " "), " ") - " won't work with leader mappings - if ctrlspace#keys#IsDefaultKey() - for i in range(len(keyNames)) - let fullKeyName = (strlen(keyNames[i]) > 1) ? ("<" . keyNames[i] . ">") : keyNames[i] + " won't work with leader mappings + if ctrlspace#keys#IsDefaultKey() + for i in range(len(keyNames)) + let fullKeyName = (strlen(keyNames[i]) > 1) ? ("<" . keyNames[i] . ">") : keyNames[i] - if fullKeyName ==# ctrlspace#keys#DefaultKey() - call remove(keyNames, i) - break - endif - endfor - endif + if fullKeyName ==# ctrlspace#keys#DefaultKey() + call remove(keyNames, i) + break + endif + endfor + endif - let s:keyNames = keyNames - let s:characters.lowercase = split(lowercase, " ") - let s:characters.uppercase = split(uppercase, " ") - let s:characters.controls = split(controls, " ") - let s:characters.numbers = split(numbers, " ") - let s:characters.specials = split(specials, " ") + let s:keyNames = keyNames + let s:characters.lowercase = split(lowercase, " ") + let s:characters.uppercase = split(uppercase, " ") + let s:characters.controls = split(controls, " ") + let s:characters.numbers = split(numbers, " ") + let s:characters.punctuation = split(punctuation, " ") + let s:characters.specials = split(specials, " ") endfunction -function! ctrlspace#keys#Undefined(k) - call ctrlspace#ui#Msg("Key '" . a:k . "' doesn't work in this view.") +function! ctrlspace#keys#Undefined(k) abort + call ctrlspace#ui#Msg("Key '" . a:k . "' doesn't work in this view.") endfunction -function! s:initKeyMap() - let Undefined = function("ctrlspace#keys#Undefined") - let blankMap = {} +function! s:initKeyMap() abort + let Undefined = function("ctrlspace#keys#Undefined") + let blankMap = {} - for k in s:keyNames - let blankMap[k] = Undefined - endfor + for k in s:keyNames + let blankMap[k] = Undefined + endfor - for m in ["Search", "Help", "Nop", "Buffer", "File", "Tab", "Workspace", "Bookmark"] - let s:keyMap[m] = copy(blankMap) - endfor + for m in ["Search", "Help", "Nop", "Buffer", "File", "Tab", "Workspace", "Bookmark"] + let s:keyMap[m] = copy(blankMap) + endfor endfunction -function! ctrlspace#keys#AddMapping(funcName, mapName, keys) - let keys = [] +function! ctrlspace#keys#AddMapping(funcName, mapName, keys) abort + let keys = [] - for entry in a:keys - if has_key(s:characters, entry) - call extend(keys, s:characters[entry]) - else - call add(keys, entry) - endif + for entry in a:keys + if has_key(s:characters, entry) + call extend(keys, s:characters[entry]) + else + call add(keys, entry) + endif - call ctrlspace#help#AddMapping(a:funcName, a:mapName, entry) - endfor + call ctrlspace#help#AddMapping(a:funcName, a:mapName, entry) + endfor - let FuncRef = function(a:funcName) + let FuncRef = function(a:funcName) - for k in keys - let s:keyMap[a:mapName][k] = FuncRef - endfor + for k in keys + let s:keyMap[a:mapName][k] = FuncRef + endfor endfunction -function! ctrlspace#keys#Keypressed(key) - let key = (s:keyEscSequence && (a:key ==# "Z")) ? "S-Tab" : a:key - let s:keyEscSequence = 0 - - if s:modes.Help.Enabled - let mapName = "Help" - elseif s:modes.Search.Enabled - let mapName = "Search" - elseif s:modes.Nop.Enabled - let mapName = "Nop" - else - let mapName = ctrlspace#modes#CurrentListView().Name - endif - - call s:keyMap[mapName][key](key) +function! ctrlspace#keys#Keypressed(key) abort + let key = (s:keyEscSequence && (a:key ==# "Z")) ? "S-Tab" : a:key + let s:keyEscSequence = 0 + + if s:modes.Help.Enabled + let mapName = "Help" + elseif s:modes.Search.Enabled + let mapName = "Search" + elseif s:modes.Nop.Enabled + let mapName = "Nop" + else + let mapName = ctrlspace#modes#CurrentListView().Name + endif + + call s:keyMap[mapName][key](key) endfunction -function! ctrlspace#keys#SetDefaultMapping(key, action) - let s:defaultKey = a:key - if !empty(s:defaultKey) - if s:defaultKey ==? " " && !has("gui_running") && !has("win32") - let s:defaultKey = " " - endif +function! ctrlspace#keys#SetDefaultMapping(key, action) abort + let s:defaultKey = a:key + if !empty(s:defaultKey) + if s:defaultKey ==? " " && !has("gui_running") && !has("win32") + let s:defaultKey = " " + endif - silent! exe 'nnoremap ' . s:defaultKey . ' ' . a:action - endif + silent! exe 'nnoremap ' . s:defaultKey . ' ' . a:action + endif endfunction -function! ctrlspace#keys#IsDefaultKey() - return exists("s:defaultKey") +function! ctrlspace#keys#IsDefaultKey() abort + return exists("s:defaultKey") endfunction -function! ctrlspace#keys#DefaultKey() - return s:defaultKey +function! ctrlspace#keys#DefaultKey() abort + return s:defaultKey endfunction diff --git a/autoload/ctrlspace/keys/bookmark.vim b/autoload/ctrlspace/keys/bookmark.vim index 451b5dab..80176edc 100644 --- a/autoload/ctrlspace/keys/bookmark.vim +++ b/autoload/ctrlspace/keys/bookmark.vim @@ -1,81 +1,81 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#bookmark#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#GoToBookmark", "Bookmark", ["Tab", "CR", "Space"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Rename", "Bookmark", ["=", "m"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Edit", "Bookmark", ["e"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Add", "Bookmark", ["a", "A"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Delete", "Bookmark", ["d"]) +function! ctrlspace#keys#bookmark#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#GoToBookmark", "Bookmark", ["Tab", "CR", "Space"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Rename", "Bookmark", ["=", "m"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Edit", "Bookmark", ["e"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Add", "Bookmark", ["a", "A"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#bookmark#Delete", "Bookmark", ["d"]) endfunction -function! ctrlspace#keys#bookmark#GoToBookmark(k) - let nr = ctrlspace#window#SelectedIndex() +function! ctrlspace#keys#bookmark#GoToBookmark(k) abort + let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#window#Kill(0, 1) - call ctrlspace#bookmarks#GoToBookmark(nr) + call ctrlspace#window#Kill(0, 1) + call ctrlspace#bookmarks#GoToBookmark(nr) - if a:k ==# "CR" - call ctrlspace#window#Toggle(0) - elseif a:k ==# "Space" - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Bookmark.Enable() - call ctrlspace#window#Toggle(1) - endif + if a:k ==# "CR" + call ctrlspace#window#Toggle(0) + elseif a:k ==# "Space" + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Bookmark.Enable() + call ctrlspace#window#Toggle(1) + endif - call ctrlspace#ui#DelayedMsg() + call ctrlspace#ui#DelayedMsg() endfunction -function! ctrlspace#keys#bookmark#Rename(k) - let curline = line(".") - let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#bookmarks#ChangeBookmarkName(nr) - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) - call ctrlspace#window#MoveSelectionBar(curline) - call ctrlspace#ui#DelayedMsg() +function! ctrlspace#keys#bookmark#Rename(k) abort + let curline = line(".") + let nr = ctrlspace#window#SelectedIndex() + call ctrlspace#bookmarks#ChangeBookmarkName(nr) + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) + call ctrlspace#window#MoveSelectionBar(curline) + call ctrlspace#ui#DelayedMsg() endfunction -function! ctrlspace#keys#bookmark#Edit(k) - let curline = line(".") - let nr = ctrlspace#window#SelectedIndex() +function! ctrlspace#keys#bookmark#Edit(k) abort + let curline = line(".") + let nr = ctrlspace#window#SelectedIndex() - if ctrlspace#bookmarks#ChangeBookmarkDirectory(nr) - call ctrlspace#window#Kill(0, 1) - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Bookmark.Enable() - call ctrlspace#window#Toggle(1) - call ctrlspace#window#MoveSelectionBar(curline) - call ctrlspace#ui#DelayedMsg() - endif + if ctrlspace#bookmarks#ChangeBookmarkDirectory(nr) + call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Bookmark.Enable() + call ctrlspace#window#Toggle(1) + call ctrlspace#window#MoveSelectionBar(curline) + call ctrlspace#ui#DelayedMsg() + endif endfunction -function! ctrlspace#keys#bookmark#Add(k) - if a:k ==# "a" - let result = ctrlspace#bookmarks#AddNewBookmark(ctrlspace#window#SelectedIndex()) - else - let result = ctrlspace#bookmarks#AddNewBookmark() - endif +function! ctrlspace#keys#bookmark#Add(k) abort + if a:k ==# "a" + let result = ctrlspace#bookmarks#AddNewBookmark(ctrlspace#window#SelectedIndex()) + else + let result = ctrlspace#bookmarks#AddNewBookmark() + endif - if result - call ctrlspace#window#Kill(0, 1) - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Bookmark.Enable() - call ctrlspace#window#Toggle(1) - call ctrlspace#ui#DelayedMsg() - endif + if result + call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Bookmark.Enable() + call ctrlspace#window#Toggle(1) + call ctrlspace#ui#DelayedMsg() + endif endfunction -function! ctrlspace#keys#bookmark#Delete(k) - let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#bookmarks#RemoveBookmark(nr) - call ctrlspace#window#Kill(0, 1) - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Bookmark.Enable() - call ctrlspace#window#Toggle(1) - call ctrlspace#ui#DelayedMsg() +function! ctrlspace#keys#bookmark#Delete(k) abort + let nr = ctrlspace#window#SelectedIndex() + call ctrlspace#bookmarks#RemoveBookmark(nr) + call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Bookmark.Enable() + call ctrlspace#window#Toggle(1) + call ctrlspace#ui#DelayedMsg() endfunction diff --git a/autoload/ctrlspace/keys/buffer.vim b/autoload/ctrlspace/keys/buffer.vim index df9ab243..bebffcd9 100644 --- a/autoload/ctrlspace/keys/buffer.vim +++ b/autoload/ctrlspace/keys/buffer.vim @@ -1,321 +1,287 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#buffer#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SearchParentDirectory", "Buffer", ["BSlash"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SearchParentDirectoryInFile", "Buffer", ["Bar"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBuffer", "Buffer", ["CR"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffers", "Buffer", ["Space"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToWindow", "Buffer", ["Tab"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToWindowAndBack", "Buffer", ["S-Tab"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#VisibleMode", "Buffer", ["*"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#ZoomMode", "Buffer", ["z"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBufferVS", "Buffer", ["v"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersVS", "Buffer", ["V"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBufferSP", "Buffer", ["s"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersSP", "Buffer", ["S"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseWindow", "Buffer", ["x"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseManyWindows", "Buffer", ["X"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBufferT", "Buffer", ["t"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersT", "Buffer", ["T"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersCT", "Buffer", ["C-t"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewTabLabel", "Buffer", ["="]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#RemoveTabLabel", "Buffer", ["_"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#MoveTab", "Buffer", ["+", "-"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SwitchTab", "Buffer", ["[", "]"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CopyBufferToTab", "Buffer", ["<", ">"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#MoveBufferToTab", "Buffer", ["{", "}"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DeleteBuffer", "Buffer", ["d"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DeleteHiddenNonameBuffers", "Buffer", ["D"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#ToggleAllMode", "Buffer", ["a"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#ToggleAllModeAndSearch", "Buffer", ["A"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DetachBuffer", "Buffer", ["f"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DeleteForeignBuffers", "Buffer", ["F"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseBuffer", "Buffer", ["c"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseTab", "Buffer", ["C"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#EditFile", "Buffer", ["e"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#ExploreDirectory", "Buffer", ["E"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#GoToDirectory", "Buffer", ["i", "I"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RemoveFile", "Buffer", ["R"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RenameFileOrBuffer", "Buffer", ["m"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#CopyFileOrBuffer", "Buffer", ["y"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToBufferOrFile", "Buffer", ["g", "G"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewWorkspace", "Buffer", ["N"]) -endfunction - -function! ctrlspace#keys#buffer#SearchParentDirectory(k) - call ctrlspace#search#SearchParentDirectoryCycle() -endfunction - -function! ctrlspace#keys#buffer#SearchParentDirectoryInFile(k) - call ctrlspace#search#SearchParentDirectoryCycle() - call ctrlspace#keys#common#ToggleFileMode(a:k) -endfunction - -function! ctrlspace#keys#buffer#LoadBuffer(k) - call ctrlspace#buffers#LoadBuffer() -endfunction - -function! ctrlspace#keys#buffer#LoadManyBuffers(k) - call ctrlspace#buffers#LoadManyBuffers() +function! ctrlspace#keys#buffer#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SearchParentDirectory", "Buffer", ["BSlash"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SearchParentDirectoryInFile", "Buffer", ["Bar"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBuffer", "Buffer", ["CR"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffers", "Buffer", ["Space"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToWindow", "Buffer", ["Tab"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToWindowAndBack", "Buffer", ["S-Tab"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#VisibleMode", "Buffer", ["*"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#ZoomMode", "Buffer", ["z"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBufferVS", "Buffer", ["v"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersVS", "Buffer", ["V"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBufferSP", "Buffer", ["s"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersSP", "Buffer", ["S"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseWindow", "Buffer", ["x"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseManyWindows", "Buffer", ["X"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadBufferT", "Buffer", ["t"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersT", "Buffer", ["T"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#LoadManyBuffersCT", "Buffer", ["C-t"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewTabLabel", "Buffer", ["="]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#RemoveTabLabel", "Buffer", ["_"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#MoveTab", "Buffer", ["+", "-"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SwitchTab", "Buffer", ["[", "]"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CopyBufferToTab", "Buffer", ["<", ">"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#MoveBufferToTab", "Buffer", ["{", "}"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DeleteBuffer", "Buffer", ["d"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DeleteHiddenNonameBuffers", "Buffer", ["D"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#ToggleAllMode", "Buffer", ["a"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#ToggleAllModeAndSearch", "Buffer", ["A"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DetachBuffer", "Buffer", ["f"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#DeleteForeignBuffers", "Buffer", ["F"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseBuffer", "Buffer", ["c"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseTab", "Buffer", ["C"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#EditFile", "Buffer", ["e"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#ExploreDirectory", "Buffer", ["E"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#GoToDirectory", "Buffer", ["i", "I"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RemoveFile", "Buffer", ["R"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RenameFileOrBuffer", "Buffer", ["m"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#CopyFileOrBuffer", "Buffer", ["y"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToBufferOrFile", "Buffer", ["g", "G"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewWorkspace", "Buffer", ["N"]) +endfunction + +function! ctrlspace#keys#buffer#SearchParentDirectory(k) abort + call ctrlspace#search#SearchParentDirectoryCycle() +endfunction + +function! ctrlspace#keys#buffer#SearchParentDirectoryInFile(k) abort + call ctrlspace#search#SearchParentDirectoryCycle() + call ctrlspace#keys#common#ToggleFileMode(a:k) +endfunction + +function! ctrlspace#keys#buffer#LoadBuffer(k) abort + call ctrlspace#buffers#LoadBuffer() +endfunction + +function! ctrlspace#keys#buffer#LoadManyBuffers(k) abort + call ctrlspace#buffers#LoadManyBuffers() endfunction -function! ctrlspace#keys#buffer#GoToWindow(k) - call ctrlspace#window#GoToWindow() -endfunction +function! ctrlspace#keys#buffer#GoToWindow(k) abort + call ctrlspace#window#GoToWindow() +endfunction -function! ctrlspace#keys#buffer#GoToWindowAndBack(k) - let subMode = s:modes.Buffer.Data.SubMode +function! ctrlspace#keys#buffer#GoToWindowAndBack(k) abort + let subMode = s:modes.Buffer.Data.SubMode - if ctrlspace#window#GoToWindow() - call ctrlspace#window#Toggle(0) - - if subMode !=# "single" - call ctrlspace#window#Kill(0, 0) - call s:modes.Buffer.SetData("SubMode", subMode) - call ctrlspace#window#Toggle(1) - endif - endif -endfunction - -function! ctrlspace#keys#buffer#VisibleMode(k) - if s:modes.Buffer.Data.SubMode ==# "visible" - call s:modes.Buffer.SetData("SubMode", "single") - else - call s:modes.Buffer.SetData("SubMode", "visible") - endif - - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) -endfunction + if ctrlspace#window#GoToWindow() + call ctrlspace#window#Toggle(0) -function! ctrlspace#keys#buffer#ZoomMode(k) - if !s:modes.Zoom.Enabled - call ctrlspace#buffers#ZoomBuffer(0) - else - call ctrlspace#window#Kill(0, 1) - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - if s:modes.Zoom.Data.Mode ==# "File" - call s:modes.File.Enable() - else - call s:modes.Buffer.SetData("SubMode", s:modes.Zoom.Data.SubMode) - endif - call s:modes.Search.SetData("Letters", copy(s:modes.Zoom.Data.Letters)) - call ctrlspace#window#Toggle(1) - call ctrlspace#window#MoveSelectionBar(s:modes.Zoom.Data.Line) - endif + if subMode !=# "single" + call ctrlspace#window#Kill(0, 0) + call s:modes.Buffer.SetData("SubMode", subMode) + call ctrlspace#window#Toggle(1) + endif + endif endfunction -function! ctrlspace#keys#buffer#LoadBufferVS(k) - call ctrlspace#buffers#LoadBuffer("vs") -endfunction +function! ctrlspace#keys#buffer#VisibleMode(k) abort + if s:modes.Buffer.Data.SubMode ==# "visible" + call s:modes.Buffer.SetData("SubMode", "single") + else + call s:modes.Buffer.SetData("SubMode", "visible") + endif -function! ctrlspace#keys#buffer#LoadManyBuffersVS(k) - call ctrlspace#buffers#LoadManyBuffers("vs") + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#keys#buffer#LoadBufferSP(k) - call ctrlspace#buffers#LoadBuffer("sp") +function! ctrlspace#keys#buffer#ZoomMode(k) abort + if !s:modes.Zoom.Enabled + call ctrlspace#buffers#ZoomBuffer(0) + else + call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + if s:modes.Zoom.Data.Mode ==# "File" + call s:modes.File.Enable() + else + call s:modes.Buffer.SetData("SubMode", s:modes.Zoom.Data.SubMode) + endif + call s:modes.Search.SetData("Letters", copy(s:modes.Zoom.Data.Letters)) + call ctrlspace#window#Toggle(1) + call ctrlspace#window#MoveSelectionBar(s:modes.Zoom.Data.Line) + endif endfunction -function! ctrlspace#keys#buffer#LoadManyBuffersSP(k) - call ctrlspace#buffers#LoadManyBuffers("sp") +function! ctrlspace#keys#buffer#LoadBufferVS(k) abort + call ctrlspace#buffers#LoadBuffer("vs") endfunction -function! ctrlspace#keys#buffer#CloseWindow(k) - let curln = line(".") - if (winnr("$") > 2) && ctrlspace#window#GoToWindow() - silent! exe "wincmd c" - call ctrlspace#window#Toggle(0) - call ctrlspace#window#MoveSelectionBar(curln) - endif +function! ctrlspace#keys#buffer#LoadManyBuffersVS(k) abort + call ctrlspace#buffers#LoadManyBuffers("vs") endfunction -function! ctrlspace#keys#buffer#CloseManyWindows(k) - let curln = line(".") - if (winnr("$") > 2) && ctrlspace#window#GoToWindow() - only - call ctrlspace#window#Toggle(0) - call ctrlspace#window#MoveSelectionBar(curln) - endif +function! ctrlspace#keys#buffer#LoadBufferSP(k) abort + call ctrlspace#buffers#LoadBuffer("sp") endfunction -function! ctrlspace#keys#buffer#LoadBufferT(k) - call ctrlspace#buffers#LoadBuffer("tabnew") +function! ctrlspace#keys#buffer#LoadManyBuffersSP(k) abort + call ctrlspace#buffers#LoadManyBuffers("sp") endfunction -function! ctrlspace#keys#buffer#LoadManyBuffersT(k) - if s:modes.NextTab.Enabled - call ctrlspace#buffers#LoadManyBuffers("tabnext", "tabprevious") - else - call s:modes.NextTab.Enable() - call ctrlspace#buffers#LoadManyBuffers("tabnew", "tabprevious") - endif +function! ctrlspace#keys#buffer#CloseWindow(k) abort + let curln = line(".") + if (winnr("$") > 2) && ctrlspace#window#GoToWindow() + silent! exe "wincmd c" + call ctrlspace#window#Toggle(0) + call ctrlspace#window#MoveSelectionBar(curln) + endif endfunction -function! ctrlspace#keys#buffer#LoadManyBuffersCT(k) - call s:modes.NextTab.Enable() - call ctrlspace#buffers#LoadManyBuffers("tabnew", "tabprevious") +function! ctrlspace#keys#buffer#CloseManyWindows(k) abort + let curln = line(".") + if (winnr("$") > 2) && ctrlspace#window#GoToWindow() + only + call ctrlspace#window#Toggle(0) + call ctrlspace#window#MoveSelectionBar(curln) + endif endfunction -function! ctrlspace#keys#buffer#NewTabLabel(k) - call ctrlspace#tabs#NewTabLabel(0) - call ctrlspace#util#SetStatusline() - redraws +function! ctrlspace#keys#buffer#LoadBufferT(k) abort + call ctrlspace#buffers#LoadBuffer("tabnew") endfunction -function! ctrlspace#keys#buffer#MoveTab(k) - if v:version < 704 - if a:k ==# "+" - silent! exe "tabm" . tabpagenr() - elseif a:k ==# "-" - silent! exe "tabm" . (tabpagenr() - 2) - endif - else - silent! exe "tabm" . a:k . "1" - endif - - call ctrlspace#util#SetStatusline() - redraws +function! ctrlspace#keys#buffer#LoadManyBuffersT(k) abort + if s:modes.NextTab.Enabled + call ctrlspace#buffers#LoadManyBuffers("tabnext", "tabprevious") + else + call s:modes.NextTab.Enable() + call ctrlspace#buffers#LoadManyBuffers("tabnew", "tabprevious") + endif endfunction -function! ctrlspace#keys#buffer#RemoveTabLabel(k) - call ctrlspace#tabs#RemoveTabLabel(0) - call ctrlspace#util#SetStatusline() - redraw! +function! ctrlspace#keys#buffer#LoadManyBuffersCT(k) abort + call s:modes.NextTab.Enable() + call ctrlspace#buffers#LoadManyBuffers("tabnew", "tabprevious") endfunction -function! ctrlspace#keys#buffer#SwitchTab(k) - call ctrlspace#window#Kill(0, 1) - - if a:k ==# "[" - silent! exe "normal! gT" - elseif a:k ==# "]" - silent! exe "normal! gt" - endif - - call ctrlspace#window#Toggle(0) +function! ctrlspace#keys#buffer#NewTabLabel(k) abort + call ctrlspace#tabs#NewTabLabel(0) + call ctrlspace#util#SetStatusline() + redraws endfunction -function! ctrlspace#keys#buffer#CopyBufferToTab(k) - if s:modes.Buffer.Data.SubMode ==# "all" - return 0 - endif - - let curTab = tabpagenr() +function! ctrlspace#keys#buffer#MoveTab(k) abort + call ctrlspace#keys#tab#MoveHelper(a:k) + call ctrlspace#util#SetStatusline() + redraws +endfunction - if a:k ==# "<" - if curTab > 1 - call ctrlspace#buffers#CopyBufferToTab(curTab - 1) - endif - elseif a:k ==# ">" - if curTab < tabpagenr("$") - call ctrlspace#buffers#CopyBufferToTab(curTab + 1) - endif - endif +function! ctrlspace#keys#buffer#RemoveTabLabel(k) abort + call ctrlspace#tabs#RemoveTabLabel(0) + call ctrlspace#util#SetStatusline() + redraw! endfunction -function! ctrlspace#keys#buffer#MoveBufferToTab(k) - if s:modes.Buffer.Data.SubMode ==# "all" - return 0 - endif +function! ctrlspace#keys#buffer#SwitchTab(k) abort + call ctrlspace#window#Kill(0, 1) + let dir = {'[': 'BWD', ']': 'FWD'}[a:k] + call ctrlspace#changebuftab#Execute("SwitchTabInBufMode", dir) + call ctrlspace#window#Toggle(0) +endfunction - let curTab = tabpagenr() +function! ctrlspace#keys#buffer#CopyBufferToTab(k) abort + if s:modes.Buffer.Data.SubMode ==# "all" + return 0 + endif + let dir = {'<': 'BWD', '>': 'FWD'}[a:k] + call ctrlspace#changebuftab#Execute('CopyBufferToTab', dir) +endfunction - if a:k ==# "{" - if curTab > 1 - call ctrlspace#buffers#MoveBufferToTab(curTab - 1) - endif - elseif a:k ==# "}" - if curTab < tabpagenr("$") - call ctrlspace#buffers#MoveBufferToTab(curTab + 1) - endif - endif +function! ctrlspace#keys#buffer#MoveBufferToTab(k) abort + if s:modes.Buffer.Data.SubMode ==# "all" + return 0 + endif + let dir = {'{': 'BWD', '}': 'FWD'}[a:k] + call ctrlspace#changebuftab#Execute('MoveBufferToTab', dir) endfunction -function! ctrlspace#keys#buffer#DeleteBuffer(k) - call ctrlspace#buffers#DeleteBuffer() +function! ctrlspace#keys#buffer#DeleteBuffer(k) abort + call ctrlspace#buffers#DeleteBuffer() endfunction -function! ctrlspace#keys#buffer#DeleteHiddenNonameBuffers(k) - call ctrlspace#buffers#DeleteHiddenNonameBuffers(0) - call ctrlspace#ui#DelayedMsg() +function! ctrlspace#keys#buffer#DeleteHiddenNonameBuffers(k) abort + call ctrlspace#buffers#DeleteHiddenNonameBuffers(0) + call ctrlspace#ui#DelayedMsg() endfunction -function! ctrlspace#keys#buffer#DetachBuffer(k) - if s:modes.Buffer.Data.SubMode ==# "single" - call ctrlspace#buffers#DetachBuffer() - endif +function! ctrlspace#keys#buffer#DetachBuffer(k) abort + if s:modes.Buffer.Data.SubMode ==# "single" + call ctrlspace#buffers#DetachBuffer() + endif endfunction -function! ctrlspace#keys#buffer#DeleteForeignBuffers(k) - call ctrlspace#buffers#DeleteForeignBuffers(0) - call ctrlspace#ui#DelayedMsg() +function! ctrlspace#keys#buffer#DeleteForeignBuffers(k) abort + call ctrlspace#buffers#DeleteForeignBuffers(0) + call ctrlspace#ui#DelayedMsg() endfunction -function! ctrlspace#keys#buffer#CloseBuffer(k) - call ctrlspace#buffers#CloseBuffer() +function! ctrlspace#keys#buffer#CloseBuffer(k) abort + call ctrlspace#buffers#CloseBuffer() endfunction -function! ctrlspace#keys#buffer#CloseTab(k) - call ctrlspace#tabs#CloseTab() - call ctrlspace#ui#Msg("Current tab closed.") +function! ctrlspace#keys#buffer#CloseTab(k) abort + call ctrlspace#tabs#CloseTab() + call ctrlspace#ui#Msg("Current tab closed.") endfunction -function! ctrlspace#keys#buffer#ToggleAllMode(k) - call s:toggleAllMode() +function! ctrlspace#keys#buffer#ToggleAllMode(k) abort + call s:toggleAllMode() endfunction -function! ctrlspace#keys#buffer#ToggleAllModeAndSearch(k) - if s:modes.Buffer.Data.SubMode !=# "all" - call s:toggleAllMode() - endif - call ctrlspace#search#SwitchSearchMode(1) +function! ctrlspace#keys#buffer#ToggleAllModeAndSearch(k) abort + if s:modes.Buffer.Data.SubMode !=# "all" + call s:toggleAllMode() + endif + call ctrlspace#search#SwitchSearchMode(1) endfunction -function! ctrlspace#keys#buffer#GoToBufferOrFile(k) - call ctrlspace#buffers#GoToBufferOrFile(a:k ==# "g" ? "next" : "previous") +function! ctrlspace#keys#buffer#GoToBufferOrFile(k) abort + call ctrlspace#buffers#GoToBufferOrFile(a:k ==# "g" ? "next" : "previous") endfunction -function! ctrlspace#keys#buffer#NewWorkspace(k) - let saveWorkspaceBefore = 0 - let active = ctrlspace#workspaces#ActiveWorkspace() +function! ctrlspace#keys#buffer#NewWorkspace(k) abort + let saveWorkspaceBefore = 0 + let active = ctrlspace#workspaces#ActiveWorkspace() - if active.Status == 2 - if s:config.SaveWorkspaceOnSwitch - let saveWorkspaceBefore = 1 - elseif !ctrlspace#ui#Confirmed("Current workspace ('" . active.Name . "') not saved. Proceed anyway?") - return 0 - endif - endif + if active.Status == 2 + if s:config.SaveWorkspaceOnSwitch + let saveWorkspaceBefore = 1 + elseif !ctrlspace#ui#Confirmed("Current workspace ('" . active.Name . "') not saved. Proceed anyway?") + return 0 + endif + endif - if !ctrlspace#ui#ProceedIfModified() - return 0 - endif + if !ctrlspace#ui#ProceedIfModified() + return 0 + endif - call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Kill(0, 1) - if saveWorkspaceBefore - call ctrlspace#workspaces#SaveWorkspace("") - endif + if saveWorkspaceBefore + call ctrlspace#workspaces#SaveWorkspace("") + endif - call ctrlspace#workspaces#NewWorkspace() - call ctrlspace#window#Toggle(0) - return 1 + call ctrlspace#workspaces#NewWorkspace() + call ctrlspace#window#Toggle(0) + return 1 endfunction -function! s:toggleAllMode() - if s:modes.Buffer.Data.SubMode !=# "all" - call s:modes.Buffer.SetData("SubMode", "all") - else - call s:modes.Buffer.SetData("SubMode", "single") - endif +function! s:toggleAllMode() abort + if s:modes.Buffer.Data.SubMode !=# "all" + call s:modes.Buffer.SetData("SubMode", "all") + else + call s:modes.Buffer.SetData("SubMode", "single") + endif - if !empty(s:modes.Search.Data.Letters) - call s:modes.Search.SetData("NewSearchPerformed", 1) - endif + if !empty(s:modes.Search.Data.Letters) + call s:modes.Search.SetData("NewSearchPerformed", 1) + endif - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) endfunction diff --git a/autoload/ctrlspace/keys/common.vim b/autoload/ctrlspace/keys/common.vim index 833c0cf8..eb582dcb 100644 --- a/autoload/ctrlspace/keys/common.vim +++ b/autoload/ctrlspace/keys/common.vim @@ -4,336 +4,411 @@ let s:commonMap = {} let s:helpMap = {} let s:lastListView = "Buffer" -function! ctrlspace#keys#common#Init() - call s:map("ToggleHelp", "?") - call s:map("Down", "j") - call s:map("Up", "k") - call s:map("Previous", "p") - call s:map("PreviousCR", "P") - call s:map("Next", "n") - call s:map("MouseDown", "MouseDown") - call s:map("MouseUp", "MouseUp") - call s:map("LeftRelease", "LeftRelease") - call s:map("LeftMouse2", '2-LeftMouse') - call s:map("DownArrow", "Down") - call s:map("UpArrow", "Up") - call s:map("Home", "Home") - call s:map("Top", "K") - call s:map("End", "End") - call s:map("Bottom", "J") - call s:map("PageDown", "PageDown") - call s:map("ScrollDown", 'C-f') - call s:map("PageUp", "PageUp") - call s:map("ScrollUp", 'C-b') - call s:map("HalfScrollDown", 'C-d') - call s:map("HalfScrollUp", 'C-u') - call s:map("Close", "q", "Esc", 'C-c') - call s:map("Quit", "Q") - call s:map("EnterSearchMode", "/") - call s:map("RestorePreviousSearch", 'C-p') - call s:map("RestoreNextSearch", 'C-n') - call s:map("BackOrClearSearch", "BS") - call s:map("ToggleFileMode", "o") - call s:map("ToggleFileModeAndSearch", "O") - call s:map("ToggleBufferMode", "h") - call s:map("ToggleBufferModeAndSearch", "H") - call s:map("ToggleWorkspaceMode", "w") - call s:map("ToggleWorkspaceModeAndSearch", "W") - call s:map("ToggleTabMode", "l") - call s:map("ToggleTabModeAndSearch", "L") - call s:map("ToggleBookmarkMode", "b") - call s:map("ToggleBookmarkModeAndSearch", "B") +function! ctrlspace#keys#common#Init() abort + call s:map("ToggleHelp", "?") + call s:map("Down", "j") + call s:map("Up", "k") + call s:map("Previous", "p") + call s:map("PreviousCR", "P") + call s:map("Next", "n") + call s:map("MouseDown", "MouseDown") + call s:map("MouseUp", "MouseUp") + call s:map("LeftRelease", "LeftRelease") + call s:map("LeftMouse2", '2-LeftMouse') + call s:map("DownArrow", "Down") + call s:map("UpArrow", "Up") + call s:map("Home", "Home") + call s:map("Top", "K") + call s:map("End", "End") + call s:map("Bottom", "J") + call s:map("PageDown", "PageDown") + call s:map("ScrollDown", 'C-f') + call s:map("PageUp", "PageUp") + call s:map("ScrollUp", 'C-b') + call s:map("HalfScrollDown", 'C-d') + call s:map("HalfScrollUp", 'C-u') + call s:map("Close", "q", "Esc", 'C-c') + call s:map("Quit", "Q") + call s:map("EnterSearchMode", "/") + call s:map("RestorePreviousSearch", 'C-p') + call s:map("RestoreNextSearch", 'C-n') + call s:map("BackOrClearSearch", "BS") + call s:map("ToggleFileMode", "o") + call s:map("ToggleFileModeAndSearch", "O") + call s:map("ToggleBufferMode", "h") + call s:map("ToggleBufferModeAndSearch", "H") + call s:map("ToggleWorkspaceMode", "w") + call s:map("ToggleWorkspaceModeAndSearch", "W") + call s:map("ToggleTabMode", "l") + call s:map("ToggleTabModeAndSearch", "L") + call s:map("ToggleBookmarkMode", "b") + call s:map("ToggleBookmarkModeAndSearch", "B") - let keyMap = ctrlspace#keys#KeyMap() - let helpMap = ctrlspace#help#HelpMap() + call s:map("CountPrefix1", "1") + call s:map("CountPrefix2", "2") + call s:map("CountPrefix3", "3") + call s:map("CountPrefix4", "4") + call s:map("CountPrefix5", "5") + call s:map("CountPrefix6", "6") + call s:map("CountPrefix7", "7") + call s:map("CountPrefix8", "8") + call s:map("CountPrefix9", "9") - for m in ["Buffer", "File", "Tab", "Workspace", "Bookmark"] - call extend(keyMap[m], s:commonMap) - call extend(helpMap[m], s:helpMap) - endfor + let keyMap = ctrlspace#keys#KeyMap() + let helpMap = ctrlspace#help#HelpMap() + + for m in ["Buffer", "File", "Tab", "Workspace", "Bookmark"] + call extend(keyMap[m], s:commonMap) + call extend(helpMap[m], s:helpMap) + endfor endfunction -function! s:map(func, ...) - let fn = "ctrlspace#keys#common#" . a:func - let Ref = function(fn) +function! s:map(func, ...) abort + let fn = "ctrlspace#keys#common#" . a:func + let Ref = function(fn) - for k in a:000 - let s:helpMap[k] = fn - let s:commonMap[k] = Ref - endfor + for k in a:000 + let s:helpMap[k] = fn + let s:commonMap[k] = Ref + endfor endfunction -function! ctrlspace#keys#common#EnterSearchMode(k) - call ctrlspace#search#SwitchSearchMode(1) +function! ctrlspace#keys#common#EnterSearchMode(k) abort + call ctrlspace#search#SwitchSearchMode(1) endfunction -function! ctrlspace#keys#common#RestorePreviousSearch(k) - call ctrlspace#search#RestoreSearchLetters("previous") +function! ctrlspace#keys#common#RestorePreviousSearch(k) abort + call ctrlspace#search#RestoreSearchLetters("previous") endfunction -function! ctrlspace#keys#common#RestoreNextSearch(k) - call ctrlspace#search#RestoreSearchLetters("next") +function! ctrlspace#keys#common#RestoreNextSearch(k) abort + call ctrlspace#search#RestoreSearchLetters("next") endfunction -function! ctrlspace#keys#common#ToggleHelp(k) - call ctrlspace#window#Kill(0, 0) +function! ctrlspace#keys#common#ToggleHelp(k) abort + call ctrlspace#window#Kill(0, 0) - if s:modes.Help.Enabled - call s:modes.Help.Disable() - else - call s:modes.Help.Enable() - endif + if s:modes.Help.Enabled + call s:modes.Help.Disable() + else + call s:modes.Help.Enable() + endif - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#keys#common#Up(k) - call ctrlspace#window#MoveSelectionBar("up") +function! ctrlspace#keys#common#Up(k) abort + call ctrlspace#window#MoveSelectionBar("up") endfunction -function! ctrlspace#keys#common#Down(k) - call ctrlspace#window#MoveSelectionBar("down") +function! ctrlspace#keys#common#Down(k) abort + call ctrlspace#window#MoveSelectionBar("down") endfunction -function! ctrlspace#keys#common#Previous(k) - call ctrlspace#jumps#Jump("previous") +function! ctrlspace#keys#common#Previous(k) abort + call ctrlspace#jumps#Jump("previous") endfunction -function! ctrlspace#keys#common#PreviousCR(k) - call ctrlspace#jumps#Jump("previous") - call feedkeys("\ ") +function! ctrlspace#keys#common#PreviousCR(k) abort + call ctrlspace#jumps#Jump("previous") + call feedkeys("\ ") endfunction -function! ctrlspace#keys#common#Next(k) - call ctrlspace#jumps#Jump("next") +function! ctrlspace#keys#common#Next(k) abort + call ctrlspace#jumps#Jump("next") endfunction -function! ctrlspace#keys#common#MouseUp(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("down") - endif +function! ctrlspace#keys#common#MouseUp(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("down") + endif endfunction -function! ctrlspace#keys#common#MouseDown(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("up") - endif +function! ctrlspace#keys#common#MouseDown(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("up") + endif endfunction -function! ctrlspace#keys#common#LeftRelease(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("mouse") - endif +function! ctrlspace#keys#common#LeftRelease(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("mouse") + endif endfunction -function! ctrlspace#keys#common#LeftMouse2(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("mouse") - call feedkeys("\ ") - endif +function! ctrlspace#keys#common#LeftMouse2(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("mouse") + call feedkeys("\ ") + endif endfunction -function! ctrlspace#keys#common#DownArrow(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("down") - endif +function! ctrlspace#keys#common#DownArrow(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("down") + endif endfunction -function! ctrlspace#keys#common#UpArrow(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("up") - endif +function! ctrlspace#keys#common#UpArrow(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("up") + endif endfunction -function! ctrlspace#keys#common#Home(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar(1) - endif +function! ctrlspace#keys#common#Home(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar(1) + endif endfunction -function! ctrlspace#keys#common#Top(k) - call ctrlspace#window#MoveSelectionBar(1) +function! ctrlspace#keys#common#Top(k) abort + call ctrlspace#window#MoveSelectionBar(1) endfunction -function! ctrlspace#keys#common#End(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar(line("$")) - endif +function! ctrlspace#keys#common#End(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar(line("$")) + endif endfunction -function! ctrlspace#keys#common#Bottom(k) - call ctrlspace#window#MoveSelectionBar(line("$")) +function! ctrlspace#keys#common#Bottom(k) abort + call ctrlspace#window#MoveSelectionBar(line("$")) endfunction -function! ctrlspace#keys#common#PageDown(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("pgdown") - endif +function! ctrlspace#keys#common#PageDown(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("pgdown") + endif endfunction -function! ctrlspace#keys#common#ScrollDown(k) - call ctrlspace#window#MoveSelectionBar("pgdown") +function! ctrlspace#keys#common#ScrollDown(k) abort + call ctrlspace#window#MoveSelectionBar("pgdown") endfunction -function! ctrlspace#keys#common#PageUp(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveSelectionBar("pgup") - endif +function! ctrlspace#keys#common#PageUp(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveSelectionBar("pgup") + endif endfunction -function! ctrlspace#keys#common#ScrollUp(k) - call ctrlspace#window#MoveSelectionBar("pgup") +function! ctrlspace#keys#common#ScrollUp(k) abort + call ctrlspace#window#MoveSelectionBar("pgup") endfunction -function! ctrlspace#keys#common#HalfScrollDown(k) - call ctrlspace#window#MoveSelectionBar("half_pgdown") +function! ctrlspace#keys#common#HalfScrollDown(k) abort + call ctrlspace#window#MoveSelectionBar("half_pgdown") endfunction -function! ctrlspace#keys#common#HalfScrollUp(k) - call ctrlspace#window#MoveSelectionBar("half_pgup") +function! ctrlspace#keys#common#HalfScrollUp(k) abort + call ctrlspace#window#MoveSelectionBar("half_pgup") endfunction -function! ctrlspace#keys#common#Close(k) - call ctrlspace#window#Kill(0, 1) +function! ctrlspace#keys#common#Close(k) abort + call ctrlspace#window#Kill(0, 1) endfunction -function! ctrlspace#keys#common#Quit(k) - call ctrlspace#window#QuitVim() +function! ctrlspace#keys#common#Quit(k) abort + call ctrlspace#window#QuitVim() endfunction -function! s:toggleListViewAndSearch(k, mode) - if !s:modes[a:mode].Enabled - if !function("ctrlspace#keys#common#Toggle" . a:mode . "Mode")(a:k) - return 0 - endif - endif +function! s:toggleListViewAndSearch(k, mode) abort + if !s:modes[a:mode].Enabled + if !function("ctrlspace#keys#common#Toggle" . a:mode . "Mode")(a:k) + return 0 + endif + endif - call ctrlspace#search#SwitchSearchMode(1) - return 1 + call ctrlspace#search#SwitchSearchMode(1) + return 1 endfunction -function! s:toggleListView(k, mode) - " TODO Temporary place - if s:modes.Workspace.Enabled - call s:modes.Workspace.SetData("LastBrowsed", line(".")) - endif +function! s:toggleListView(k, mode) abort + " TODO Temporary place + if s:modes.Workspace.Enabled + call s:modes.Workspace.SetData("LastBrowsed", line(".")) + endif - if s:modes[a:mode].Enabled - if s:lastListView ==# a:mode - return 0 - else - return function("ctrlspace#keys#common#Toggle" . s:lastListView . "Mode")(a:k) - endif - endif + if s:modes[a:mode].Enabled + if s:lastListView ==# a:mode + return 0 + else + return function("ctrlspace#keys#common#Toggle" . s:lastListView . "Mode")(a:k) + endif + endif - let s:lastListView = ctrlspace#modes#CurrentListView().Name + let s:lastListView = ctrlspace#modes#CurrentListView().Name - call ctrlspace#window#Kill(0, 0) - call s:modes[a:mode].Enable() - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Kill(0, 0) + call s:modes[a:mode].Enable() + call ctrlspace#window#Toggle(1) - return 1 + return 1 endfunction -function! ctrlspace#keys#common#BackOrClearSearch(k) - if !empty(s:modes.Search.Data.Letters) - call ctrlspace#search#ClearSearchMode() - elseif !empty(s:lastListView) - if ctrlspace#modes#CurrentListView().Name ==# s:lastListView - return 0 - else - return function("ctrlspace#keys#common#Toggle" . s:lastListView . "Mode")(a:k) - endif - endif +function! ctrlspace#keys#common#BackOrClearSearch(k) abort + if !empty(s:modes.Search.Data.Letters) + call ctrlspace#search#ClearSearchMode() + elseif !empty(s:lastListView) + if ctrlspace#modes#CurrentListView().Name ==# s:lastListView + return 0 + else + return function("ctrlspace#keys#common#Toggle" . s:lastListView . "Mode")(a:k) + endif + endif endfunction -function! ctrlspace#keys#common#ToggleFileModeAndSearch(k) - return s:toggleListViewAndSearch(a:k, "File") +function! ctrlspace#keys#common#ToggleFileModeAndSearch(k) abort + return s:toggleListViewAndSearch(a:k, "File") endfunction -function! ctrlspace#keys#common#ToggleFileMode(k) - if !ctrlspace#roots#ProjectRootFound() - return 0 - endif +function! ctrlspace#keys#common#ToggleFileMode(k) abort + if !ctrlspace#roots#ProjectRootFound() + return 0 + endif + + return s:toggleListView(a:k, "File") +endfunction + +function! ctrlspace#keys#common#ToggleBufferModeAndSearch(k) abort + return s:toggleListViewAndSearch(a:k, "Buffer") +endfunction - return s:toggleListView(a:k, "File") +function! ctrlspace#keys#common#ToggleBufferMode(k) abort + return s:toggleListView(a:k, "Buffer") endfunction -function! ctrlspace#keys#common#ToggleBufferModeAndSearch(k) - return s:toggleListViewAndSearch(a:k, "Buffer") +function! ctrlspace#keys#common#ToggleWorkspaceModeAndSearch(k) abort + return s:toggleListViewAndSearch(a:k, "Workspace") endfunction -function! ctrlspace#keys#common#ToggleBufferMode(k) - return s:toggleListView(a:k, "Buffer") +function! ctrlspace#keys#common#ToggleWorkspaceMode(k) abort + if empty(ctrlspace#workspaces#Workspaces()) + return s:saveFirstWorkspace() + else + return s:toggleListView(a:k, "Workspace") + endif endfunction -function! ctrlspace#keys#common#ToggleWorkspaceModeAndSearch(k) - return s:toggleListViewAndSearch(a:k, "Workspace") +function! ctrlspace#keys#common#ToggleTabModeAndSearch(k) abort + return s:toggleListViewAndSearch(a:k, "Tab") endfunction -function! ctrlspace#keys#common#ToggleWorkspaceMode(k) - if empty(ctrlspace#workspaces#Workspaces()) - return s:saveFirstWorkspace() - else - return s:toggleListView(a:k, "Workspace") - endif +function! ctrlspace#keys#common#ToggleTabMode(k) abort + return s:toggleListView(a:k, "Tab") endfunction -function! ctrlspace#keys#common#ToggleTabModeAndSearch(k) - return s:toggleListViewAndSearch(a:k, "Tab") +function! ctrlspace#keys#common#ToggleBookmarkModeAndSearch(k) abort + return s:toggleListViewAndSearch(a:k, "Bookmark") endfunction -function! ctrlspace#keys#common#ToggleTabMode(k) - return s:toggleListView(a:k, "Tab") +function! ctrlspace#keys#common#CountPrefix1(k) abort + return s:CountPrefix(1) +endfunction +function! ctrlspace#keys#common#CountPrefix2(k) abort + return s:CountPrefix(2) +endfunction +function! ctrlspace#keys#common#CountPrefix3(k) abort + return s:CountPrefix(3) +endfunction +function! ctrlspace#keys#common#CountPrefix4(k) abort + return s:CountPrefix(4) +endfunction +function! ctrlspace#keys#common#CountPrefix5(k) abort + return s:CountPrefix(5) endfunction +function! ctrlspace#keys#common#CountPrefix6(k) abort + return s:CountPrefix(6) +endfunction +function! ctrlspace#keys#common#CountPrefix7(k) abort + return s:CountPrefix(7) +endfunction +function! ctrlspace#keys#common#CountPrefix8(k) abort + return s:CountPrefix(8) +endfunction +function! ctrlspace#keys#common#CountPrefix9(k) abort + return s:CountPrefix(9) +endfunction + +function! s:CountPrefix(initial_digit) abort + let digitString = '' . a:initial_digit + let nonDigitChar = '' + + while 1 + let char = nr2char(getchar()) + + if char =~# '[0-9]' + let digitString .= char + else + let nonDigitChar = char + break + endif + endwhile + + let l:number = str2nr(digitString) -function! ctrlspace#keys#common#ToggleBookmarkModeAndSearch(k) - return s:toggleListViewAndSearch(a:k, "Bookmark") + " Check if the input character is either k or j + if nonDigitChar =~# 'j' + let l:count = 0 + while l:count < l:number + call ctrlspace#window#MoveSelectionBar('down') + let l:count += 1 + endwhile + elseif nonDigitChar =~# 'k' + let l:count = 0 + while l:count < l:number + call ctrlspace#window#MoveSelectionBar('up') + let l:count += 1 + endwhile + " If the input character is not k or j, print warning + else + echo 'Only "j" and "k" accept counts!' + endif + return 1 endfunction -function! ctrlspace#keys#common#ToggleBookmarkMode(k) - if empty(ctrlspace#bookmarks#Bookmarks()) - call ctrlspace#bookmarks#AddFirstBookmark() - return 0 - else - return s:toggleListView(a:k, "Bookmark") - endif +function! ctrlspace#keys#common#ToggleBookmarkMode(k) abort + if empty(ctrlspace#bookmarks#Bookmarks()) + call ctrlspace#bookmarks#AddFirstBookmark() + return 0 + else + return s:toggleListView(a:k, "Bookmark") + endif endfunction -function! s:saveFirstWorkspace() - let labels = [] +function! s:saveFirstWorkspace() abort + let labels = [] - for t in range(1, tabpagenr("$")) - let label = ctrlspace#util#Gettabvar(t, "CtrlSpaceLabel") - if !empty(label) - call add(labels, label) - endif - endfor + for t in range(1, tabpagenr("$")) + let label = ctrlspace#util#Gettabvar(t, "CtrlSpaceLabel") + if !empty(label) + call add(labels, label) + endif + endfor - let name = ctrlspace#ui#GetInput("Save first workspace as: ", join(labels, " ")) + let name = ctrlspace#ui#GetInput("Save first workspace as: ", join(labels, " ")) - if empty(name) - return 0 - endif + if empty(name) + return 0 + endif - let lv = ctrlspace#modes#CurrentListView() + let lv = ctrlspace#modes#CurrentListView() - call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Kill(0, 1) - let ok = ctrlspace#workspaces#SaveWorkspace(name) + let ok = ctrlspace#workspaces#SaveWorkspace(name) - call ctrlspace#window#Toggle(0) + call ctrlspace#window#Toggle(0) - if ok - let lv = s:modes.Workspace - elseif lv.Name ==# "Buffer" - return 0 - endif + if ok + let lv = s:modes.Workspace + elseif lv.Name ==# "Buffer" + return 0 + endif - call ctrlspace#window#Kill(0, 0) - call lv.Enable() - call ctrlspace#window#Toggle(1) - call ctrlspace#ui#DelayedMsg() + call ctrlspace#window#Kill(0, 0) + call lv.Enable() + call ctrlspace#window#Toggle(1) + call ctrlspace#ui#DelayedMsg() - return ok + return ok endfunction diff --git a/autoload/ctrlspace/keys/file.vim b/autoload/ctrlspace/keys/file.vim index a50ed966..6623f7ea 100644 --- a/autoload/ctrlspace/keys/file.vim +++ b/autoload/ctrlspace/keys/file.vim @@ -1,122 +1,122 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#file#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#SearchParentDirectory", "File", ["BSlash", "Bar"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#ZoomMode", "File", ["z"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFile", "File", ["CR"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFiles", "File", ["Space"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFileVS", "File", ["v"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesVS", "File", ["V"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFileSP", "File", ["s"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesSP", "File", ["S"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFileT", "File", ["t"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesT", "File", ["T"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesCT", "File", ["C-t"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewTabLabel", "File", ["="]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#RemoveTabLabel", "File", ["_"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#MoveTab", "File", ["+", "-"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SwitchTab", "File", ["[", "]"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#Refresh", "File", ["r"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseTab", "File", ["C"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#EditFile", "File", ["e"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#ExploreDirectory", "File", ["E"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#GoToDirectory", "File", ["i", "I"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RemoveFile", "File", ["R"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RenameFileOrBuffer", "File", ["m"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#file#CopyFileOrBuffer", "File", ["y"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToBufferOrFile", "File", ["g", "G"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CollectUnsavedBuffers", "File", ["U"]) +function! ctrlspace#keys#file#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#SearchParentDirectory", "File", ["BSlash", "Bar"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#ZoomMode", "File", ["z"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFile", "File", ["CR"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFiles", "File", ["Space"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFileVS", "File", ["v"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesVS", "File", ["V"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFileSP", "File", ["s"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesSP", "File", ["S"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadFileT", "File", ["t"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesT", "File", ["T"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#LoadManyFilesCT", "File", ["C-t"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewTabLabel", "File", ["="]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#RemoveTabLabel", "File", ["_"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#MoveTab", "File", ["+", "-"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#SwitchTab", "File", ["[", "]"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#Refresh", "File", ["r"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CloseTab", "File", ["C"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#EditFile", "File", ["e"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#ExploreDirectory", "File", ["E"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#GoToDirectory", "File", ["i", "I"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RemoveFile", "File", ["R"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#RenameFileOrBuffer", "File", ["m"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#file#CopyFileOrBuffer", "File", ["y"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#GoToBufferOrFile", "File", ["g", "G"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#CollectUnsavedBuffers", "File", ["U"]) endfunction -function! ctrlspace#keys#file#SearchParentDirectory(k) - call ctrlspace#search#SearchParentDirectoryCycle() +function! ctrlspace#keys#file#SearchParentDirectory(k) abort + call ctrlspace#search#SearchParentDirectoryCycle() endfunction -function! ctrlspace#keys#file#ZoomMode(k) - if !s:modes.Zoom.Enabled - call ctrlspace#files#ZoomFile() - else - call ctrlspace#window#Kill(0, 1) - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - if s:modes.Zoom.Data.Mode ==# "File" - call s:modes.File.Enable() - else - call s:modes.Buffer.SetData("SubMode", s:modes.Zoom.Data.SubMode) - endif - call s:modes.Search.SetData("Letters", copy(s:modes.Zoom.Data.Letters)) - call ctrlspace#window#Toggle(1) - call ctrlspace#window#MoveSelectionBar(s:modes.Zoom.Data.Line) - endif +function! ctrlspace#keys#file#ZoomMode(k) abort + if !s:modes.Zoom.Enabled + call ctrlspace#files#ZoomFile() + else + call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + if s:modes.Zoom.Data.Mode ==# "File" + call s:modes.File.Enable() + else + call s:modes.Buffer.SetData("SubMode", s:modes.Zoom.Data.SubMode) + endif + call s:modes.Search.SetData("Letters", copy(s:modes.Zoom.Data.Letters)) + call ctrlspace#window#Toggle(1) + call ctrlspace#window#MoveSelectionBar(s:modes.Zoom.Data.Line) + endif endfunction -function! ctrlspace#keys#file#LoadFile(k) - call ctrlspace#files#LoadFile() +function! ctrlspace#keys#file#LoadFile(k) abort + call ctrlspace#files#LoadFile() endfunction -function! ctrlspace#keys#file#LoadManyFiles(k) - call ctrlspace#files#LoadManyFiles() +function! ctrlspace#keys#file#LoadManyFiles(k) abort + call ctrlspace#files#LoadManyFiles() endfunction -function! ctrlspace#keys#file#LoadFileVS(k) - call ctrlspace#files#LoadFile("vs") +function! ctrlspace#keys#file#LoadFileVS(k) abort + call ctrlspace#files#LoadFile("vs") endfunction -function! ctrlspace#keys#file#LoadManyFilesVS(k) - call ctrlspace#files#LoadManyFiles("vs") +function! ctrlspace#keys#file#LoadManyFilesVS(k) abort + call ctrlspace#files#LoadManyFiles("vs") endfunction -function! ctrlspace#keys#file#LoadFileSP(k) - call ctrlspace#files#LoadFile("sp") +function! ctrlspace#keys#file#LoadFileSP(k) abort + call ctrlspace#files#LoadFile("sp") endfunction -function! ctrlspace#keys#file#LoadManyFilesSP(k) - call ctrlspace#files#LoadManyFiles("sp") +function! ctrlspace#keys#file#LoadManyFilesSP(k) abort + call ctrlspace#files#LoadManyFiles("sp") endfunction -function! ctrlspace#keys#file#LoadFileT(k) - call ctrlspace#files#LoadFile("tabnew") +function! ctrlspace#keys#file#LoadFileT(k) abort + call ctrlspace#files#LoadFile("tabnew") endfunction -function! ctrlspace#keys#file#LoadManyFilesT(k) - if s:modes.NextTab.Enabled - call ctrlspace#files#LoadManyFiles("tabnext", "tabprevious") - else - call s:modes.NextTab.Enable() - call ctrlspace#files#LoadManyFiles("tabnew", "tabprevious") - endif +function! ctrlspace#keys#file#LoadManyFilesT(k) abort + if s:modes.NextTab.Enabled + call ctrlspace#files#LoadManyFiles("tabnext", "tabprevious") + else + call s:modes.NextTab.Enable() + call ctrlspace#files#LoadManyFiles("tabnew", "tabprevious") + endif endfunction -function! ctrlspace#keys#file#LoadManyFilesCT(k) - call s:modes.NextTab.Enable() - call ctrlspace#files#LoadManyFiles("tabnew", "tabprevious") +function! ctrlspace#keys#file#LoadManyFilesCT(k) abort + call s:modes.NextTab.Enable() + call ctrlspace#files#LoadManyFiles("tabnew", "tabprevious") endfunction -function! ctrlspace#keys#file#Refresh(k) - call ctrlspace#files#RefreshFiles() +function! ctrlspace#keys#file#Refresh(k) abort + call ctrlspace#files#RefreshFiles() endfunction -function! ctrlspace#keys#file#EditFile(k) - call ctrlspace#files#EditFile() +function! ctrlspace#keys#file#EditFile(k) abort + call ctrlspace#files#EditFile() endfunction -function! ctrlspace#keys#file#ExploreDirectory(k) - call ctrlspace#files#ExploreDirectory() +function! ctrlspace#keys#file#ExploreDirectory(k) abort + call ctrlspace#files#ExploreDirectory() endfunction -function! ctrlspace#keys#file#GoToDirectory(k) - call ctrlspace#files#GoToDirectory(a:k ==# "I") +function! ctrlspace#keys#file#GoToDirectory(k) abort + call ctrlspace#files#GoToDirectory(a:k ==# "I") endfunction -function! ctrlspace#keys#file#RemoveFile(k) - call ctrlspace#files#RemoveFile() +function! ctrlspace#keys#file#RemoveFile(k) abort + call ctrlspace#files#RemoveFile() endfunction -function! ctrlspace#keys#file#RenameFileOrBuffer(k) - call ctrlspace#files#RenameFileOrBuffer() +function! ctrlspace#keys#file#RenameFileOrBuffer(k) abort + call ctrlspace#files#RenameFileOrBuffer() endfunction -function! ctrlspace#keys#file#CopyFileOrBuffer(k) - call ctrlspace#files#CopyFileOrBuffer() +function! ctrlspace#keys#file#CopyFileOrBuffer(k) abort + call ctrlspace#files#CopyFileOrBuffer() endfunction diff --git a/autoload/ctrlspace/keys/help.vim b/autoload/ctrlspace/keys/help.vim index d0250815..06aaa7cc 100644 --- a/autoload/ctrlspace/keys/help.vim +++ b/autoload/ctrlspace/keys/help.vim @@ -1,129 +1,129 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#help#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleHelp", "Help", ["BS", "?"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Close", "Help", ["q", "Esc", "C-c"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Quit", "Help", ["Q"]) +function! ctrlspace#keys#help#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleHelp", "Help", ["BS", "?"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Close", "Help", ["q", "Esc", "C-c"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Quit", "Help", ["Q"]) - call s:map("Down", "j") - call s:map("Up", "k") - call s:map("MouseDown", "MouseDown") - call s:map("MouseUp", "MouseUp") - call s:map("LeftRelease", "LeftRelease") - call s:map("LeftMouse2", '2-LeftMouse') - call s:map("DownArrow", "Down") - call s:map("UpArrow", "Up") - call s:map("Home", "Home") - call s:map("Top", "K") - call s:map("End", "End") - call s:map("Bottom", "J") - call s:map("PageDown", "PageDown") - call s:map("ScrollDown", 'C-f') - call s:map("PageUp", "PageUp") - call s:map("ScrollUp", 'C-b') - call s:map("HalfScrollDown", 'C-d') - call s:map("HalfScrollUp", 'C-u') - call s:map("OpenInNewWindow", "CR") + call s:map("Down", "j") + call s:map("Up", "k") + call s:map("MouseDown", "MouseDown") + call s:map("MouseUp", "MouseUp") + call s:map("LeftRelease", "LeftRelease") + call s:map("LeftMouse2", '2-LeftMouse') + call s:map("DownArrow", "Down") + call s:map("UpArrow", "Up") + call s:map("Home", "Home") + call s:map("Top", "K") + call s:map("End", "End") + call s:map("Bottom", "J") + call s:map("PageDown", "PageDown") + call s:map("ScrollDown", 'C-f') + call s:map("PageUp", "PageUp") + call s:map("ScrollUp", 'C-b') + call s:map("HalfScrollDown", 'C-d') + call s:map("HalfScrollUp", 'C-u') + call s:map("OpenInNewWindow", "CR") endfunction -function! s:map(fn, ...) - call ctrlspace#keys#AddMapping("ctrlspace#keys#help#" . a:fn, "Help", a:000) +function! s:map(fn, ...) abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#help#" . a:fn, "Help", a:000) endfunction -function! ctrlspace#keys#help#OpenInNewWindow(k) - call ctrlspace#help#OpenInNewWindow() +function! ctrlspace#keys#help#OpenInNewWindow(k) abort + call ctrlspace#help#OpenInNewWindow() endfunction -function! ctrlspace#keys#help#Up(k) - call ctrlspace#window#MoveCursor("up") +function! ctrlspace#keys#help#Up(k) abort + call ctrlspace#window#MoveCursor("up") endfunction -function! ctrlspace#keys#help#Down(k) - call ctrlspace#window#MoveCursor("down") +function! ctrlspace#keys#help#Down(k) abort + call ctrlspace#window#MoveCursor("down") endfunction -function! ctrlspace#keys#help#MouseUp(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("down") - endif +function! ctrlspace#keys#help#MouseUp(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("down") + endif endfunction -function! ctrlspace#keys#help#MouseDown(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("up") - endif +function! ctrlspace#keys#help#MouseDown(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("up") + endif endfunction -function! ctrlspace#keys#help#LeftRelease(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("mouse") - endif +function! ctrlspace#keys#help#LeftRelease(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("mouse") + endif endfunction -function! ctrlspace#keys#help#LeftMouse2(k) - if s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("mouse") - call feedkeys("\ ") - endif +function! ctrlspace#keys#help#LeftMouse2(k) abort + if s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("mouse") + call feedkeys("\ ") + endif endfunction -function! ctrlspace#keys#help#DownArrow(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("down") - endif +function! ctrlspace#keys#help#DownArrow(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("down") + endif endfunction -function! ctrlspace#keys#help#UpArrow(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("up") - endif +function! ctrlspace#keys#help#UpArrow(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("up") + endif endfunction -function! ctrlspace#keys#help#Home(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor(1) - endif +function! ctrlspace#keys#help#Home(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor(1) + endif endfunction -function! ctrlspace#keys#help#Top(k) - call ctrlspace#window#MoveCursor(1) +function! ctrlspace#keys#help#Top(k) abort + call ctrlspace#window#MoveCursor(1) endfunction -function! ctrlspace#keys#help#End(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor(line("$")) - endif +function! ctrlspace#keys#help#End(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor(line("$")) + endif endfunction -function! ctrlspace#keys#help#Bottom(k) - call ctrlspace#window#MoveCursor(line("$")) +function! ctrlspace#keys#help#Bottom(k) abort + call ctrlspace#window#MoveCursor(line("$")) endfunction -function! ctrlspace#keys#help#PageDown(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("pgdown") - endif +function! ctrlspace#keys#help#PageDown(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("pgdown") + endif endfunction -function! ctrlspace#keys#help#ScrollDown(k) - call ctrlspace#window#MoveCursor("pgdown") +function! ctrlspace#keys#help#ScrollDown(k) abort + call ctrlspace#window#MoveCursor("pgdown") endfunction -function! ctrlspace#keys#help#PageUp(k) - if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") - call ctrlspace#window#MoveCursor("pgup") - endif +function! ctrlspace#keys#help#PageUp(k) abort + if s:config.UseArrowsInTerm || s:config.UseMouseAndArrowsInTerm || has("gui_running") + call ctrlspace#window#MoveCursor("pgup") + endif endfunction -function! ctrlspace#keys#help#ScrollUp(k) - call ctrlspace#window#MoveCursor("pgup") +function! ctrlspace#keys#help#ScrollUp(k) abort + call ctrlspace#window#MoveCursor("pgup") endfunction -function! ctrlspace#keys#help#HalfScrollDown(k) - call ctrlspace#window#MoveCursor("half_pgdown") +function! ctrlspace#keys#help#HalfScrollDown(k) abort + call ctrlspace#window#MoveCursor("half_pgdown") endfunction -function! ctrlspace#keys#help#HalfScrollUp(k) - call ctrlspace#window#MoveCursor("half_pgup") +function! ctrlspace#keys#help#HalfScrollUp(k) abort + call ctrlspace#window#MoveCursor("half_pgup") endfunction diff --git a/autoload/ctrlspace/keys/nop.vim b/autoload/ctrlspace/keys/nop.vim index 9d9b71ea..fb4e1bf7 100644 --- a/autoload/ctrlspace/keys/nop.vim +++ b/autoload/ctrlspace/keys/nop.vim @@ -1,37 +1,68 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#nop#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleHelp", "Nop", ["?"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#BackOrClearSearch", "Nop", ["BS", 'C-h']) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#EnterSearchMode", "Nop", ["/"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleFileMode", "Nop", ["o"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleFileModeAndSearch", "Nop", ["O"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBufferMode", "Nop", ["h"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBufferModeAndSearch", "Nop", ["H"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleWorkspaceMode", "Nop", ["w"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleWorkspaceModeAndSearch", "Nop", ["W"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleTabMode", "Nop", ["l"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleTabModeAndSearch", "Nop", ["L"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBookmarkMode", "Nop", ["b"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBookmarkModeAndSearch", "Nop", ["B"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Close", "Nop", ["q", "Esc", 'C-c']) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Quit", "Nop", ["Q"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#RestorePreviousSearch", "Nop", ['C-p']) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#RestoreNextSearch", "Nop", ['C-n']) - call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewWorkspace", "Nop", ["N"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#nop#ToggleAllMode", "Nop", ["a"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#nop#ToggleAllModeAndSearch", "Nop", ["A"]) +function! ctrlspace#keys#nop#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleHelp", "Nop", ["?"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#BackOrClearSearch", "Nop", ["BS", 'C-h']) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#EnterSearchMode", "Nop", ["/"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleFileMode", "Nop", ["o"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleFileModeAndSearch", "Nop", ["O"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBufferMode", "Nop", ["h"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBufferModeAndSearch", "Nop", ["H"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleWorkspaceMode", "Nop", ["w"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleWorkspaceModeAndSearch", "Nop", ["W"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleTabMode", "Nop", ["l"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleTabModeAndSearch", "Nop", ["L"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBookmarkMode", "Nop", ["b"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleBookmarkModeAndSearch", "Nop", ["B"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Close", "Nop", ["q", "Esc", 'C-c']) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Quit", "Nop", ["Q"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#RestorePreviousSearch", "Nop", ['C-p']) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#RestoreNextSearch", "Nop", ['C-n']) + call ctrlspace#keys#AddMapping("ctrlspace#keys#buffer#NewWorkspace", "Nop", ["N"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#nop#ToggleAllMode", "Nop", ["a"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#nop#ToggleAllModeAndSearch", "Nop", ["A"]) endfunction -function! ctrlspace#keys#nop#ToggleAllMode(k) - if s:modes.Buffer.Enabled - call ctrlspace#keys#buffer#ToggleAllMode(a:k) - endif +function! ctrlspace#keys#nop#ToggleAllMode(k) abort + if s:modes.Buffer.Enabled + call ctrlspace#keys#buffer#ToggleAllMode(a:k) + endif endfunction -function! ctrlspace#keys#nop#ToggleAllModeAndSearch(k) - if s:modes.Buffer.Enabled - call ctrlspace#keys#buffer#ToggleAllModeAndSearch(a:k) - endif +function! ctrlspace#keys#nop#ToggleAllModeAndSearch(k) abort + if s:modes.Buffer.Enabled + call ctrlspace#keys#buffer#ToggleAllModeAndSearch(a:k) + endif +endfunction + + +" ----------------------------- +" Dbmdex: DouBle MoDe EXception +" ----------------------------- + +" Define keymappings for combined NOP+ mode inside the following Initiator, +" where is a ListView mode such as BUFFER, FILE, BOOKMARK, etc. +function! ctrlspace#keys#nop#DbmdexInit() abort abort + call s:AddDbmdexMapping("ctrlspace#keys#buffer#MoveTab", "Buffer", ["+", "-"]) + call s:AddDbmdexMapping("ctrlspace#keys#buffer#SwitchTab", "Buffer", ["[", "]"]) + call s:AddDbmdexMapping("ctrlspace#keys#file#Refresh", "File", ["r"]) +endfunction + +" Function used to add these Dbmdex mappings +" Its signature is the same as that of ctrlspace#keys#AddMapping +function! s:AddDbmdexMapping(actionName, excpMode, keys) abort abort + call ctrlspace#keys#AddMapping(function('ctrlspace#keys#nop#_ExecDbmdexAction', + \ [a:excpMode, a:actionName]), + \ "Nop", a:keys) +endfunction + +" Function that wraps the action normally available in , and makes it +" available when CtrlSpace is in the double-mode enabled state of NOP + +function! ctrlspace#keys#nop#_ExecDbmdexAction(excpMode, actionName, k) abort abort + if s:modes[a:excpMode].Enabled + call function(a:actionName)(a:k) + else + call ctrlspace#keys#Undefined(a:k) + endif endfunction diff --git a/autoload/ctrlspace/keys/search.vim b/autoload/ctrlspace/keys/search.vim index 5e55152c..835c9fcb 100644 --- a/autoload/ctrlspace/keys/search.vim +++ b/autoload/ctrlspace/keys/search.vim @@ -1,47 +1,47 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#search#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleHelp", "Search", ["?"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Close", "Search", ["Esc", 'C-c']) - call ctrlspace#keys#AddMapping("ctrlspace#keys#search#ClearOrRemoveLetter", "Search", ["BS", 'C-h']) - call ctrlspace#keys#AddMapping("ctrlspace#keys#search#SwitchOff", "Search", ["/", "CR"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#search#SwitchOffCR", "Search", ["Tab"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#search#SwitchOffSpace", "Search", ["Space"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#search#ClearLetters", "Search", ['C-u', 'C-w']) - call ctrlspace#keys#AddMapping("ctrlspace#keys#search#AddLetter", "Search", ["lowercase", "uppercase", "numbers"]) +function! ctrlspace#keys#search#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#ToggleHelp", "Search", ["?"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#common#Close", "Search", ["Esc", 'C-c']) + call ctrlspace#keys#AddMapping("ctrlspace#keys#search#ClearOrRemoveLetter", "Search", ["BS", 'C-h']) + call ctrlspace#keys#AddMapping("ctrlspace#keys#search#SwitchOff", "Search", ["/", "CR"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#search#SwitchOffCR", "Search", ["Tab"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#search#SwitchOffSpace", "Search", ["Space"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#search#ClearLetters", "Search", ['C-u', 'C-w']) + call ctrlspace#keys#AddMapping("ctrlspace#keys#search#AddLetter", "Search", ["lowercase", "uppercase", "numbers", "punctuation"]) endfunction -function! ctrlspace#keys#search#ClearOrRemoveLetter(k) - if empty(s:modes.Search.Data.Letters) - call ctrlspace#search#ClearSearchMode() - else - call ctrlspace#search#RemoveSearchLetter() - endif +function! ctrlspace#keys#search#ClearOrRemoveLetter(k) abort + if empty(s:modes.Search.Data.Letters) + call ctrlspace#search#ClearSearchMode() + else + call ctrlspace#search#RemoveSearchLetter() + endif endfunction -function! ctrlspace#keys#search#AddLetter(k) - call ctrlspace#search#AddSearchLetter(a:k) +function! ctrlspace#keys#search#AddLetter(k) abort + call ctrlspace#search#AddSearchLetter(a:k) endfunction -function! ctrlspace#keys#search#SwitchOff(k) - call ctrlspace#search#SwitchSearchMode(0) +function! ctrlspace#keys#search#SwitchOff(k) abort + call ctrlspace#search#SwitchSearchMode(0) endfunction -function! ctrlspace#keys#search#SwitchOffCR(k) - call ctrlspace#search#SwitchSearchMode(0) - if !s:modes.Nop.Enabled - call feedkeys("\ ") - endif +function! ctrlspace#keys#search#SwitchOffCR(k) abort + call ctrlspace#search#SwitchSearchMode(0) + if !s:modes.Nop.Enabled + call feedkeys("\ ") + endif endfunction -function! ctrlspace#keys#search#SwitchOffSpace(k) - call ctrlspace#search#SwitchSearchMode(0) - if !s:modes.Nop.Enabled - call feedkeys("\ ") - endif +function! ctrlspace#keys#search#SwitchOffSpace(k) abort + call ctrlspace#search#SwitchSearchMode(0) + if !s:modes.Nop.Enabled + call feedkeys("\ ") + endif endfunction -function! ctrlspace#keys#search#ClearLetters(k) - call ctrlspace#search#ClearSearchLetters() +function! ctrlspace#keys#search#ClearLetters(k) abort + call ctrlspace#search#ClearSearchLetters() endfunction diff --git a/autoload/ctrlspace/keys/tab.vim b/autoload/ctrlspace/keys/tab.vim index 913d17e1..d755db85 100644 --- a/autoload/ctrlspace/keys/tab.vim +++ b/autoload/ctrlspace/keys/tab.vim @@ -1,157 +1,148 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#tab#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#GoToTab", "Tab", ["Tab", "CR", "Space"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CloseTab", "Tab", ["c"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#AddTab", "Tab", ["t", "a"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CopyTab", "Tab", ["y"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#SwitchTab", "Tab", ["[", "]"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#MoveTab", "Tab", ["{", "}", "+", "-"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#NewTabLabel", "Tab", ["=", "m"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#RemoveTabLabel", "Tab", ["_"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CollectUnsavedBuffers", "Tab", ["u"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CollectForeignBuffers", "Tab", ["f"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#NewWorkspace", "Tab", ["N"]) +function! ctrlspace#keys#tab#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#GoToTab", "Tab", ["Tab", "CR", "Space"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CloseTab", "Tab", ["c"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#AddTab", "Tab", ["t", "a"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CopyTab", "Tab", ["y"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#SwitchTab", "Tab", ["[", "]"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#MoveTab", "Tab", ["{", "}", "+", "-"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#NewTabLabel", "Tab", ["=", "m"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#RemoveTabLabel", "Tab", ["_"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CollectUnsavedBuffers", "Tab", ["u"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#CollectForeignBuffers", "Tab", ["f"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#tab#NewWorkspace", "Tab", ["N"]) endfunction -function! ctrlspace#keys#tab#GoToTab(k) - let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#window#Kill(0, 1) - silent! exe "normal! " . nr . "gt" - - if a:k ==# "CR" - call ctrlspace#window#Toggle(0) - elseif a:k ==# "Space" - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) - endif +function! ctrlspace#keys#tab#GoToTab(k) abort + let nr = ctrlspace#window#SelectedIndex() + call ctrlspace#window#Kill(0, 1) + silent! exe "normal! " . nr . "gt" + + if a:k ==# "CR" + call ctrlspace#window#Toggle(0) + elseif a:k ==# "Space" + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) + endif endfunction -function! ctrlspace#keys#tab#CloseTab(k) - let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#window#Kill(0, 1) - silent! exe "normal! " . nr . "gt" - call ctrlspace#window#Toggle(0) - call ctrlspace#tabs#CloseTab() - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) +function! ctrlspace#keys#tab#CloseTab(k) abort + let nr = ctrlspace#window#SelectedIndex() + call ctrlspace#window#Kill(0, 1) + silent! exe "normal! " . nr . "gt" + call ctrlspace#window#Toggle(0) + call ctrlspace#tabs#CloseTab() + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#keys#tab#AddTab(k) - let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#window#Kill(0, 1) - silent! exe "normal! " . nr . "gt" - silent! exe "tabnew" - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) +function! ctrlspace#keys#tab#AddTab(k) abort + let nr = ctrlspace#window#SelectedIndex() + call ctrlspace#window#Kill(0, 1) + silent! exe "normal! " . nr . "gt" + silent! exe "tabnew" + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#keys#tab#CopyTab(k) - let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#window#Kill(0, 1) - silent! exe "normal! " . nr . "gt" +function! ctrlspace#keys#tab#CopyTab(k) abort + let nr = ctrlspace#window#SelectedIndex() + call ctrlspace#window#Kill(0, 1) + silent! exe "normal! " . nr . "gt" - let sourceLabel = exists("t:CtrlSpaceLabel") ? t:CtrlSpaceLabel : "" - let sourceList = copy(t:CtrlSpaceList) + let sourceLabel = exists("t:CtrlSpaceLabel") ? t:CtrlSpaceLabel : "" + let sourceList = copy(t:CtrlSpaceList) - silent! exe "tabnew" + silent! exe "tabnew" - let label = empty(sourceLabel) ? ("Copy of tab " . nr) : (sourceLabel . " (copy)") - call ctrlspace#tabs#SetTabLabel(tabpagenr(), label, 1) + let label = empty(sourceLabel) ? ("Copy of tab " . nr) : (sourceLabel . " (copy)") + call ctrlspace#tabs#SetTabLabel(tabpagenr(), label, 1) - let t:CtrlSpaceList = sourceList + let t:CtrlSpaceList = sourceList - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 1) - call ctrlspace#window#Toggle(0) - call ctrlspace#buffers#CloseBuffer() - call ctrlspace#jumps#Jump("previous") - call ctrlspace#buffers#LoadBuffer() - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Toggle(0) + call ctrlspace#buffers#CloseBuffer() + call ctrlspace#jumps#Jump("previous") + call ctrlspace#buffers#LoadBuffer() + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#keys#tab#SwitchTab(k) - call ctrlspace#window#MoveSelectionBar(tabpagenr()) - if a:k ==# "[" - call feedkeys("k\ ") - elseif a:k ==# "]" - call feedkeys("j\ ") - endif +function! ctrlspace#keys#tab#SwitchTab(k) abort + call ctrlspace#window#MoveSelectionBar(tabpagenr()) + let dir = {'[': 'BWD', ']': 'FWD'}[a:k] + call ctrlspace#changebuftab#Execute("SwitchTabInTabMode", dir) endfunction -function! ctrlspace#keys#tab#NewTabLabel(k) - let l = line(".") +function! ctrlspace#keys#tab#NewTabLabel(k) abort + let l = line(".") - if ctrlspace#tabs#NewTabLabel(ctrlspace#window#SelectedIndex()) - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) - call ctrlspace#window#MoveSelectionBar(l) - endif + if ctrlspace#tabs#NewTabLabel(ctrlspace#window#SelectedIndex()) + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) + call ctrlspace#window#MoveSelectionBar(l) + endif endfunction -function! ctrlspace#keys#tab#RemoveTabLabel(k) - let l = line(".") +function! ctrlspace#keys#tab#RemoveTabLabel(k) abort + let l = line(".") - if ctrlspace#tabs#RemoveTabLabel(ctrlspace#window#SelectedIndex()) - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) - redraw! + if ctrlspace#tabs#RemoveTabLabel(ctrlspace#window#SelectedIndex()) + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) + redraw! - call ctrlspace#window#MoveSelectionBar(l) - endif + call ctrlspace#window#MoveSelectionBar(l) + endif endfunction -function! ctrlspace#keys#tab#MoveTab(k) - let nr = ctrlspace#window#SelectedIndex() - call ctrlspace#window#Kill(0, 1) - silent! exe "normal! " . nr . "gt" - - let cmd = "tabm" - - if v:version < 704 - if (a:k ==# "+") || (a:k ==# "}") - let cmd .= tabpagenr() - elseif (a:k ==# "-") || (a:k ==# "{") - let cmd .= (tabpagenr() - 2) - endif - else - if (a:k ==# "+") || (a:k ==# "}") - let cmd .= "+1" - elseif (a:k ==# "-") || (a:k ==# "{") - let cmd .= "-1" - endif - endif - - silent! exe cmd - - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) +" this function is also used to move tabs in Buffer mode +function! ctrlspace#keys#tab#MoveHelper(k) abort + let dir = {'-': 'BWD', '+': 'FWD', '{': 'BWD', '}': 'FWD'}[a:k] + if v:version < 704 + " NOTE: the tabmove cmds used here are directly copied from the existing code, + " and are assumed to work for <704 on faith, as they don't work for newer vers. + call ctrlspace#changebuftab#Execute("MoveTabLegacy", dir) + else + call ctrlspace#changebuftab#Execute("MoveTab", dir) + endif endfunction -function! ctrlspace#keys#tab#CollectUnsavedBuffers(k) - call ctrlspace#tabs#CollectUnsavedBuffers() +function! ctrlspace#keys#tab#MoveTab(k) abort + let nr = ctrlspace#window#SelectedIndex() + call ctrlspace#window#Kill(0, 1) + silent! exe "normal! " . nr . "gt" + call ctrlspace#keys#tab#MoveHelper(a:k) + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#keys#tab#CollectForeignBuffers(k) - call ctrlspace#tabs#CollectForeignBuffers() +function! ctrlspace#keys#tab#CollectUnsavedBuffers(k) abort + call ctrlspace#tabs#CollectUnsavedBuffers() endfunction -function! ctrlspace#keys#tab#NewWorkspace(k) - if !ctrlspace#keys#buffer#NewWorkspace(a:k) - return - endif +function! ctrlspace#keys#tab#CollectForeignBuffers(k) abort + call ctrlspace#tabs#CollectForeignBuffers() +endfunction + +function! ctrlspace#keys#tab#NewWorkspace(k) abort + if !ctrlspace#keys#buffer#NewWorkspace(a:k) + return + endif - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) endfunction diff --git a/autoload/ctrlspace/keys/workspace.vim b/autoload/ctrlspace/keys/workspace.vim index d692414d..e249f60d 100644 --- a/autoload/ctrlspace/keys/workspace.vim +++ b/autoload/ctrlspace/keys/workspace.vim @@ -1,129 +1,129 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#keys#workspace#Init() - call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#LoadOrSave", "Workspace", ["Tab", "CR", "Space"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#Append", "Workspace", ["a"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#NewWorkspace", "Workspace", ["N"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#ToggleSubmode", "Workspace", ["s"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#Delete", "Workspace", ["d"]) - call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#Rename", "Workspace", ["=", "m"]) +function! ctrlspace#keys#workspace#Init() abort + call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#LoadOrSave", "Workspace", ["Tab", "CR", "Space"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#Append", "Workspace", ["a"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#NewWorkspace", "Workspace", ["N"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#ToggleSubmode", "Workspace", ["s"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#Delete", "Workspace", ["d"]) + call ctrlspace#keys#AddMapping("ctrlspace#keys#workspace#Rename", "Workspace", ["=", "m"]) endfunction -function! ctrlspace#keys#workspace#Delete(k) - call ctrlspace#workspaces#DeleteWorkspace(ctrlspace#workspaces#SelectedWorkspaceName()) - call ctrlspace#ui#DelayedMsg() +function! ctrlspace#keys#workspace#Delete(k) abort + call ctrlspace#workspaces#DeleteWorkspace(ctrlspace#workspaces#SelectedWorkspaceName()) + call ctrlspace#ui#DelayedMsg() endfunction -function! ctrlspace#keys#workspace#Rename(k) - call ctrlspace#workspaces#RenameWorkspace(ctrlspace#workspaces#SelectedWorkspaceName()) - call ctrlspace#ui#DelayedMsg() +function! ctrlspace#keys#workspace#Rename(k) abort + call ctrlspace#workspaces#RenameWorkspace(ctrlspace#workspaces#SelectedWorkspaceName()) + call ctrlspace#ui#DelayedMsg() endfunction -function! ctrlspace#keys#workspace#LoadOrSave(k) - if s:modes.Workspace.Data.SubMode ==# "load" - if !s:loadWorkspace(0, ctrlspace#workspaces#SelectedWorkspaceName()) - return - endif - elseif s:modes.Workspace.Data.SubMode ==# "save" - if !s:saveWorkspace(ctrlspace#workspaces#SelectedWorkspaceName()) - return - endif - endif - - if a:k ==# "CR" - call ctrlspace#window#Toggle(0) - call ctrlspace#ui#DelayedMsg() - elseif a:k ==# "Space" - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Workspace.Enable() - call ctrlspace#window#Toggle(1) - call ctrlspace#ui#DelayedMsg() - endif +function! ctrlspace#keys#workspace#LoadOrSave(k) abort + if s:modes.Workspace.Data.SubMode ==# "load" + if !s:loadWorkspace(0, ctrlspace#workspaces#SelectedWorkspaceName()) + return + endif + elseif s:modes.Workspace.Data.SubMode ==# "save" + if !s:saveWorkspace(ctrlspace#workspaces#SelectedWorkspaceName()) + return + endif + endif + + if a:k ==# "CR" + call ctrlspace#window#Toggle(0) + call ctrlspace#ui#DelayedMsg() + elseif a:k ==# "Space" + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Workspace.Enable() + call ctrlspace#window#Toggle(1) + call ctrlspace#ui#DelayedMsg() + endif endfunction -function! ctrlspace#keys#workspace#Append(k) - call s:loadWorkspace(1, ctrlspace#workspaces#SelectedWorkspaceName()) - call ctrlspace#ui#DelayedMsg() +function! ctrlspace#keys#workspace#Append(k) abort + call s:loadWorkspace(1, ctrlspace#workspaces#SelectedWorkspaceName()) + call ctrlspace#ui#DelayedMsg() endfunction -function! ctrlspace#keys#workspace#NewWorkspace(k) - if !ctrlspace#keys#buffer#NewWorkspace(a:k) - return - endif +function! ctrlspace#keys#workspace#NewWorkspace(k) abort + if !ctrlspace#keys#buffer#NewWorkspace(a:k) + return + endif - call ctrlspace#window#Kill(0, 0) - call s:modes.Workspace.Enable() - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Kill(0, 0) + call s:modes.Workspace.Enable() + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#keys#workspace#ToggleSubmode(k) - call s:modes.Workspace.SetData("LastBrowsed", line(".")) - call ctrlspace#window#Kill(0, 0) +function! ctrlspace#keys#workspace#ToggleSubmode(k) abort + call s:modes.Workspace.SetData("LastBrowsed", line(".")) + call ctrlspace#window#Kill(0, 0) - if s:modes.Workspace.Data.SubMode == "load" - call s:modes.Workspace.SetData("SubMode", "save") - else - call s:modes.Workspace.SetData("SubMode", "load") - endif + if s:modes.Workspace.Data.SubMode ==# "load" + call s:modes.Workspace.SetData("SubMode", "save") + else + call s:modes.Workspace.SetData("SubMode", "load") + endif - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Toggle(1) endfunction -function! s:saveWorkspace(name) - let name = ctrlspace#ui#GetInput("Save current workspace as: ", a:name) +function! s:saveWorkspace(name) abort + let name = ctrlspace#ui#GetInput("Save current workspace as: ", a:name) - if empty(name) - return 0 - endif + if empty(name) + return 0 + endif - call ctrlspace#window#Kill(0, 1) - return ctrlspace#workspaces#SaveWorkspace(name) + call ctrlspace#window#Kill(0, 1) + return ctrlspace#workspaces#SaveWorkspace(name) endfunction -function! s:loadWorkspace(bang, name) - let saveWorkspaceBefore = 0 - let active = ctrlspace#workspaces#ActiveWorkspace() - - if active.Status && !a:bang - let msg = "" - - if a:name ==# active.Name - let msg = "Reload current workspace: '" . a:name . "'?" - elseif active.Status == 2 - if s:config.SaveWorkspaceOnSwitch - let saveWorkspaceBefore = 1 - else - let msg = "Current workspace ('" . active.Name . "') not saved. Proceed anyway?" - endif - endif - - if !empty(msg) && !ctrlspace#ui#Confirmed(msg) - return 0 - endif - endif - - if !a:bang && !ctrlspace#ui#ProceedIfModified() - return 0 - endif - - call ctrlspace#window#Kill(0, 1) - - if saveWorkspaceBefore && !ctrlspace#workspaces#SaveWorkspace("") - return 0 - endif - - if !ctrlspace#workspaces#LoadWorkspace(a:bang, a:name) - return 0 - endif - - if a:bang - call ctrlspace#window#Toggle(0) - call s:modes.Workspace.Enable() - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) - endif - - return 1 +function! s:loadWorkspace(bang, name) abort + let saveWorkspaceBefore = 0 + let active = ctrlspace#workspaces#ActiveWorkspace() + + if active.Status && !a:bang + let msg = "" + + if a:name ==# active.Name + let msg = "Reload current workspace: '" . a:name . "'?" + elseif active.Status == 2 + if s:config.SaveWorkspaceOnSwitch + let saveWorkspaceBefore = 1 + else + let msg = "Current workspace ('" . active.Name . "') not saved. Proceed anyway?" + endif + endif + + if !empty(msg) && !ctrlspace#ui#Confirmed(msg) + return 0 + endif + endif + + if !a:bang && !ctrlspace#ui#ProceedIfModified() + return 0 + endif + + call ctrlspace#window#Kill(0, 1) + + if saveWorkspaceBefore && !ctrlspace#workspaces#SaveWorkspace("") + return 0 + endif + + if !ctrlspace#workspaces#LoadWorkspace(a:bang, a:name) + return 0 + endif + + if a:bang + call ctrlspace#window#Toggle(0) + call s:modes.Workspace.Enable() + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) + endif + + return 1 endfunction diff --git a/autoload/ctrlspace/modes.vim b/autoload/ctrlspace/modes.vim index 0a01df46..7967aca3 100644 --- a/autoload/ctrlspace/modes.vim +++ b/autoload/ctrlspace/modes.vim @@ -4,97 +4,97 @@ let s:lists = [] let s:currentListView = {} let s:mode = { - \ "Name": "", - \ "Enabled": 0, - \ "Data": {}, - \ "ListView": 0 - \ } - -function! s:mode.new(name, listView, data) dict - let instance = copy(self) - let instance.Name = a:name - let instance.Data = a:data - let instance.ListView = a:listView - - let s:collection[a:name] = instance - - if a:listView - call add(s:lists, instance) - else - call add(s:noLists, instance) - endif - - return instance + \ "Name": "", + \ "Enabled": 0, + \ "Data": {}, + \ "ListView": 0 + \ } + +function! s:mode.new(name, listView, data) dict abort + let instance = copy(self) + let instance.Name = a:name + let instance.Data = a:data + let instance.ListView = a:listView + + let s:collection[a:name] = instance + + if a:listView + call add(s:lists, instance) + else + call add(s:noLists, instance) + endif + + return instance endfunction -function! s:mode.SetData(key, value) dict - let self.Data[a:key] = a:value - return a:value +function! s:mode.SetData(key, value) dict abort + let self.Data[a:key] = a:value + return a:value endfunction -function! s:mode.HasData(key) dict - return has_key(self.Data, a:key) +function! s:mode.HasData(key) dict abort + return has_key(self.Data, a:key) endfunction -function! s:mode.RemoveData(key) dict - if self.HasData(a:key) - call remove(self.Data, a:key) - return 1 - endif - return 0 +function! s:mode.RemoveData(key) dict abort + if self.HasData(a:key) + call remove(self.Data, a:key) + return 1 + endif + return 0 endfunction -function! s:mode.Enable() dict - if self.ListView - for m in s:lists - call m.Disable() - endfor +function! s:mode.Enable() dict abort + if self.ListView + for m in s:lists + call m.Disable() + endfor - let s:currentListView = self - endif + let s:currentListView = self + endif - let self.Enabled = 1 + let self.Enabled = 1 endfunction -function! s:mode.Disable() dict - let self.Enabled = 0 +function! s:mode.Disable() dict abort + let self.Enabled = 0 endfunction -function! s:init() - call s:mode.new("Zoom", 0, { "Buffer": 0, "Mode": "", "SubMode": "", "Line": "", "Letters": [] }) - call s:mode.new("NextTab", 0, {}) - call s:mode.new("Search", 0, { "Letters": [], "NewSearchPerformed": 0, "Restored": 0, "HistoryIndex": -1 }) - call s:mode.new("Help", 0, {}) - call s:mode.new("Nop", 0, {}) - call s:mode.new("Buffer", 1, { "SubMode": "single" }) - call s:mode.new("File", 1, {}) - call s:mode.new("Tab", 1, {}) - call s:mode.new("Workspace", 1, { "SubMode": "load", "Active": { "Name": "", "Digest": "", "Root": "" }, "LastActive": "", "LastBrowsed": 0 }) - call s:mode.new("Bookmark", 1, { "Active": {} }) +function! s:init() abort + call s:mode.new("Zoom", 0, { "Buffer": 0, "Mode": "", "SubMode": "", "Line": "", "Letters": [] }) + call s:mode.new("NextTab", 0, {}) + call s:mode.new("Search", 0, { "Letters": [], "NewSearchPerformed": 0, "Restored": 0, "HistoryIndex": -1 }) + call s:mode.new("Help", 0, {}) + call s:mode.new("Nop", 0, {}) + call s:mode.new("Buffer", 1, { "SubMode": "single" }) + call s:mode.new("File", 1, {}) + call s:mode.new("Tab", 1, {}) + call s:mode.new("Workspace", 1, { "SubMode": "load", "Active": { "Name": "", "Digest": "", "Root": "" }, "LastActive": "", "LastBrowsed": 0 }) + call s:mode.new("Bookmark", 1, { "Active": {} }) endfunction call s:init() -function! ctrlspace#modes#Modes() - return s:collection +function! ctrlspace#modes#Modes() abort + return s:collection endfunction -function! ctrlspace#modes#Enabled() - let result = [] +function! ctrlspace#modes#Enabled() abort + let result = [] - for m in values(s:collection) - if m.Enabled - call add(result, m) - endif - endfor + for m in values(s:collection) + if m.Enabled + call add(result, m) + endif + endfor - return result + return result endfunction -function! ctrlspace#modes#ListViews() - return s:lists +function! ctrlspace#modes#ListViews() abort + return s:lists endfunction -function! ctrlspace#modes#CurrentListView() - return s:currentListView +function! ctrlspace#modes#CurrentListView() abort + return s:currentListView endfunction diff --git a/autoload/ctrlspace/roots.vim b/autoload/ctrlspace/roots.vim index 646e21a1..898618f2 100644 --- a/autoload/ctrlspace/roots.vim +++ b/autoload/ctrlspace/roots.vim @@ -5,175 +5,175 @@ let s:projectRoots = {} let s:lastProjectRoot = "" let s:currentProjectRoot = "" -function! ctrlspace#roots#ProjectRoots() - return s:projectRoots +function! ctrlspace#roots#ProjectRoots() abort + return s:projectRoots endfunction -function! ctrlspace#roots#SetProjectRoots(value) - let s:projectRoots = a:value - return s:projectRoots +function! ctrlspace#roots#SetProjectRoots(value) abort + let s:projectRoots = a:value + return s:projectRoots endfunction -function! ctrlspace#roots#CurrentProjectRoot() - return s:currentProjectRoot +function! ctrlspace#roots#CurrentProjectRoot() abort + return s:currentProjectRoot endfunction -function! ctrlspace#roots#SetCurrentProjectRoot(value) - let s:currentProjectRoot = a:value - return s:currentProjectRoot +function! ctrlspace#roots#SetCurrentProjectRoot(value) abort + let s:currentProjectRoot = a:value + return s:currentProjectRoot endfunction -function! ctrlspace#roots#LastProjectRoot() - return s:lastProjectRoot +function! ctrlspace#roots#LastProjectRoot() abort + return s:lastProjectRoot endfunction -function! ctrlspace#roots#SetLastProjectRoot(value) - let s:lastProjectRoot = a:value - return s:lastProjectRoot +function! ctrlspace#roots#SetLastProjectRoot(value) abort + let s:lastProjectRoot = a:value + return s:lastProjectRoot endfunction -function! ctrlspace#roots#AddProjectRoot(directory) - let directory = ctrlspace#util#NormalizeDirectory(fnamemodify(empty(a:directory) ? getcwd() : a:directory, ":p")) +function! ctrlspace#roots#AddProjectRoot(directory) abort + let directory = ctrlspace#util#NormalizeDirectory(fnamemodify(empty(a:directory) ? getcwd() : a:directory, ":p")) - if !isdirectory(directory) - call ctrlspace#ui#Msg("Invalid directory: '" . directory . "'") - return - endif + if !isdirectory(directory) + call ctrlspace#ui#Msg("Invalid directory: '" . directory . "'") + return + endif - let roots = copy(s:projectRoots) + let roots = copy(s:projectRoots) - for bm in ctrlspace#bookmarks#Bookmarks() - let roots[bm.Directory] = 1 - endfor + for bm in ctrlspace#bookmarks#Bookmarks() + let roots[bm.Directory] = 1 + endfor - if exists("roots[directory]") - call ctrlspace#ui#Msg("Directory '" . directory . "' is already a permanent project root!") - return - endif + if exists("roots[directory]") + call ctrlspace#ui#Msg("Directory '" . directory . "' is already a permanent project root!") + return + endif - call s:addProjectRoot(directory) - call ctrlspace#ui#Msg("Directory '" . directory . "' has been added as a permanent project root.") + call s:addProjectRoot(directory) + call ctrlspace#ui#Msg("Directory '" . directory . "' has been added as a permanent project root.") endfunction -function! ctrlspace#roots#RemoveProjectRoot(directory) - let directory = ctrlspace#util#NormalizeDirectory(fnamemodify(empty(a:directory) ? getcwd() : a:directory, ":p")) +function! ctrlspace#roots#RemoveProjectRoot(directory) abort + let directory = ctrlspace#util#NormalizeDirectory(fnamemodify(empty(a:directory) ? getcwd() : a:directory, ":p")) - if !exists("s:projectRoots[directory]") - call ctrlspace#ui#Msg("Directory '" . directory . "' is not a permanent project root!" ) - return - endif + if !exists("s:projectRoots[directory]") + call ctrlspace#ui#Msg("Directory '" . directory . "' is not a permanent project root!" ) + return + endif - call s:removeProjectRoot(directory) - call ctrlspace#ui#Msg("Project root '" . directory . "' has been removed.") + call s:removeProjectRoot(directory) + call ctrlspace#ui#Msg("Project root '" . directory . "' has been removed.") endfunction -function! s:removeProjectRoot(directory) - let directory = ctrlspace#util#NormalizeDirectory(a:directory) +function! s:removeProjectRoot(directory) abort + let directory = ctrlspace#util#NormalizeDirectory(a:directory) - if exists("s:projectRoots[directory]") - unlet s:projectRoots[directory] - endif + if exists("s:projectRoots[directory]") + unlet s:projectRoots[directory] + endif - let lines = [] - let cacheFile = s:config.CacheDir . "/.cs_cache" + let lines = [] + let cacheFile = s:config.CacheDir . "/.cs_cache" - if filereadable(cacheFile) - for oldLine in readfile(cacheFile) - if oldLine !~# "CS_PROJECT_ROOT: " - call add(lines, oldLine) - endif - endfor - endif + if filereadable(cacheFile) + for oldLine in readfile(cacheFile) + if oldLine !~# "CS_PROJECT_ROOT: " + call add(lines, oldLine) + endif + endfor + endif - for root in keys(s:projectRoots) - call add(lines, "CS_PROJECT_ROOT: " . root) - endfor + for root in keys(s:projectRoots) + call add(lines, "CS_PROJECT_ROOT: " . root) + endfor - call writefile(lines, cacheFile) + call writefile(lines, cacheFile) endfunction -function! s:addProjectRoot(directory) - let directory = ctrlspace#util#NormalizeDirectory(a:directory) +function! s:addProjectRoot(directory) abort + let directory = ctrlspace#util#NormalizeDirectory(a:directory) - let s:projectRoots[directory] = 1 + let s:projectRoots[directory] = 1 - let lines = [] - let bmRoots = {} - let cacheFile = s:config.CacheDir . "/.cs_cache" + let lines = [] + let bmRoots = {} + let cacheFile = s:config.CacheDir . "/.cs_cache" - for bm in ctrlspace#bookmarks#Bookmarks() - let bmRoots[bm.Directory] = 1 - endfor + for bm in ctrlspace#bookmarks#Bookmarks() + let bmRoots[bm.Directory] = 1 + endfor - if filereadable(cacheFile) - for oldLine in readfile(cacheFile) - if oldLine !~# "CS_PROJECT_ROOT: " - call add(lines, oldLine) - endif - endfor - endif + if filereadable(cacheFile) + for oldLine in readfile(cacheFile) + if oldLine !~# "CS_PROJECT_ROOT: " + call add(lines, oldLine) + endif + endfor + endif - for root in keys(s:projectRoots) - if !exists("bmRoots[root]") - call add(lines, "CS_PROJECT_ROOT: " . root) - endif - endfor + for root in keys(s:projectRoots) + if !exists("bmRoots[root]") + call add(lines, "CS_PROJECT_ROOT: " . root) + endif + endfor - call writefile(lines, cacheFile) + call writefile(lines, cacheFile) endfunction -function! ctrlspace#roots#FindProjectRoot() - let projectRoot = fnamemodify(".", ":p:h") +function! ctrlspace#roots#FindProjectRoot() abort + let projectRoot = fnamemodify(".", ":p:h") - if !empty(s:config.ProjectRootMarkers) - let rootFound = 0 - let candidate = fnamemodify(projectRoot, ":p:h") - let lastCandidate = "" + if !empty(s:config.ProjectRootMarkers) + let rootFound = 0 + let candidate = fnamemodify(projectRoot, ":p:h") + let lastCandidate = "" - while candidate != lastCandidate - for marker in s:config.ProjectRootMarkers - let markerPath = candidate . "/" . marker - if filereadable(markerPath) || isdirectory(markerPath) - let rootFound = 1 - break - endif - endfor + while candidate != lastCandidate + for marker in s:config.ProjectRootMarkers + let markerPath = candidate . "/" . marker + if filereadable(markerPath) || isdirectory(markerPath) + let rootFound = 1 + break + endif + endfor - if !rootFound - let rootFound = exists("s:projectRoots[candidate]") - endif + if !rootFound + let rootFound = exists("s:projectRoots[candidate]") + endif - if rootFound - let projectRoot = candidate - break - endif + if rootFound + let projectRoot = candidate + break + endif - let lastCandidate = candidate - let candidate = fnamemodify(candidate, ":p:h:h") - endwhile + let lastCandidate = candidate + let candidate = fnamemodify(candidate, ":p:h:h") + endwhile - return rootFound ? projectRoot : "" - endif + return rootFound ? projectRoot : "" + endif - return projectRoot + return projectRoot endfunction -function! ctrlspace#roots#ProjectRootFound() - if empty(s:currentProjectRoot) - let s:currentProjectRoot = ctrlspace#roots#FindProjectRoot() - - if empty(s:currentProjectRoot) - let projectRoot = ctrlspace#ui#GetInput("No project root found. Set the project root: ", fnamemodify(".", ":p:h"), "dir") - - if !empty(projectRoot) && isdirectory(projectRoot) - call ctrlspace#files#ClearAll() " clear current files - force reload - call s:addProjectRoot(projectRoot) - let s:currentProjectRoot = projectRoot - else - call ctrlspace#ui#Msg("Cannot continue with the project root not set.") - return 0 - endif - endif - endif - return 1 +function! ctrlspace#roots#ProjectRootFound() abort + if empty(s:currentProjectRoot) + let s:currentProjectRoot = ctrlspace#roots#FindProjectRoot() + + if empty(s:currentProjectRoot) + let projectRoot = ctrlspace#ui#GetInput("No project root found. Set the project root: ", fnamemodify(".", ":p:h"), "dir") + + if !empty(projectRoot) && isdirectory(projectRoot) + call ctrlspace#files#ClearAll() " clear current files - force reload + call s:addProjectRoot(projectRoot) + let s:currentProjectRoot = projectRoot + else + call ctrlspace#ui#Msg("Cannot continue with the project root not set.") + return 0 + endif + endif + endif + return 1 endfunction diff --git a/autoload/ctrlspace/search.vim b/autoload/ctrlspace/search.vim index 0f2caafa..c452b6bb 100644 --- a/autoload/ctrlspace/search.vim +++ b/autoload/ctrlspace/search.vim @@ -2,196 +2,196 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() let s:updateSearchResults = 0 -function! ctrlspace#search#UpdateSearchResults() - if s:updateSearchResults - let s:updateSearchResults = 0 - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) - endif +function! ctrlspace#search#UpdateSearchResults() abort + if s:updateSearchResults + let s:updateSearchResults = 0 + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) + endif endfunction -function! ctrlspace#search#ClearSearchMode() - call s:modes.Search.Disable() - call s:modes.Search.SetData("Letters", []) +function! ctrlspace#search#ClearSearchMode() abort + call s:modes.Search.Disable() + call s:modes.Search.SetData("Letters", []) - call s:modes.Search.SetData("HistoryIndex", -1) - call s:modes.Search.RemoveData("LastSearchedDirectory") + call s:modes.Search.SetData("HistoryIndex", -1) + call s:modes.Search.RemoveData("LastSearchedDirectory") - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) endfunction -function! ctrlspace#search#AddSearchLetter(letter) - call add(s:modes.Search.Data.Letters, a:letter) - call s:modes.Search.SetData("NewSearchPerformed", 1) +function! ctrlspace#search#AddSearchLetter(letter) abort + call add(s:modes.Search.Data.Letters, a:letter) + call s:modes.Search.SetData("NewSearchPerformed", 1) - let s:updateSearchResults = 1 + let s:updateSearchResults = 1 - call s:modes.Search.RemoveData("LastSearchedDirectory") + call s:modes.Search.RemoveData("LastSearchedDirectory") - call ctrlspace#util#SetStatusline() - redraws + call ctrlspace#util#SetStatusline() + redraws endfunction -function! ctrlspace#search#RemoveSearchLetter() - call remove(s:modes.Search.Data.Letters, -1) - call s:modes.Search.SetData("NewSearchPerformed", 1) +function! ctrlspace#search#RemoveSearchLetter() abort + call remove(s:modes.Search.Data.Letters, -1) + call s:modes.Search.SetData("NewSearchPerformed", 1) - let s:updateSearchResults = 1 + let s:updateSearchResults = 1 - call s:modes.Search.RemoveData("LastSearchedDirectory") + call s:modes.Search.RemoveData("LastSearchedDirectory") - call ctrlspace#util#SetStatusline() - redraws + call ctrlspace#util#SetStatusline() + redraws endfunction -function! ctrlspace#search#ClearSearchLetters() - if !empty(s:modes.Search.Data.Letters) - call s:modes.Search.SetData("Letters", []) - call s:modes.Search.SetData("NewSearchPerformed", 1) +function! ctrlspace#search#ClearSearchLetters() abort + if !empty(s:modes.Search.Data.Letters) + call s:modes.Search.SetData("Letters", []) + call s:modes.Search.SetData("NewSearchPerformed", 1) - let s:updateSearchResults = 1 + let s:updateSearchResults = 1 - call s:modes.Search.RemoveData("LastSearchedDirectory") + call s:modes.Search.RemoveData("LastSearchedDirectory") - call ctrlspace#util#SetStatusline() - redraws - endif + call ctrlspace#util#SetStatusline() + redraws + endif endfunction -function! ctrlspace#search#SwitchSearchMode(switch) - if (a:switch == 0) && !empty(s:modes.Search.Data.Letters) - call ctrlspace#search#AppendToSearchHistory() - endif +function! ctrlspace#search#SwitchSearchMode(switch) abort + if (a:switch == 0) && !empty(s:modes.Search.Data.Letters) + call ctrlspace#search#AppendToSearchHistory() + endif - if a:switch - call s:modes.Search.Enable() - else - call s:modes.Search.Disable() - endif + if a:switch + call s:modes.Search.Enable() + else + call s:modes.Search.Disable() + endif - let s:updateSearchResults = 1 - call ctrlspace#search#UpdateSearchResults() + let s:updateSearchResults = 1 + call ctrlspace#search#UpdateSearchResults() endfunction -function! ctrlspace#search#InsertSearchText(text) - let letters = [] - - for i in range(strlen(a:text)) - if a:text[i] =~? "^[A-Z0-9]$" - call add(letters, a:text[i]) - endif - endfor - - if !empty(letters) - call s:modes.Search.SetData("Letters", letters) - call ctrlspace#search#AppendToSearchHistory() - call s:modes.Search.SetData("HistoryIndex", 0) - let s:updateSearchResults = 1 - call ctrlspace#search#UpdateSearchResults() - return 1 - endif - - return 0 +function! ctrlspace#search#InsertSearchText(text) abort + let letters = [] + + for i in range(strlen(a:text)) + if a:text[i] =~? "^[A-Z0-9]$" + call add(letters, a:text[i]) + endif + endfor + + if !empty(letters) + call s:modes.Search.SetData("Letters", letters) + call ctrlspace#search#AppendToSearchHistory() + call s:modes.Search.SetData("HistoryIndex", 0) + let s:updateSearchResults = 1 + call ctrlspace#search#UpdateSearchResults() + return 1 + endif + + return 0 endfunction -function! ctrlspace#search#SearchHistoryIndex() - if !s:modes.Search.HasData("HistoryIndex") - call s:modes.Search.SetData("HistoryIndex", -1) - endif +function! ctrlspace#search#SearchHistoryIndex() abort + if !s:modes.Search.HasData("HistoryIndex") + call s:modes.Search.SetData("HistoryIndex", -1) + endif - return s:modes.Search.Data.HistoryIndex + return s:modes.Search.Data.HistoryIndex endfunction -function! ctrlspace#search#AppendToSearchHistory() - if empty(s:modes.Search.Data.Letters) - return - endif +function! ctrlspace#search#AppendToSearchHistory() abort + if empty(s:modes.Search.Data.Letters) + return + endif - if !s:modes.Search.HasData("History") - call s:modes.Search.SetData("History", {}) - endif + if !s:modes.Search.HasData("History") + call s:modes.Search.SetData("History", {}) + endif - let s:modes.Search.Data.History[join(s:modes.Search.Data.Letters)] = ctrlspace#jumps#IncrementJumpCounter() + let s:modes.Search.Data.History[join(s:modes.Search.Data.Letters)] = ctrlspace#jumps#IncrementJumpCounter() endfunction -function! ctrlspace#search#RestoreSearchLetters(direction) - if !s:modes.Search.HasData("History") || empty(s:modes.Search.Data.History) - return - endif +function! ctrlspace#search#RestoreSearchLetters(direction) abort + if !s:modes.Search.HasData("History") || empty(s:modes.Search.Data.History) + return + endif - let historyEntries = [] + let historyEntries = [] - for [letters, counter] in items(s:modes.Search.Data.History) - call add(historyEntries, { "letters": letters, "counter": counter }) - endfor + for [letters, counter] in items(s:modes.Search.Data.History) + call add(historyEntries, { "letters": letters, "counter": counter }) + endfor - call sort(historyEntries, function("s:compareEntries")) + call sort(historyEntries, function("s:compareEntries")) - let historyIndex = ctrlspace#search#SearchHistoryIndex() + let historyIndex = ctrlspace#search#SearchHistoryIndex() - if a:direction == "previous" - let historyIndex += 1 + if a:direction == "previous" + let historyIndex += 1 - if historyIndex == len(historyEntries) - let historyIndex = len(historyEntries) - 1 - endif - elseif a:direction == "next" - let historyIndex -= 1 + if historyIndex == len(historyEntries) + let historyIndex = len(historyEntries) - 1 + endif + elseif a:direction == "next" + let historyIndex -= 1 - if historyIndex < -1 - let historyIndex = -1 - endif - endif + if historyIndex < -1 + let historyIndex = -1 + endif + endif - if historyIndex < 0 - call s:modes.Search.SetData("Letters", []) - else - call s:modes.Search.SetData("Letters", split(historyEntries[historyIndex]["letters"])) - call s:modes.Search.SetData("Restored", 1) - endif + if historyIndex < 0 + call s:modes.Search.SetData("Letters", []) + else + call s:modes.Search.SetData("Letters", split(historyEntries[historyIndex]["letters"])) + call s:modes.Search.SetData("Restored", 1) + endif - call s:modes.Search.SetData("HistoryIndex", historyIndex) + call s:modes.Search.SetData("HistoryIndex", historyIndex) - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) endfunction -function! s:compareEntries(a, b) - if a:a.counter > a:b.counter - return -1 - elseif a:a.counter < a:b.counter - return 1 - else - return 0 - endif +function! s:compareEntries(a, b) abort + if a:a.counter > a:b.counter + return -1 + elseif a:a.counter < a:b.counter + return 1 + else + return 0 + endif endfunction -function! s:getSelectedDirectory() - if s:modes.File.Enabled - let name = ctrlspace#files#SelectedFileName() - elseif s:modes.Buffer.Enabled - let name = ctrlspace#buffers#SelectedBufferName() - else - return "" - endif +function! s:getSelectedDirectory() abort + if s:modes.File.Enabled + let name = ctrlspace#files#SelectedFileName() + elseif s:modes.Buffer.Enabled + let name = ctrlspace#buffers#SelectedBufferName() + else + return "" + endif - return fnamemodify(name, ":h") + return fnamemodify(name, ":h") endfunction -function! ctrlspace#search#SearchParentDirectoryCycle() - let candidate = s:getSelectedDirectory() +function! ctrlspace#search#SearchParentDirectoryCycle() abort + let candidate = s:getSelectedDirectory() - if empty(candidate) - return 0 - endif + if empty(candidate) + return 0 + endif - if !s:modes.Search.HasData("LastSearchedDirectory") || s:modes.Search.Data.LastSearchedDirectory !=# candidate - call s:modes.Search.SetData("LastSearchedDirectory", candidate) - else - call s:modes.Search.SetData("LastSearchedDirectory", fnamemodify(s:modes.Search.Data.LastSearchedDirectory, ":h")) - endif + if !s:modes.Search.HasData("LastSearchedDirectory") || s:modes.Search.Data.LastSearchedDirectory !=# candidate + call s:modes.Search.SetData("LastSearchedDirectory", candidate) + else + call s:modes.Search.SetData("LastSearchedDirectory", fnamemodify(s:modes.Search.Data.LastSearchedDirectory, ":h")) + endif - call ctrlspace#search#InsertSearchText(s:modes.Search.Data.LastSearchedDirectory) - return 1 + call ctrlspace#search#InsertSearchText(s:modes.Search.Data.LastSearchedDirectory) + return 1 endfunction diff --git a/autoload/ctrlspace/tabs.vim b/autoload/ctrlspace/tabs.vim index 85b06a72..56124b65 100644 --- a/autoload/ctrlspace/tabs.vim +++ b/autoload/ctrlspace/tabs.vim @@ -1,122 +1,127 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#tabs#SetTabLabel(tabnr, label, auto) - call settabvar(a:tabnr, "CtrlSpaceLabel", a:label) - call settabvar(a:tabnr, "CtrlSpaceAutotab", a:auto) +function! ctrlspace#tabs#SetTabLabel(tabnr, label, auto) abort + call settabvar(a:tabnr, "CtrlSpaceLabel", a:label) + call settabvar(a:tabnr, "CtrlSpaceAutotab", a:auto) + if get(g:, 'loaded_airline', 0) + " Force Update of tabline in airline + call airline#extensions#tabline#ctrlspace#invalidate() + sil doautocmd TabEnter + endif endfunction -function! ctrlspace#tabs#NewTabLabel(tabnr) - let tabnr = a:tabnr > 0 ? a:tabnr : tabpagenr() - let label = ctrlspace#ui#GetInput("Label for tab " . tabnr . ": ", ctrlspace#util#Gettabvar(tabnr, "CtrlSpaceLabel")) - if empty(label) - return 0 - endif +function! ctrlspace#tabs#NewTabLabel(tabnr) abort + let tabnr = a:tabnr > 0 ? a:tabnr : tabpagenr() + let label = ctrlspace#ui#GetInput("Label for tab " . tabnr . ": ", ctrlspace#util#Gettabvar(tabnr, "CtrlSpaceLabel")) + if empty(label) + return 0 + endif - call ctrlspace#tabs#SetTabLabel(tabnr, label, 0) - return 1 + call ctrlspace#tabs#SetTabLabel(tabnr, label, 0) + return 1 endfunction -function! ctrlspace#tabs#RemoveTabLabel(tabnr) - let tabnr = a:tabnr > 0 ? a:tabnr : tabpagenr() +function! ctrlspace#tabs#RemoveTabLabel(tabnr) abort + let tabnr = a:tabnr > 0 ? a:tabnr : tabpagenr() - if empty(ctrlspace#util#Gettabvar(tabnr, "CtrlSpaceLabel")) - return 0 - endif + if empty(ctrlspace#util#Gettabvar(tabnr, "CtrlSpaceLabel")) + return 0 + endif - call ctrlspace#tabs#SetTabLabel(tabnr, "", 0) - return 1 + call ctrlspace#tabs#SetTabLabel(tabnr, "", 0) + return 1 endfunction -function! ctrlspace#tabs#CloseTab() - if tabpagenr("$") == 1 - return - endif +function! ctrlspace#tabs#CloseTab() abort + if tabpagenr("$") == 1 + return + endif - if exists("t:CtrlSpaceAutotab") && (t:CtrlSpaceAutotab != 0) - " do nothing - elseif exists("t:CtrlSpaceLabel") && !empty(t:CtrlSpaceLabel) - let bufCount = len(ctrlspace#buffers#Buffers(tabpagenr())) + if exists("t:CtrlSpaceAutotab") && (t:CtrlSpaceAutotab != 0) + " do nothing + elseif exists("t:CtrlSpaceLabel") && !empty(t:CtrlSpaceLabel) + let bufCount = len(ctrlspace#buffers#Buffers(tabpagenr())) - if (bufCount > 1) && !ctrlspace#ui#Confirmed("Close tab named '" . t:CtrlSpaceLabel . "' with " . bufCount . " buffers?") - return - endif - endif + if (bufCount > 1) && !ctrlspace#ui#Confirmed("Close tab named '" . t:CtrlSpaceLabel . "' with " . bufCount . " buffers?") + return + endif + endif - call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Kill(0, 1) - tabclose + tabclose - call ctrlspace#buffers#DeleteHiddenNonameBuffers(1) - call ctrlspace#buffers#DeleteForeignBuffers(1) + call ctrlspace#buffers#DeleteHiddenNonameBuffers(1) + call ctrlspace#buffers#DeleteForeignBuffers(1) - call ctrlspace#window#Toggle(0) + call ctrlspace#window#Toggle(0) endfunction -function! ctrlspace#tabs#CollectUnsavedBuffers() - let buffers = [] +function! ctrlspace#tabs#CollectUnsavedBuffers() abort + let buffers = [] - for i in range(1, bufnr("$")) - if getbufvar(i, "&modified") && getbufvar(i, "&buflisted") - call add(buffers, i) - endif - endfor + for i in range(1, bufnr("$")) + if getbufvar(i, "&modified") && getbufvar(i, "&buflisted") + call add(buffers, i) + endif + endfor - if empty(buffers) - call ctrlspace#ui#Msg("There are no unsaved buffers.") - return 0 - endif + if empty(buffers) + call ctrlspace#ui#Msg("There are no unsaved buffers.") + return 0 + endif - call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Kill(0, 1) - tabnew + tabnew - call ctrlspace#tabs#SetTabLabel(tabpagenr(), "Unsaved Buffers", 1) + call ctrlspace#tabs#SetTabLabel(tabpagenr(), "Unsaved Buffers", 1) - for b in buffers - silent! exe ":b " . b - endfor + for b in buffers + silent! exe ":b " . b + endfor - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) - return 1 + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) + return 1 endfunction -function! ctrlspace#tabs#CollectForeignBuffers() - let buffers = {} +function! ctrlspace#tabs#CollectForeignBuffers() abort + let buffers = {} - for t in range(1, tabpagenr("$")) - silent! call extend(buffers, ctrlspace#util#GettabvarWithDefault(t, "CtrlSpaceList", {})) - endfor + for t in range(1, tabpagenr("$")) + silent! call extend(buffers, ctrlspace#util#GettabvarWithDefault(t, "CtrlSpaceList", {})) + endfor - let foreignBuffers = [] + let foreignBuffers = [] - for b in keys(ctrlspace#buffers#Buffers(0)) - if !has_key(buffers, b) - call add(foreignBuffers, b) - endif - endfor + for b in keys(ctrlspace#buffers#Buffers(0)) + if !has_key(buffers, b) + call add(foreignBuffers, b) + endif + endfor - if empty(foreignBuffers) - call ctrlspace#ui#Msg("There are no foreign buffers.") - return 0 - endif + if empty(foreignBuffers) + call ctrlspace#ui#Msg("There are no foreign buffers.") + return 0 + endif - call ctrlspace#window#Kill(0, 1) + call ctrlspace#window#Kill(0, 1) - tabnew + tabnew - call ctrlspace#tabs#SetTabLabel(tabpagenr(), "Foreign Buffers", 1) + call ctrlspace#tabs#SetTabLabel(tabpagenr(), "Foreign Buffers", 1) - for fb in foreignBuffers - silent! exe ":b " . fb - endfor + for fb in foreignBuffers + silent! exe ":b " . fb + endfor - call ctrlspace#window#Toggle(0) - call ctrlspace#window#Kill(0, 0) - call s:modes.Tab.Enable() - call ctrlspace#window#Toggle(1) - return 1 + call ctrlspace#window#Toggle(0) + call ctrlspace#window#Kill(0, 0) + call s:modes.Tab.Enable() + call ctrlspace#window#Toggle(1) + return 1 endfunction diff --git a/autoload/ctrlspace/ui.vim b/autoload/ctrlspace/ui.vim index 533dbc79..09c59643 100644 --- a/autoload/ctrlspace/ui.vim +++ b/autoload/ctrlspace/ui.vim @@ -1,49 +1,49 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#ui#Msg(message) - echo s:config.Symbols.CS . " " . a:message +function! ctrlspace#ui#Msg(message) abort + echo s:config.Symbols.CS . " " . a:message endfunction -function! ctrlspace#ui#DelayedMsg(...) - if !empty(a:000) - let s:delayedMessage = a:1 - elseif exists("s:delayedMessage") && !empty(s:delayedMessage) - redraw - call ctrlspace#ui#Msg(s:delayedMessage) - unlet s:delayedMessage - endif +function! ctrlspace#ui#DelayedMsg(...) abort + if !empty(a:000) + let s:delayedMessage = a:1 + elseif exists("s:delayedMessage") && !empty(s:delayedMessage) + redraw + call ctrlspace#ui#Msg(s:delayedMessage) + unlet s:delayedMessage + endif endfunction -function! ctrlspace#ui#GetInput(msg, ...) - let msg = s:config.Symbols.CS . " " . a:msg +function! ctrlspace#ui#GetInput(msg, ...) abort + let msg = s:config.Symbols.CS . " " . a:msg - call inputsave() + call inputsave() - if a:0 >= 2 - let answer = input(msg, a:1, a:2) - elseif a:0 == 1 - let answer = input(msg, a:1) - else - let answer = input(msg) - endif + if a:0 >= 2 + let answer = input(msg, a:1, a:2) + elseif a:0 == 1 + let answer = input(msg, a:1) + else + let answer = input(msg) + endif - call inputrestore() - redraw! + call inputrestore() + redraw! - return answer + return answer endfunction -function! ctrlspace#ui#Confirmed(msg) - return ctrlspace#ui#GetInput(a:msg . " (yN): ") =~? "y" +function! ctrlspace#ui#Confirmed(msg) abort + return ctrlspace#ui#GetInput(a:msg . " (yN): ") =~? "y" endfunction -function! ctrlspace#ui#ProceedIfModified() - for i in range(1, bufnr("$")) - if getbufvar(i, "&modified") - return ctrlspace#ui#Confirmed("Some buffers not saved. Proceed anyway?") - endif - endfor +function! ctrlspace#ui#ProceedIfModified() abort + for i in range(1, bufnr("$")) + if getbufvar(i, "&modified") + return ctrlspace#ui#Confirmed("Some buffers not saved. Proceed anyway?") + endif + endfor - return 1 + return 1 endfunction diff --git a/autoload/ctrlspace/util.vim b/autoload/ctrlspace/util.vim index e11b60cb..e574caae 100644 --- a/autoload/ctrlspace/util.vim +++ b/autoload/ctrlspace/util.vim @@ -1,116 +1,148 @@ -let s:config = ctrlspace#context#Configuration() -let s:modes = ctrlspace#modes#Modes() +function! ctrlspace#util#system(cmd, ...) abort + if has('win32') && &shell !~? 'cmd' + let saved_shell = [ + \ &shell, + \ &shellcmdflag, + \ &shellxquote, + \ &shellxescape, + \ &shellquote, + \ &shellpipe, + \ &shellredir, + \ &shellslash + \] + set shell& shellcmdflag& shellxquote& shellxescape& + set shellquote& shellpipe& shellredir& shellslash& + endif + + let output = a:0 > 0 ? system(a:cmd, a:1) : system(a:cmd) + + if exists('saved_shell') + let [ &shell, + \ &shellcmdflag, + \ &shellxquote, + \ &shellxescape, + \ &shellquote, + \ &shellpipe, + \ &shellredir, + \ &shellslash ] = saved_shell + endif + + return has('win32') ? substitute(output, "\r", '', 'g') : output +endfunction -function! ctrlspace#util#NormalizeDirectory(directory) - let directory = resolve(expand(a:directory)) +function! ctrlspace#util#NormalizeDirectory(directory) abort + let directory = resolve(expand(a:directory)) - while directory[strlen(directory) - 1] == "/" || directory[strlen(directory) - 1] == "\\" - let directory = directory[0:-2] - endwhile + while directory[strlen(directory) - 1] ==# "/" || directory[strlen(directory) - 1] ==# "\\" + let directory = directory[0:-2] + endwhile - return directory + return directory endfunction -function! ctrlspace#util#HandleVimSettings(switch) - call s:handleSwitchbuf(a:switch) - call s:handleAutochdir(a:switch) +function! ctrlspace#util#HandleVimSettings(switch) abort + call s:handleSwitchbuf(a:switch) + call s:handleAutochdir(a:switch) endfunction -function! s:handleSwitchbuf(switch) - if (a:switch == "start") && !empty(&swb) - let s:swbSave = &swb - set swb= - elseif (a:switch == "stop") && exists("s:swbSave") - let &swb = s:swbSave - unlet s:swbSave - endif +function! s:handleSwitchbuf(switch) abort + if (a:switch ==# "start") && !empty(&swb) + let s:swbSave = &swb + set swb= + elseif (a:switch ==# "stop") && exists("s:swbSave") + let &swb = s:swbSave + unlet s:swbSave + endif endfunction -function! s:handleAutochdir(switch) - if (a:switch == "start") && &acd - let s:acdWasOn = 1 - set noacd - elseif (a:switch == "stop") && exists("s:acdWasOn") - set acd - unlet s:acdWasOn - endif +function! s:handleAutochdir(switch) abort + if (a:switch ==# "start") && &acd + let s:acdWasOn = 1 + set noacd + elseif (a:switch ==# "stop") && exists("s:acdWasOn") + set acd + unlet s:acdWasOn + endif endfunction -function! ctrlspace#util#WorkspaceFile() - return s:internalFilePath("cs_workspaces") +function! ctrlspace#util#WorkspaceFile() abort + let config = ctrlspace#context#Configuration() + return filereadable(config.WorkspaceFile) ? config.WorkspaceFile : s:internalFilePath("cs_workspaces") endfunction -function! ctrlspace#util#FilesCache() - return s:internalFilePath("cs_files") +function! ctrlspace#util#FilesCache() abort + return s:internalFilePath("cs_files") endfunction -function! ctrlspace#util#ChDir(dir) - let dir = fnameescape(a:dir) - let curtab = tabpagenr() - let curwin = winnr() +function! ctrlspace#util#ChDir(dir) abort + let dir = fnameescape(a:dir) + let curtab = tabpagenr() + let curwin = winnr() - silent! exe "cd " . dir + silent! exe "cd " . dir - for t in range(1, tabpagenr("$")) - silent! exe "noautocmd tabnext " . t + for t in range(1, tabpagenr("$")) + silent! exe "noautocmd tabnext " . t - for w in range(1, winnr("$")) - silent! exe "noautocmd " . w . "wincmd w" + for w in range(1, winnr("$")) + silent! exe "noautocmd " . w . "wincmd w" - if haslocaldir() - silent! exe "lcd " . dir - endif - endfor - endfor + if haslocaldir() + silent! exe "lcd " . dir + endif + endfor + endfor - silent! exe "noautocmd tabnext " . curtab - silent! exe "noautocmd " . curwin . "wincmd w" + silent! exe "noautocmd tabnext " . curtab + silent! exe "noautocmd " . curwin . "wincmd w" endfunction -function! s:internalFilePath(name) - let root = ctrlspace#roots#CurrentProjectRoot() - let fullPart = empty(root) ? "" : (root . "/") +function! s:internalFilePath(name) abort + let config = ctrlspace#context#Configuration() + let root = ctrlspace#roots#CurrentProjectRoot() + let fullPart = empty(root) ? "" : (root . "/") - if !empty(s:config.ProjectRootMarkers) - for candidate in s:config.ProjectRootMarkers - let candidatePath = fullPart . candidate + if !empty(config.ProjectRootMarkers) + for candidate in config.ProjectRootMarkers + let candidatePath = fullPart . candidate - if isdirectory(candidatePath) - return candidatePath . "/" . a:name - endif - endfor - endif + if isdirectory(candidatePath) + return candidatePath . "/" . a:name + endif + endfor + endif - return fullPart . "." . a:name + return fullPart . "." . a:name endfunction " Workaround for a Vim bug after :only and e.g. help window: " for the first time after :only gettabvar cannot properly ready any tab variable " More info: https://github.com/vim/vim/issues/394 " TODO Remove when decided to drop support for Vim 7.3 -function! ctrlspace#util#Gettabvar(nr, name) - let value = gettabvar(a:nr, a:name) +function! ctrlspace#util#Gettabvar(nr, name) abort + let value = gettabvar(a:nr, a:name) - if type(value) == 1 && empty(value) - unlet value - let value = gettabvar(a:nr, a:name) - endif + if type(value) == 1 && empty(value) + unlet value + let value = gettabvar(a:nr, a:name) + endif - return value + return value endfunction -function! ctrlspace#util#GettabvarWithDefault(nr, name, default) - let value = ctrlspace#util#Gettabvar(a:nr, a:name) - return type(value) == 1 && empty(value) ? a:default : value +function! ctrlspace#util#GettabvarWithDefault(nr, name, default) abort + let value = ctrlspace#util#Gettabvar(a:nr, a:name) + return type(value) == 1 && empty(value) ? a:default : value endfunction -function! ctrlspace#util#GetbufvarWithDefault(nr, name, default) - let value = getbufvar(a:nr, a:name) - return type(value) == 1 && empty(value) ? a:default : value +function! ctrlspace#util#GetbufvarWithDefault(nr, name, default) abort + let value = getbufvar(a:nr, a:name) + return type(value) == 1 && empty(value) ? a:default : value endfunction -function! ctrlspace#util#SetStatusline() - if has("statusline") - silent! exe "let &l:statusline = " . s:config.StatuslineFunction - endif +function! ctrlspace#util#SetStatusline() abort + if has("statusline") + let config = ctrlspace#context#Configuration() + silent! exe "let &l:statusline = " . config.StatuslineFunction + endif endfunction diff --git a/autoload/ctrlspace/window.vim b/autoload/ctrlspace/window.vim index 91605574..c663ed06 100644 --- a/autoload/ctrlspace/window.vim +++ b/autoload/ctrlspace/window.vim @@ -1,600 +1,615 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() -function! ctrlspace#window#MaxHeight() - let maxFromConfig = s:config.MaxHeight - - if maxFromConfig - return maxFromConfig - else - return &lines / 3 - endif +function! ctrlspace#window#MaxHeight() abort + let maxFromConfig = s:config.MaxHeight + + if maxFromConfig + return maxFromConfig + else + return &lines / 3 + endif endfunction -function! ctrlspace#window#Toggle(internal) - if !a:internal - call s:resetWindow() - endif - - " if we get called and the list is open --> close it - let pbuf = ctrlspace#context#PluginBuffer() - - if bufexists(pbuf) - if bufwinnr(pbuf) != -1 - call ctrlspace#window#Kill(pbuf, 1) - return - else - call ctrlspace#window#Kill(pbuf, 0) - if !a:internal - let t:CtrlSpaceStartWindow = winnr() - let t:CtrlSpaceWinrestcmd = winrestcmd() - let t:CtrlSpaceActivebuf = bufnr("") - endif - endif - elseif !a:internal - " make sure zoom window is closed - silent! exe "pclose" - let t:CtrlSpaceStartWindow = winnr() - let t:CtrlSpaceWinrestcmd = winrestcmd() - let t:CtrlSpaceActivebuf = bufnr("") - endif - - if s:modes.Zoom.Enabled - let t:CtrlSpaceActivebuf = bufnr("") - endif - - " create the buffer first & set it up - silent! exe "noautocmd botright pedit CtrlSpace" - silent! exe "noautocmd wincmd P" - silent! exe "resize" s:config.Height - - " zoom start window in Zoom Mode - if s:modes.Zoom.Enabled - silent! exe t:CtrlSpaceStartWindow . "wincmd w" - vert resize | resize - silent! exe "noautocmd wincmd P" - endif - - call s:setUpBuffer() - - if s:modes.Help.Enabled - call ctrlspace#help#DisplayHelp(s:filler()) - call ctrlspace#util#SetStatusline() - return - endif - - let [b:patterns, b:indices, b:size, b:text] = ctrlspace#engine#Content() - - " set up window height - if b:size > s:config.Height - let maxHeight = ctrlspace#window#MaxHeight() - - if b:size < maxHeight - silent! exe "resize " . b:size - else - silent! exe "resize " . maxHeight - endif - endif - - silent! exe "set updatetime=" . s:config.SearchTiming - - call s:displayContent() - call ctrlspace#util#SetStatusline() - - " display search patterns - for pattern in b:patterns - " escape ~ sign because of E874: (NFA) Could not pop the stack ! - call matchadd("CtrlSpaceSearch", "\\c" .substitute(pattern, '\~', '\\~', "g")) - endfor - - call s:setActiveLine() - - normal! zb +function! ctrlspace#window#Toggle(internal) abort + if !a:internal + call s:resetWindow() + endif + + " if we get called and the list is open --> close it + let pbuf = ctrlspace#context#PluginBuffer() + + if bufexists(pbuf) + if bufwinnr(pbuf) != -1 + call ctrlspace#window#Kill(pbuf, 1) + return + else + call ctrlspace#window#Kill(pbuf, 0) + if !a:internal + let t:CtrlSpaceStartWindow = winnr() + let t:CtrlSpaceWinrestcmd = winrestcmd() + let t:CtrlSpaceActivebuf = bufnr("") + endif + endif + elseif !a:internal + " make sure zoom window is closed + silent! exe "pclose" + let t:CtrlSpaceStartWindow = winnr() + let t:CtrlSpaceWinrestcmd = winrestcmd() + let t:CtrlSpaceActivebuf = bufnr("") + endif + + if s:modes.Zoom.Enabled + let t:CtrlSpaceActivebuf = bufnr("") + endif + + " create the buffer first & set it up + try + if has('patch-8.1.1714') && !empty(&previewpopup) + let previewpopup_save = &previewpopup + set previewpopup= + endif + silent exe "noautocmd botright pedit CtrlSpace" + silent exe "noautocmd wincmd P" + silent exe "resize" s:config.Height + catch + echoerr 'cannot open CtrlSpace window here' + return + finally + if exists("previewpopup_save") + let &previewpopup = previewpopup_save + unlet previewpopup_save + endif + endtry + + " zoom start window in Zoom Mode + if s:modes.Zoom.Enabled + silent! exe t:CtrlSpaceStartWindow . "wincmd w" + vert resize | resize + silent! exe "noautocmd wincmd P" + endif + + call s:setUpBuffer() + + if s:modes.Help.Enabled + call ctrlspace#help#DisplayHelp(s:filler()) + call ctrlspace#util#SetStatusline() + return + endif + + let [b:patterns, b:indices, b:size, b:text] = ctrlspace#engine#Content() + + " set up window height + if b:size > s:config.Height + let maxHeight = ctrlspace#window#MaxHeight() + + if b:size < maxHeight + silent! exe "resize " . b:size + else + silent! exe "resize " . maxHeight + endif + endif + + silent! exe "set updatetime=" . s:config.SearchTiming + + call s:displayContent() + call ctrlspace#util#SetStatusline() + + " display search patterns + for pattern in b:patterns + " escape ~ sign because of E874: (NFA) Could not pop the stack ! + call matchadd("CtrlSpaceSearch", "\\c" .substitute(pattern, '\~', '\\~', "g")) + endfor + + call s:setActiveLine() + + normal! zb endfunction -function! ctrlspace#window#GoToBufferListPosition(direction) - let bufferList = ctrlspace#api#BufferList(tabpagenr()) - let currentBuffer = bufnr("%") - let currentIndex = -1 - let bufferListLen = len(bufferList) - - for index in range(bufferListLen) - if bufferList[index]["index"] == currentBuffer - let currentIndex = index - break - endif - endfor - - if currentIndex == -1 - return - endif - - if a:direction == "down" - let targetIndex = currentIndex + 1 - - if targetIndex == bufferListLen - let targetIndex = 0 - endif - else - let targetIndex = currentIndex - 1 - - if targetIndex < 0 - let targetIndex = bufferListLen - 1 - endif - endif - - silent! exe ":b " . bufferList[targetIndex]["index"] +function! ctrlspace#window#GoToBufferListPosition(direction) abort + let bufferList = ctrlspace#api#BufferList(tabpagenr()) + let currentBuffer = bufnr("%") + let currentIndex = -1 + let bufferListLen = len(bufferList) + + for index in range(bufferListLen) + if bufferList[index]["index"] == currentBuffer + let currentIndex = index + break + endif + endfor + + if currentIndex == -1 + return + endif + + if a:direction == "down" + let targetIndex = currentIndex + 1 + + if targetIndex == bufferListLen + let targetIndex = 0 + endif + else + let targetIndex = currentIndex - 1 + + if targetIndex < 0 + let targetIndex = bufferListLen - 1 + endif + endif + + silent! exe ":b " . bufferList[targetIndex]["index"] endfunction -function! ctrlspace#window#GoToStartWindow() - silent! exe t:CtrlSpaceStartWindow . "wincmd w" +function! ctrlspace#window#GoToStartWindow() abort + silent! exe t:CtrlSpaceStartWindow . "wincmd w" - if winrestcmd() != t:CtrlSpaceWinrestcmd - silent! exe t:CtrlSpaceWinrestcmd + if winrestcmd() != t:CtrlSpaceWinrestcmd && !has('nvim') + silent! exe t:CtrlSpaceWinrestcmd + endif - if winrestcmd() != t:CtrlSpaceWinrestcmd - wincmd = - endif - endif + if winrestcmd() != t:CtrlSpaceWinrestcmd + wincmd = + endif endfunction -function! ctrlspace#window#Kill(pluginBuffer, final) - " added workaround for strange Vim behavior when, when kill starts with some delay - " (in a wrong buffer). This happens in some Nop modes (in a File List view). - if (exists("s:killingNow") && s:killingNow) || (!a:pluginBuffer && &ft != "ctrlspace") - return - endif +function! ctrlspace#window#Kill(pluginBuffer, final) abort + " added workaround for strange Vim behavior when, when kill starts with some delay + " (in a wrong buffer). This happens in some Nop modes (in a File List view). + if (exists("s:killingNow") && s:killingNow) || (!a:pluginBuffer && &ft != "ctrlspace") + return + endif - let s:killingNow = 1 + let s:killingNow = 1 - if exists("b:updatetimeSave") - silent! exe "set updatetime=" . b:updatetimeSave - endif + if exists("b:updatetimeSave") + silent! exe "set updatetime=" . b:updatetimeSave + endif - if exists("b:timeoutlenSave") - silent! exe "set timeoutlen=" . b:timeoutlenSave - endif + if exists("b:timeoutlenSave") + silent! exe "set timeoutlen=" . b:timeoutlenSave + endif - if exists("b:mouseSave") - silent! exe "set mouse=" . b:mouseSave - endif + if exists("b:mouseSave") + silent! exe "set mouse=" . b:mouseSave + endif - " shellslash support for win32 - if exists("b:nosslSave") && b:nosslSave - set nossl - endif + " shellslash support for win32 + if exists("b:nosslSave") && b:nosslSave + set nossl + endif - if a:pluginBuffer - silent! exe ':' . a:pluginBuffer . 'bwipeout' - else - bwipeout - endif + if a:pluginBuffer + silent! exe ':' . a:pluginBuffer . 'bwipeout' + else + bwipeout + endif - if a:final - call ctrlspace#util#HandleVimSettings("stop") + if a:final + call ctrlspace#util#HandleVimSettings("stop") - if s:modes.Search.Data.Restored - call ctrlspace#search#AppendToSearchHistory() - endif + if s:modes.Search.Data.Restored + call ctrlspace#search#AppendToSearchHistory() + endif - call ctrlspace#window#GoToStartWindow() + call ctrlspace#window#GoToStartWindow() - if s:modes.Zoom.Enabled - exec ":b " . s:modes.Zoom.Data.Buffer - call s:modes.Zoom.SetData("Buffer", 0) - call s:modes.Zoom.Disable() - call ctrlspace#buffers#DeleteForeignBuffers(1) - call ctrlspace#buffers#DeleteHiddenNonameBuffers(1) - endif + if s:modes.Zoom.Enabled + exec ":b " . s:modes.Zoom.Data.Buffer + call s:modes.Zoom.SetData("Buffer", 0) + call s:modes.Zoom.Disable() + call ctrlspace#buffers#DeleteForeignBuffers(1) + call ctrlspace#buffers#DeleteHiddenNonameBuffers(1) + endif - set guicursor-=n:block-CtrlSpaceSelected-blinkon0 - endif + set guicursor-=n:block-CtrlSpaceSelected-blinkon0 + endif - unlet s:killingNow + unlet s:killingNow endfunction -function! ctrlspace#window#QuitVim() - if !s:config.SaveWorkspaceOnExit - let aw = ctrlspace#workspaces#ActiveWorkspace() +function! ctrlspace#window#QuitVim() abort + if !s:config.SaveWorkspaceOnExit + let aw = ctrlspace#workspaces#ActiveWorkspace() - if aw.Status == 2 && !ctrlspace#ui#Confirmed("Current workspace ('" . aw.Name . "') not saved. Proceed anyway?") - return - endif - endif + if aw.Status == 2 && !ctrlspace#ui#Confirmed("Current workspace ('" . aw.Name . "') not saved. Proceed anyway?") + return + endif + endif - if !ctrlspace#ui#ProceedIfModified() - return - endif + if !ctrlspace#ui#ProceedIfModified() + return + endif - call ctrlspace#window#Kill(0, 1) - qa! + call ctrlspace#window#Kill(0, 1) + qa! endfunction -function! ctrlspace#window#MoveSelectionBar(where) - if b:size < 1 - return - endif - - let newpos = 0 - - if !exists("b:lastline") - let b:lastline = 0 - endif - - setlocal modifiable - - " the mouse was pressed: remember which line - " and go back to the original location for now - if a:where == "mouse" - let newpos = line(".") - call s:goto(b:lastline) - endif - - " exchange the first char (>) with a space - call setline(line("."), " " . strpart(getline(line(".")), 1)) - - " go where the user want's us to go - if a:where == "up" - call s:goto(line(".") - 1) - elseif a:where == "down" - call s:goto(line(".") + 1) - elseif a:where == "mouse" - call s:goto(newpos) - elseif a:where == "pgup" - let newpos = line(".") - winheight(0) - if newpos < 1 - let newpos = 1 - endif - call s:goto(newpos) - elseif a:where == "pgdown" - let newpos = line(".") + winheight(0) - if newpos > line("$") - let newpos = line("$") - endif - call s:goto(newpos) - elseif a:where == "half_pgup" - let newpos = line(".") - winheight(0) / 2 - if newpos < 1 - let newpos = 1 - endif - call s:goto(newpos) - elseif a:where == "half_pgdown" - let newpos = line(".") + winheight(0) / 2 - if newpos > line("$") - let newpos = line("$") - endif - call s:goto(newpos) - else - call s:goto(a:where) - endif - - " and mark this line with a > - call setline(line("."), ">" . strpart(getline(line(".")), 1)) - - " remember this line, in case the mouse is clicked - " (which automatically moves the cursor there) - let b:lastline = line(".") - - setlocal nomodifiable +function! ctrlspace#window#MoveSelectionBar(where) abort + if b:size < 1 + return + endif + + let newpos = 0 + + if !exists("b:lastline") + let b:lastline = 0 + endif + + setlocal modifiable + + " the mouse was pressed: remember which line + " and go back to the original location for now + if a:where == "mouse" + let newpos = line(".") + call s:goto(b:lastline) + endif + + " exchange the first char (>) with a space + call setline(line("."), " " . strpart(getline(line(".")), 1)) + + " go where the user want's us to go + if a:where == "up" + call s:goto(line(".") - 1) + elseif a:where == "down" + call s:goto(line(".") + 1) + elseif a:where == "mouse" + call s:goto(newpos) + elseif a:where == "pgup" + let newpos = line(".") - winheight(0) + if newpos < 1 + let newpos = 1 + endif + call s:goto(newpos) + elseif a:where == "pgdown" + let newpos = line(".") + winheight(0) + if newpos > line("$") + let newpos = line("$") + endif + call s:goto(newpos) + elseif a:where == "half_pgup" + let newpos = line(".") - winheight(0) / 2 + if newpos < 1 + let newpos = 1 + endif + call s:goto(newpos) + elseif a:where == "half_pgdown" + let newpos = line(".") + winheight(0) / 2 + if newpos > line("$") + let newpos = line("$") + endif + call s:goto(newpos) + else + call s:goto(a:where) + endif + + " and mark this line with a > + call setline(line("."), ">" . strpart(getline(line(".")), 1)) + + " remember this line, in case the mouse is clicked + " (which automatically moves the cursor there) + let b:lastline = line(".") + + setlocal nomodifiable endfunction -function! ctrlspace#window#MoveCursor(where) - if a:where == "up" - call s:goto(line(".") - 1) - elseif a:where == "down" - call s:goto(line(".") + 1) - elseif a:where == "mouse" - call s:goto(line(".")) - elseif a:where == "pgup" - let newpos = line(".") - winheight(0) - if newpos < 1 - let newpos = 1 - endif - call s:goto(newpos) - elseif a:where == "pgdown" - let newpos = line(".") + winheight(0) - if newpos > line("$") - let newpos = line("$") - endif - call s:goto(newpos) - elseif a:where == "half_pgup" - let newpos = line(".") - winheight(0) / 2 - if newpos < 1 - let newpos = 1 - endif - call s:goto(newpos) - elseif a:where == "half_pgdown" - let newpos = line(".") + winheight(0) / 2 - if newpos > line("$") - let newpos = line("$") - endif - call s:goto(newpos) - else - call s:goto(a:where) - endif +function! ctrlspace#window#MoveCursor(where) abort + if a:where == "up" + call s:goto(line(".") - 1) + elseif a:where == "down" + call s:goto(line(".") + 1) + elseif a:where == "mouse" + call s:goto(line(".")) + elseif a:where == "pgup" + let newpos = line(".") - winheight(0) + if newpos < 1 + let newpos = 1 + endif + call s:goto(newpos) + elseif a:where == "pgdown" + let newpos = line(".") + winheight(0) + if newpos > line("$") + let newpos = line("$") + endif + call s:goto(newpos) + elseif a:where == "half_pgup" + let newpos = line(".") - winheight(0) / 2 + if newpos < 1 + let newpos = 1 + endif + call s:goto(newpos) + elseif a:where == "half_pgdown" + let newpos = line(".") + winheight(0) / 2 + if newpos > line("$") + let newpos = line("$") + endif + call s:goto(newpos) + else + call s:goto(a:where) + endif endfunction -function! ctrlspace#window#SelectedIndex() - return b:indices[line(".") - 1] +function! ctrlspace#window#SelectedIndex() abort + return b:indices[line(".") - 1] endfunction -function! ctrlspace#window#GoToWindow() - let nr = ctrlspace#window#SelectedIndex() +function! ctrlspace#window#GoToWindow() abort + let nr = ctrlspace#window#SelectedIndex() - if bufwinnr(nr) != -1 - call ctrlspace#window#Kill(0, 1) - silent! exe bufwinnr(nr) . "wincmd w" - return 1 - endif + if bufwinnr(nr) != -1 + call ctrlspace#window#Kill(0, 1) + silent! exe bufwinnr(nr) . "wincmd w" + return 1 + endif - return 0 + return 0 endfunction " tries to set the cursor to a line of the buffer list -function! s:goto(line) - if b:size < 1 - return - endif - - if a:line < 1 - call s:goto(b:size - a:line) - elseif a:line > b:size - call s:goto(a:line - b:size) - else - call cursor(a:line, 1) - endif +function! s:goto(line) abort + if b:size < 1 + return + endif + + if a:line < 1 + call s:goto(b:size - a:line) + elseif a:line > b:size + call s:goto(a:line - b:size) + else + call cursor(a:line, 1) + endif endfunction -function! s:resetWindow() - call s:modes.Help.Disable() - call s:modes.Nop.Disable() - call s:modes.Search.Disable() - call s:modes.NextTab.Disable() +function! s:resetWindow() abort + call s:modes.Help.Disable() + call s:modes.Nop.Disable() + call s:modes.Search.Disable() + call s:modes.NextTab.Disable() - call s:modes.Buffer.Enable() - call s:modes.Buffer.SetData("SubMode", "single") + call s:modes.Buffer.Enable() + call s:modes.Buffer.SetData("SubMode", "single") - call s:modes.Search.SetData("NewSearchPerformed", 0) - call s:modes.Search.SetData("Restored", 0) - call s:modes.Search.SetData("Letters", []) - call s:modes.Search.SetData("HistoryIndex", -1) + call s:modes.Search.SetData("NewSearchPerformed", 0) + call s:modes.Search.SetData("Restored", 0) + call s:modes.Search.SetData("Letters", []) + call s:modes.Search.SetData("HistoryIndex", -1) - call s:modes.Workspace.SetData("LastBrowsed", 0) - call s:modes.Workspace.SetData("SubMode", "load") + call s:modes.Workspace.SetData("LastBrowsed", 0) + call s:modes.Workspace.SetData("SubMode", "load") - call ctrlspace#roots#SetCurrentProjectRoot(ctrlspace#roots#FindProjectRoot()) - call s:modes.Bookmark.SetData("Active", ctrlspace#bookmarks#FindActiveBookmark()) + call ctrlspace#roots#SetCurrentProjectRoot(ctrlspace#roots#FindProjectRoot()) + call s:modes.Bookmark.SetData("Active", ctrlspace#bookmarks#FindActiveBookmark()) - call s:modes.Search.RemoveData("LastSearchedDirectory") + call s:modes.Search.RemoveData("LastSearchedDirectory") - if ctrlspace#roots#LastProjectRoot() != ctrlspace#roots#CurrentProjectRoot() - call ctrlspace#files#ClearAll() - call ctrlspace#roots#SetLastProjectRoot(ctrlspace#roots#CurrentProjectRoot()) - call ctrlspace#workspaces#SetWorkspaceNames() - endif + if ctrlspace#roots#LastProjectRoot() != ctrlspace#roots#CurrentProjectRoot() + call ctrlspace#files#ClearAll() + call ctrlspace#roots#SetLastProjectRoot(ctrlspace#roots#CurrentProjectRoot()) + call ctrlspace#workspaces#SetWorkspaceNames() + endif - set guicursor+=n:block-CtrlSpaceSelected-blinkon0 + set guicursor+=n:block-CtrlSpaceSelected-blinkon0 - call ctrlspace#util#HandleVimSettings("start") + call ctrlspace#util#HandleVimSettings("start") endfunction -function! s:setUpBuffer() - setlocal noswapfile - setlocal buftype=nofile - setlocal bufhidden=delete - setlocal nobuflisted - setlocal nomodifiable - setlocal nowrap - setlocal nonumber - if exists('+relativenumber') - setlocal norelativenumber - endif - setlocal nocursorcolumn - setlocal nocursorline - setlocal nospell - setlocal nolist - setlocal cc= - setlocal filetype=ctrlspace - - call ctrlspace#context#SetPluginBuffer(bufnr("%")) - - let root = ctrlspace#roots#CurrentProjectRoot() - - if !empty(root) - silent! exe "lcd " . fnameescape(root) - endif - - if &timeout - let b:timeoutlenSave = &timeoutlen - set timeoutlen=10 - endif - - let b:updatetimeSave = &updatetime - - " shellslash support for win32 - if has("win32") && !&ssl - let b:nosslSave = 1 - set ssl - endif - - augroup CtrlSpaceUpdateSearch - au! - au CursorHold call ctrlspace#search#UpdateSearchResults() - augroup END - - augroup CtrlSpaceLeave - au! - au BufLeave call ctrlspace#window#Kill(0, 1) - augroup END - - " set up syntax highlighting - if has("syntax") - syn clear - syn match CtrlSpaceNormal / .*/ - syn match CtrlSpaceSelected /> .*/hs=s+1 - endif - - call clearmatches() - - if !s:config.UseMouseAndArrowsInTerm && !has("gui_running") - " Block unnecessary escape sequences! - noremap [ :call ctrlspace#keys#MarkKeyEscSequence() - let b:mouseSave = &mouse - set mouse= - endif - - for k in ctrlspace#keys#KeyNames() - let key = strlen(k) > 1 ? ("<" . k . ">") : k - - if k == '"' - let k = '\' . k - endif - - silent! exe "noremap " . key . " :call ctrlspace#keys#Keypressed(\"" . k . "\") " - endfor +function! s:setUpBuffer() abort + setlocal noswapfile + setlocal buftype=nofile + setlocal bufhidden=delete + setlocal nobuflisted + setlocal nomodifiable + setlocal nowrap + setlocal nonumber + if exists('+relativenumber') + setlocal norelativenumber + endif + setlocal nocursorcolumn + setlocal nocursorline + setlocal nospell + setlocal nolist + setlocal cc= + setlocal filetype=ctrlspace + setlocal foldmethod=manual + + call ctrlspace#context#SetPluginBuffer(bufnr("%")) + + let root = ctrlspace#roots#CurrentProjectRoot() + + if !empty(root) + silent! exe "lcd " . fnameescape(root) + endif + + if &timeout + let b:timeoutlenSave = &timeoutlen + set timeoutlen=10 + endif + + let b:updatetimeSave = &updatetime + + " shellslash support for win32 + if has("win32") && !&ssl + let b:nosslSave = 1 + set ssl + endif + + augroup CtrlSpaceUpdateSearch + au! + au CursorHold call ctrlspace#search#UpdateSearchResults() + augroup END + + augroup CtrlSpaceLeave + au! + au BufLeave call ctrlspace#window#Kill(0, 1) + augroup END + + " set up syntax highlighting + if has("syntax") + syn clear + syn match CtrlSpaceNormal / .*/ + syn match CtrlSpaceSelected /> .*/hs=s+1 + endif + + call clearmatches() + + if !s:config.UseMouseAndArrowsInTerm && !has("gui_running") + " Block unnecessary escape sequences! + noremap [ :call ctrlspace#keys#MarkKeyEscSequence() + let b:mouseSave = &mouse + set mouse= + endif + + for k in ctrlspace#keys#KeyNames() + let key = strlen(k) > 1 ? ("<" . k . ">") : k + + if k == '"' + let k = '\' . k + endif + + silent! exe "nnoremap " . key . " :call ctrlspace#keys#Keypressed(\"" . k . "\") " + endfor endfunction -function! s:setActiveLine() - if !empty(s:modes.Search.Data.Letters) && s:modes.Search.Data.NewSearchPerformed - call ctrlspace#window#MoveSelectionBar(line("$")) - - if !s:modes.Search.Enabled - call s:modes.Search.SetData("NewSearchPerformed", 0) - endif - else - let clv = ctrlspace#modes#CurrentListView() - - if clv.Name ==# "Workspace" - if clv.Data.LastBrowsed - let activeLine = clv.Data.LastBrowsed - else - let activeLine = 1 - let aw = ctrlspace#workspaces#ActiveWorkspace() - - if aw.Status - let currWsp = aw.Name - elseif !empty(clv.Data.LastActive) - let currWsp = clv.Data.LastActive - else - let currWsp = "" - endif - - if !empty(currWsp) - let workspaces = ctrlspace#workspaces#Workspaces() - - for i in range(b:size) - if currWsp ==# workspaces[b:indices[i]] - let activeLine = i + 1 - break - endif - endfor - endif - endif - elseif clv.Name ==# "Tab" - let activeLine = tabpagenr() - elseif clv.Name ==# "Bookmark" - let activeLine = 1 - - if !empty(clv.Data.Active) - let bookmarks = ctrlspace#bookmarks#Bookmarks() - - for i in range(b:size) - if clv.Data.Active.Name ==# bookmarks[b:indices[i]].Name - let activeLine = i + 1 - break - endif - endfor - endif - elseif clv.Name ==# "File" - let activeLine = line("$") - else - let activeLine = 0 - let maxCounter = 0 - let lastLine = 0 - - for i in range(b:size) - if b:indices[i] == t:CtrlSpaceActivebuf - let activeLine = i + 1 - break - endif - - let currentJumpCounter = ctrlspace#util#GetbufvarWithDefault(b:indices[i], "CtrlSpaceJumpCounter", 0) - - if currentJumpCounter > maxCounter - let maxCounter = currentJumpCounter - let lastLine = i + 1 - endif - endfor - - if !activeLine - let activeLine = (lastLine > 0) ? lastLine : b:size - 1 - endif - endif - - call ctrlspace#window#MoveSelectionBar(activeLine) - endif +function! s:setActiveLine() abort + if !empty(s:modes.Search.Data.Letters) && s:modes.Search.Data.NewSearchPerformed + call ctrlspace#window#MoveSelectionBar(line("$")) + + if !s:modes.Search.Enabled + call s:modes.Search.SetData("NewSearchPerformed", 0) + endif + else + let clv = ctrlspace#modes#CurrentListView() + + if clv.Name ==# "Workspace" + if clv.Data.LastBrowsed + let activeLine = clv.Data.LastBrowsed + else + let activeLine = 1 + let aw = ctrlspace#workspaces#ActiveWorkspace() + + if aw.Status + let currWsp = aw.Name + elseif !empty(clv.Data.LastActive) + let currWsp = clv.Data.LastActive + else + let currWsp = "" + endif + + if !empty(currWsp) + let workspaces = ctrlspace#workspaces#Workspaces() + + for i in range(b:size) + if currWsp ==# workspaces[b:indices[i]] + let activeLine = i + 1 + break + endif + endfor + endif + endif + elseif clv.Name ==# "Tab" + let activeLine = tabpagenr() + elseif clv.Name ==# "Bookmark" + let activeLine = 1 + + if !empty(clv.Data.Active) + let bookmarks = ctrlspace#bookmarks#Bookmarks() + + for i in range(b:size) + if clv.Data.Active.Name ==# bookmarks[b:indices[i]].Name + let activeLine = i + 1 + break + endif + endfor + endif + elseif clv.Name ==# "File" + let activeLine = line("$") + else + let activeLine = 0 + let maxCounter = 0 + let lastLine = 0 + + for i in range(b:size) + if b:indices[i] == t:CtrlSpaceActivebuf + let activeLine = i + 1 + break + endif + + let currentJumpCounter = ctrlspace#util#GetbufvarWithDefault(b:indices[i], "CtrlSpaceJumpCounter", 0) + + if currentJumpCounter > maxCounter + let maxCounter = currentJumpCounter + let lastLine = i + 1 + endif + endfor + + if !activeLine + let activeLine = (lastLine > 0) ? lastLine : b:size - 1 + endif + endif + + call ctrlspace#window#MoveSelectionBar(activeLine) + endif endfunction -function! s:filler() - " generate a variable to fill the buffer afterwards - " (we need this for "full window" color :) - if !exists("s:filler['" . &columns . "']") - let fill = "\n" - let i = 0 +function! s:filler() abort + " generate a variable to fill the buffer afterwards + " (we need this for "full window" color :) + if !exists("s:filler['" . &columns . "']") + let fill = "\n" + let i = 0 - while i < &columns - let i += 1 - let fill = ' ' . fill - endwhile + while i < &columns + let i += 1 + let fill = ' ' . fill + endwhile - if !exists("s:filler") - let s:filler = {} - endif + if !exists("s:filler") + let s:filler = {} + endif - let s:filler[string(&columns)] = fill - endif + let s:filler[string(&columns)] = fill + endif - return s:filler[string(&columns)] + return s:filler[string(&columns)] endfunction -function! s:fillBufferSpace() - let fill = s:filler() +function! s:fillBufferSpace() abort + let fill = s:filler() - while winheight(0) > line(".") - silent! put =fill - endwhile + while winheight(0) > line(".") + silent! put =fill + endwhile endfunction -function! s:displayContent() - setlocal modifiable +function! s:displayContent() abort + setlocal modifiable - if b:size > 0 - silent! put! =b:text - normal! GkJ - call s:fillBufferSpace() - call s:modes.Nop.Disable() - else - let emptyListMessage = " List empty" + if b:size > 0 + silent! put! =b:text + normal! GkJ + call s:fillBufferSpace() + call s:modes.Nop.Disable() + else + let emptyListMessage = " List empty" - let sizes = ctrlspace#context#SymbolSizes() + let sizes = ctrlspace#context#SymbolSizes() - if &columns < (strwidth(emptyListMessage) + 2) - let emptyListMessage = strpart(emptyListMessage, 0, &columns - 2 - sizes.Dots) . s:config.Symbols.Dots - endif + if &columns < (strwidth(emptyListMessage) + 2) + let emptyListMessage = strpart(emptyListMessage, 0, &columns - 2 - sizes.Dots) . s:config.Symbols.Dots + endif - while strwidth(emptyListMessage) < &columns - let emptyListMessage .= ' ' - endwhile + while strwidth(emptyListMessage) < &columns + let emptyListMessage .= ' ' + endwhile - silent! put! =emptyListMessage - normal! GkJ + silent! put! =emptyListMessage + normal! GkJ - call s:fillBufferSpace() + call s:fillBufferSpace() - normal! 0 + normal! 0 - call s:modes.Nop.Enable() - endif + call s:modes.Nop.Enable() + endif - setlocal nomodifiable + setlocal nomodifiable endfunction diff --git a/autoload/ctrlspace/workspaces.vim b/autoload/ctrlspace/workspaces.vim index 5019ea3d..a300b8af 100644 --- a/autoload/ctrlspace/workspaces.vim +++ b/autoload/ctrlspace/workspaces.vim @@ -2,501 +2,519 @@ let s:config = ctrlspace#context#Configuration() let s:modes = ctrlspace#modes#Modes() let s:workspaces = [] -function! ctrlspace#workspaces#Workspaces() - return s:workspaces +function! ctrlspace#workspaces#Workspaces() abort + return s:workspaces endfunction -function! ctrlspace#workspaces#SetWorkspaceNames() - let filename = ctrlspace#util#WorkspaceFile() - let s:workspaces = [] - - call s:modes.Workspace.SetData("LastActive", "") - - if filereadable(filename) - for line in readfile(filename) - if line =~? "CS_WORKSPACE_BEGIN: " - call add(s:workspaces, line[20:]) - elseif line =~? "CS_LAST_WORKSPACE: " - call s:modes.Workspace.SetData("LastActive", line[19:]) - endif - endfor - endif +function! ctrlspace#workspaces#SetWorkspaceNames() abort + let filename = ctrlspace#util#WorkspaceFile() + let s:workspaces = [] + + call s:modes.Workspace.SetData("LastActive", "") + + if filereadable(filename) + for line in readfile(filename) + if line =~? "CS_WORKSPACE_BEGIN: " + call add(s:workspaces, line[20:]) + elseif line =~? "CS_LAST_WORKSPACE: " + call s:modes.Workspace.SetData("LastActive", line[19:]) + endif + endfor + endif endfunction -function! ctrlspace#workspaces#SetActiveWorkspaceName(name, ...) - if a:0 > 0 - let digest = a:1 - else - let digest = s:modes.Workspace.Data.Active.Digest - end +function! ctrlspace#workspaces#SetActiveWorkspaceName(name, ...) abort + if a:0 > 0 + let digest = a:1 + else + let digest = s:modes.Workspace.Data.Active.Digest + end - call s:modes.Workspace.SetData("Active", { "Name": a:name, "Digest": digest, "Root": ctrlspace#roots#CurrentProjectRoot() }) - call s:modes.Workspace.SetData("LastActive", a:name) + call s:modes.Workspace.SetData("Active", { "Name": a:name, "Digest": digest, "Root": ctrlspace#roots#CurrentProjectRoot() }) + call s:modes.Workspace.SetData("LastActive", a:name) - let filename = ctrlspace#util#WorkspaceFile() - let lines = [] + let filename = ctrlspace#util#WorkspaceFile() + let lines = [] - if filereadable(filename) - for line in readfile(filename) - if !(line =~? "CS_LAST_WORKSPACE: ") - call add(lines, line) - endif - endfor - endif + if filereadable(filename) + for line in readfile(filename) + if !(line =~? "CS_LAST_WORKSPACE: ") + call add(lines, line) + endif + endfor + endif - if !empty(a:name) - call insert(lines, "CS_LAST_WORKSPACE: " . a:name) - endif + if !empty(a:name) + call insert(lines, "CS_LAST_WORKSPACE: " . a:name) + endif - call writefile(lines, filename) + call writefile(lines, filename) endfunction -function! ctrlspace#workspaces#ActiveWorkspace() - let aw = s:modes.Workspace.Data.Active - let aw.Status = 0 +function! ctrlspace#workspaces#ActiveWorkspace() abort + let aw = s:modes.Workspace.Data.Active + let aw.Status = 0 - if !empty(aw.Name) && aw.Root ==# ctrlspace#roots#CurrentProjectRoot() - let aw.Status = 1 + if !empty(aw.Name) && aw.Root ==# ctrlspace#roots#CurrentProjectRoot() + let aw.Status = 1 - if aw.Digest !=# ctrlspace#workspaces#CreateDigest() - let aw.Status = 2 - endif - endif + if aw.Digest !=# ctrlspace#workspaces#CreateDigest() + let aw.Status = 2 + endif + endif - return aw + return aw endfunction -function! ctrlspace#workspaces#NewWorkspace() - tabe - tabo! - call ctrlspace#buffers#DeleteHiddenNonameBuffers(1) - call ctrlspace#buffers#DeleteForeignBuffers(1) - call s:modes.Workspace.SetData("Active", { "Name": "", "Digest": "", "Root": "" }) +function! ctrlspace#workspaces#NewWorkspace() abort + tabe + tabo! + call ctrlspace#buffers#DeleteHiddenNonameBuffers(1) + call ctrlspace#buffers#DeleteForeignBuffers(1) + call s:modes.Workspace.SetData("Active", { "Name": "", "Digest": "", "Root": "" }) endfunction -function! ctrlspace#workspaces#SelectedWorkspaceName() - return s:modes.Workspace.Enabled ? s:workspaces[ctrlspace#window#SelectedIndex()] : "" +function! ctrlspace#workspaces#SelectedWorkspaceName() abort + return s:modes.Workspace.Enabled ? s:workspaces[ctrlspace#window#SelectedIndex()] : "" endfunction -function! ctrlspace#workspaces#RenameWorkspace(name) - let newName = ctrlspace#ui#GetInput("Rename workspace '" . a:name . "' to: ", a:name) - - if empty(newName) - return 0 - endif - - for existingName in s:workspaces - if newName ==# existingName - call ctrlspace#ui#Msg("Workspace '" . newName . "' already exists.") - return 0 - endif - endfor - - let filename = ctrlspace#util#WorkspaceFile() - let lines = [] - - let workspaceStartMarker = "CS_WORKSPACE_BEGIN: " . a:name - let workspaceEndMarker = "CS_WORKSPACE_END: " . a:name - let lastWorkspaceMarker = "CS_LAST_WORKSPACE: " . a:name - - if filereadable(filename) - for line in readfile(filename) - if line ==# workspaceStartMarker - let line = "CS_WORKSPACE_BEGIN: " . newName - elseif line ==# workspaceEndMarker - let line = "CS_WORKSPACE_END: " . newName - elseif line ==# lastWorkspaceMarker - let line = "CS_LAST_WORKSPACE: " . newName - endif - - call add(lines, line) - endfor - endif - - call writefile(lines, filename) - - if s:modes.Workspace.Data.Active.Name ==# a:name && s:modes.Workspace.Data.Active.Root ==# ctrlspace#roots#CurrentProjectRoot() - call ctrlspace#workspaces#SetActiveWorkspaceName(newName) - endif - - call ctrlspace#workspaces#SetWorkspaceNames() - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) - - call ctrlspace#ui#DelayedMsg("Workspace '" . a:name . "' has been renamed to '" . newName . "'.") - return 1 +function! ctrlspace#workspaces#RenameWorkspace(name) abort + let newName = ctrlspace#ui#GetInput("Rename workspace '" . a:name . "' to: ", a:name) + + if empty(newName) + return 0 + endif + + for existingName in s:workspaces + if newName ==# existingName + call ctrlspace#ui#Msg("Workspace '" . newName . "' already exists.") + return 0 + endif + endfor + + let filename = ctrlspace#util#WorkspaceFile() + let lines = [] + + let workspaceStartMarker = "CS_WORKSPACE_BEGIN: " . a:name + let workspaceEndMarker = "CS_WORKSPACE_END: " . a:name + let lastWorkspaceMarker = "CS_LAST_WORKSPACE: " . a:name + + if filereadable(filename) + for line in readfile(filename) + if line ==# workspaceStartMarker + let line = "CS_WORKSPACE_BEGIN: " . newName + elseif line ==# workspaceEndMarker + let line = "CS_WORKSPACE_END: " . newName + elseif line ==# lastWorkspaceMarker + let line = "CS_LAST_WORKSPACE: " . newName + endif + + call add(lines, line) + endfor + endif + + call writefile(lines, filename) + + if s:modes.Workspace.Data.Active.Name ==# a:name && s:modes.Workspace.Data.Active.Root ==# ctrlspace#roots#CurrentProjectRoot() + call ctrlspace#workspaces#SetActiveWorkspaceName(newName) + endif + + call ctrlspace#workspaces#SetWorkspaceNames() + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) + + call ctrlspace#ui#DelayedMsg("Workspace '" . a:name . "' has been renamed to '" . newName . "'.") + return 1 endfunction -function! ctrlspace#workspaces#DeleteWorkspace(name) - if !ctrlspace#ui#Confirmed("Delete workspace '" . a:name . "'?") - return 0 - endif +function! ctrlspace#workspaces#DeleteWorkspace(name) abort + if !ctrlspace#ui#Confirmed("Delete workspace '" . a:name . "'?") + return 0 + endif - let filename = ctrlspace#util#WorkspaceFile() - let lines = [] - let inWorkspace = 0 + let filename = ctrlspace#util#WorkspaceFile() + let lines = [] + let inWorkspace = 0 - let workspaceStartMarker = "CS_WORKSPACE_BEGIN: " . a:name - let workspaceEndMarker = "CS_WORKSPACE_END: " . a:name + let workspaceStartMarker = "CS_WORKSPACE_BEGIN: " . a:name + let workspaceEndMarker = "CS_WORKSPACE_END: " . a:name - if filereadable(filename) - for oldLine in readfile(filename) - if oldLine ==# workspaceStartMarker - let inWorkspace = 1 - endif + if filereadable(filename) + for oldLine in readfile(filename) + if oldLine ==# workspaceStartMarker + let inWorkspace = 1 + endif - if !inWorkspace - call add(lines, oldLine) - endif + if !inWorkspace + call add(lines, oldLine) + endif - if oldLine ==# workspaceEndMarker - let inWorkspace = 0 - endif - endfor - endif + if oldLine ==# workspaceEndMarker + let inWorkspace = 0 + endif + endfor + endif - call writefile(lines, filename) + call writefile(lines, filename) - if s:modes.Workspace.Data.Active.Name ==# a:name && s:modes.Workspace.Data.Active.Root ==# ctrlspace#roots#CurrentProjectRoot() - call ctrlspace#workspaces#SetActiveWorkspaceName(a:name, "") - endif + if s:modes.Workspace.Data.Active.Name ==# a:name && s:modes.Workspace.Data.Active.Root ==# ctrlspace#roots#CurrentProjectRoot() + call ctrlspace#workspaces#SetActiveWorkspaceName(a:name, "") + endif - call ctrlspace#workspaces#SetWorkspaceNames() + call ctrlspace#workspaces#SetWorkspaceNames() - if empty(s:workspaces) - call ctrlspace#window#Kill(0, 1) - else - call ctrlspace#window#Kill(0, 0) - call ctrlspace#window#Toggle(1) - endif + if empty(s:workspaces) + call ctrlspace#window#Kill(0, 1) + else + call ctrlspace#window#Kill(0, 0) + call ctrlspace#window#Toggle(1) + endif - call ctrlspace#ui#DelayedMsg("Workspace '" . a:name . "' has been deleted.") + call ctrlspace#ui#DelayedMsg("Workspace '" . a:name . "' has been deleted.") - return 1 + return 1 endfunction " bang == 0) load " bang == 1) append -function! ctrlspace#workspaces#LoadWorkspace(bang, name) - if !ctrlspace#roots#ProjectRootFound() - return 0 - endif - - call ctrlspace#util#HandleVimSettings("start") - - let cwdSave = fnamemodify(".", ":p:h") - silent! exe "cd " . fnameescape(ctrlspace#roots#CurrentProjectRoot()) - - let filename = ctrlspace#util#WorkspaceFile() - - if !filereadable(filename) - silent! exe "cd " . fnameescape(cwdSave) - return 0 - endif - - let oldLines = readfile(filename) - - if empty(a:name) - let name = "" - - for line in oldLines - if line =~? "CS_LAST_WORKSPACE: " - let name = line[19:] - break - endif - endfor - - if empty(name) - silent! exe "cd " . fnameescape(cwdSave) - return 0 - endif - else - let name = a:name - endif - - let startMarker = "CS_WORKSPACE_BEGIN: " . name - let endMarker = "CS_WORKSPACE_END: " . name - - let lines = [] - let inWorkspace = 0 - - for ol in oldLines - if ol ==# startMarker - let inWorkspace = 1 - elseif ol ==# endMarker - let inWorkspace = 0 - elseif inWorkspace - let ol = substitute(ol, "let t:ctrlspace_label", "let t:CtrlSpaceLabel", "") - let ol = substitute(ol, "let t:ctrlspace_autotab", "let t:CtrlSpaceAutotab", "") - call add(lines, ol) - endif - endfor - - if empty(lines) - call ctrlspace#ui#Msg("Workspace '" . name . "' not found in file '" . filename . "'.") - call ctrlspace#workspaces#SetWorkspaceNames() - silent! exe "cd " . fnameescape(cwdSave) - return 0 - endif - - call s:execWorkspaceCommands(a:bang, name, lines) - - if !a:bang - let s:modes.Workspace.Data.Active.Digest = ctrlspace#workspaces#CreateDigest() - let msg = "Workspace '" . name . "' has been loaded." - else - let s:modes.Workspace.Data.Active.Digest = "" - let msg = "Workspace '" . name . "' has been appended." - endif - - call ctrlspace#ui#Msg(msg) - call ctrlspace#ui#DelayedMsg(msg) - - silent! exe "cd " . fnameescape(cwdSave) - - call ctrlspace#util#HandleVimSettings("stop") - - return 1 +function! ctrlspace#workspaces#LoadWorkspace(bang, name) abort + if !ctrlspace#roots#ProjectRootFound() + return 0 + endif + + call ctrlspace#util#HandleVimSettings("start") + + let cwdSave = fnamemodify(".", ":p:h") + silent! exe "cd " . fnameescape(ctrlspace#roots#CurrentProjectRoot()) + + let filename = ctrlspace#util#WorkspaceFile() + + if !filereadable(filename) + silent! exe "cd " . fnameescape(cwdSave) + return 0 + endif + + let oldLines = readfile(filename) + + if empty(a:name) + let name = "" + + for line in oldLines + if line =~? "CS_LAST_WORKSPACE: " + let name = line[19:] + break + endif + endfor + + if empty(name) + silent! exe "cd " . fnameescape(cwdSave) + return 0 + endif + else + let name = a:name + endif + + let startMarker = "CS_WORKSPACE_BEGIN: " . name + let endMarker = "CS_WORKSPACE_END: " . name + + let lines = [] + let inWorkspace = 0 + + for ol in oldLines + if ol ==# startMarker + let inWorkspace = 1 + elseif ol ==# endMarker + let inWorkspace = 0 + elseif inWorkspace + let ol = substitute(ol, "let t:ctrlspace_label", "let t:CtrlSpaceLabel", "") + let ol = substitute(ol, "let t:ctrlspace_autotab", "let t:CtrlSpaceAutotab", "") + call add(lines, ol) + endif + endfor + + if empty(lines) + call ctrlspace#ui#Msg("Workspace '" . name . "' not found in file '" . filename . "'.") + call ctrlspace#workspaces#SetWorkspaceNames() + silent! exe "cd " . fnameescape(cwdSave) + return 0 + endif + + call s:execWorkspaceCommands(a:bang, name, lines) + + if !a:bang + let s:modes.Workspace.Data.Active.Digest = ctrlspace#workspaces#CreateDigest() + let msg = "Workspace '" . name . "' has been loaded." + else + let s:modes.Workspace.Data.Active.Digest = "" + let msg = "Workspace '" . name . "' has been appended." + endif + + call ctrlspace#ui#Msg(msg) + call ctrlspace#ui#DelayedMsg(msg) + + silent! exe "cd " . fnameescape(cwdSave) + + call ctrlspace#util#HandleVimSettings("stop") + + return 1 endfunction -function! s:execWorkspaceCommands(bang, name, lines) - let commands = [] +function! s:execWorkspaceCommands(bang, name, lines) abort + let commands = [] - if !a:bang - call ctrlspace#ui#Msg("Loading workspace '" . a:name . "'...") - call add(commands, "tabe") - call add(commands, "tabo!") - call add(commands, "call ctrlspace#buffers#DeleteHiddenNonameBuffers(1)") - call add(commands, "call ctrlspace#buffers#DeleteForeignBuffers(1)") - call ctrlspace#workspaces#SetActiveWorkspaceName(a:name) - else - let curTab = tabpagenr() - call ctrlspace#ui#Msg("Appending workspace '" . a:name . "'...") - call add(commands, "tabe") - endif + if !a:bang + call ctrlspace#ui#Msg("Loading workspace '" . a:name . "'...") + call add(commands, "tabe") + call add(commands, "tabo!") + call add(commands, "call ctrlspace#buffers#DeleteHiddenNonameBuffers(1)") + call add(commands, "call ctrlspace#buffers#DeleteForeignBuffers(1)") + call ctrlspace#workspaces#SetActiveWorkspaceName(a:name) + else + let curTab = tabpagenr() + call ctrlspace#ui#Msg("Appending workspace '" . a:name . "'...") + call add(commands, "tabe") + endif - call writefile(a:lines, "CS_SESSION") + call writefile(a:lines, "CS_SESSION") - call add(commands, "source CS_SESSION") - call add(commands, "redraw!") + call add(commands, "source CS_SESSION") + call add(commands, "redraw!") - if a:bang - call add(commands, "normal! " . curTab . "gt") - endif + if a:bang + call add(commands, "normal! " . curTab . "gt") + endif - for c in commands - silent exe c - endfor + for c in commands + silent exe c + endfor - call delete("CS_SESSION") -endfunction - -function! ctrlspace#workspaces#SaveWorkspace(name) - if !ctrlspace#roots#ProjectRootFound() - return 0 - endif - - call ctrlspace#util#HandleVimSettings("start") - - let cwdSave = fnamemodify(".", ":p:h") - let root = ctrlspace#roots#CurrentProjectRoot() - - silent! exe "cd " . fnameescape(root) - - if empty(a:name) - if !empty(s:modes.Workspace.Data.Active.Name) && s:modes.Workspace.Data.Active.Root ==# root - let name = s:modes.Workspace.Data.Active.Name - else - silent! exe "cd " . fnameescape(cwdSave) - call ctrlspace#util#HandleVimSettings("stop") - call ctrlspace#ui#Msg("Nothing to save.") - return 0 - endif - else - let name = a:name - endif - - let filename = ctrlspace#util#WorkspaceFile() - let lastTab = tabpagenr("$") - - let lines = [] - let inWorkspace = 0 - - let startMarker = "CS_WORKSPACE_BEGIN: " . name - let endMarker = "CS_WORKSPACE_END: " . name - - if filereadable(filename) - for oldLine in readfile(filename) - if oldLine ==# startMarker - let inWorkspace = 1 - endif - - if !inWorkspace - call add(lines, oldLine) - endif - - if oldLine ==# endMarker - let inWorkspace = 0 - endif - endfor - endif - - call add(lines, startMarker) - - let ssopSave = &ssop - set ssop=winsize,tabpages,buffers,sesdir - - let tabData = [] - - for t in range(1, lastTab) - let data = { - \ "label": ctrlspace#util#Gettabvar(t, "CtrlSpaceLabel"), - \ "autotab": ctrlspace#util#GettabvarWithDefault(t, "CtrlSpaceAutotab", 0) - \ } - - let ctrlspaceList = ctrlspace#api#Buffers(t) - - let bufs = [] - - for [nr, bname] in items(ctrlspaceList) - let bufname = fnamemodify(bname, ":.") + call ctrlspace#util#ChDir(fnamemodify(".", ":p:h")) - if !filereadable(bufname) - continue - endif - - call add(bufs, bufname) - endfor - - let data.bufs = bufs - call add(tabData, data) - endfor - - silent! exe "mksession! CS_SESSION" - - if !filereadable("CS_SESSION") - silent! exe "cd " . fnameescape(cwdSave) - silent! exe "set ssop=" . ssopSave - - call ctrlspace#util#HandleVimSettings("stop") - call ctrlspace#ui#Msg("Workspace '" . name . "' cannot be saved at this moment.") - return 0 - endif - - let tabIndex = 0 - - for cmd in readfile("CS_SESSION") - if cmd =~# "^lcd" - continue - elseif ((cmd =~# "^edit") && (tabIndex == 0)) || (cmd =~# "^tabnew") || (cmd =~# "^tabedit") - let data = tabData[tabIndex] - - if tabIndex > 0 - call add(lines, cmd) - endif - - for b in data.bufs - call add(lines, "edit " . fnameescape(b)) - endfor - - if !empty(data.label) - call add(lines, "let t:CtrlSpaceLabel = '" . substitute(data.label, "'", "''","g") . "'") - endif - - if !empty(data.autotab) - call add(lines, "let t:CtrlSpaceAutotab = " . data.autotab) - endif - - if tabIndex == 0 - call add(lines, cmd) - elseif cmd =~# "^tabedit" - call add(lines, cmd[3:]) "make edit from tabedit - endif - - let tabIndex += 1 - else - let baddList = matchlist(cmd, "\\m^badd \+\\d* \\(.*\\)$") - - if !(exists("baddList[1]") && !empty(baddList[1]) && !filereadable(baddList[1])) - call add(lines, cmd) - endif - endif - endfor - - call add(lines, endMarker) - - call writefile(lines, filename) - call delete("CS_SESSION") - - call ctrlspace#workspaces#SetActiveWorkspaceName(name, ctrlspace#workspaces#CreateDigest()) - call ctrlspace#workspaces#SetWorkspaceNames() + call delete("CS_SESSION") +endfunction - silent! exe "cd " . fnameescape(cwdSave) - silent! exe "set ssop=" . ssopSave +function! ctrlspace#workspaces#SaveWorkspace(name) abort + if !ctrlspace#roots#ProjectRootFound() + return 0 + endif - call ctrlspace#util#HandleVimSettings("stop") + call ctrlspace#util#HandleVimSettings("start") - let msg = "Workspace '" . name . "' has been saved." - call ctrlspace#ui#Msg(msg) - call ctrlspace#ui#DelayedMsg(msg) + let cwdSave = fnamemodify(".", ":p:h") + let root = ctrlspace#roots#CurrentProjectRoot() - return 1 + silent! exe "cd " . fnameescape(root) + + if empty(a:name) + if !empty(s:modes.Workspace.Data.Active.Name) && s:modes.Workspace.Data.Active.Root ==# root + let name = s:modes.Workspace.Data.Active.Name + else + silent! exe "cd " . fnameescape(cwdSave) + call ctrlspace#util#HandleVimSettings("stop") + call ctrlspace#ui#Msg("Nothing to save.") + return 0 + endif + else + let name = a:name + endif + + let filename = ctrlspace#util#WorkspaceFile() + let lastTab = tabpagenr("$") + + let lines = [] + let inWorkspace = 0 + + let startMarker = "CS_WORKSPACE_BEGIN: " . name + let endMarker = "CS_WORKSPACE_END: " . name + + if filereadable(filename) + for oldLine in readfile(filename) + if oldLine ==# startMarker + let inWorkspace = 1 + endif + + if !inWorkspace + call add(lines, oldLine) + endif + + if oldLine ==# endMarker + let inWorkspace = 0 + endif + endfor + endif + + call add(lines, startMarker) + + let ssopSave = &ssop + set ssop=winsize,tabpages,buffers,sesdir + + let tabData = [] + + for t in range(1, lastTab) + let data = { + \ "label": ctrlspace#util#Gettabvar(t, "CtrlSpaceLabel"), + \ "autotab": ctrlspace#util#GettabvarWithDefault(t, "CtrlSpaceAutotab", 0) + \ } + + let ctrlspaceList = ctrlspace#api#Buffers(t) + + let bufs = [] + + for [nr, bname] in items(ctrlspaceList) + let bufname = fnamemodify(bname, ":.") + + if !filereadable(bufname) + continue + endif + + call add(bufs, bufname) + endfor + + let data.bufs = bufs + call add(tabData, data) + endfor + + silent! exe "mksession! CS_SESSION" + + if !filereadable("CS_SESSION") + silent! exe "cd " . fnameescape(cwdSave) + silent! exe "set ssop=" . ssopSave + + call ctrlspace#util#HandleVimSettings("stop") + call ctrlspace#ui#Msg("Workspace '" . name . "' cannot be saved at this moment.") + return 0 + endif + + let tabIndex = 0 + + let config = ctrlspace#context#Configuration() + if filereadable(config.WorkspaceFile) + call add(lines, "cd " . fnameescape(root)) + let useWorkspaceFile = 1 + else + let useWorkspaceFile = 0 + endif + + for cmd in readfile("CS_SESSION") + if useWorkspaceFile && cmd ==# 'exe "cd " . escape(expand(" :p:h"), '' '')' + continue + elseif cmd =~# "^lcd " + continue + elseif cmd =~# "^badd\>" + let baddList = matchlist(cmd, '\v^badd \+\d+ (\f+)$') + if exists("baddList[1]") && filereadable(baddList[1]) + call add(lines, cmd) + endif + elseif + \ ((cmd =~# '^edit \f\+') && (tabIndex == 0)) + \ || ( (has('patch-8.1.149') || has('nvim-0.5')) && cmd ==# 'tabnext') + \ || (!(has('patch-8.1.149') || has('nvim-0.5')) && cmd =~# '^tabedit \f\+') + " NB: check patch-8.1.149 for backend vim mksession change + " NB: check nvim-0.5 for port of patch-8.1.149 from Vim to Nvim + let data = tabData[tabIndex] + + if cmd =~# '^tabedit \f\+' + call add(lines, 'tabedit') + elseif cmd ==# 'tabnext' + call add(lines, cmd) + endif + + for b in data.bufs + call add(lines, 'edit ' . fnameescape(b)) + endfor + + if cmd =~# '^tabedit \f\+' + " turn 'tabedit ...' into 'edit ...' + call add(lines, cmd[3:]) + endif + + if !empty(data.label) + call add(lines, "let t:CtrlSpaceLabel = '" . substitute(data.label, "'", "''","g") . "'") + endif + if !empty(data.autotab) + call add(lines, "let t:CtrlSpaceAutotab = " . data.autotab) + endif + + let tabIndex += 1 + else + call add(lines, cmd) + endif + endfor + + call add(lines, endMarker) + + call writefile(lines, filename) + call delete("CS_SESSION") + + call ctrlspace#workspaces#SetActiveWorkspaceName(name, ctrlspace#workspaces#CreateDigest()) + call ctrlspace#workspaces#SetWorkspaceNames() + + silent! exe "cd " . fnameescape(cwdSave) + silent! exe "set ssop=" . ssopSave + + call ctrlspace#util#HandleVimSettings("stop") + + let msg = "Workspace '" . name . "' has been saved." + call ctrlspace#ui#Msg(msg) + call ctrlspace#ui#DelayedMsg(msg) + + return 1 endfunction -function! ctrlspace#workspaces#CreateDigest() - let useNossl = exists("b:nosslSave") && b:nosslSave +function! ctrlspace#workspaces#CreateDigest() abort + let useNossl = exists("b:nosslSave") && b:nosslSave - if useNossl - set nossl - endif + if useNossl + set nossl + endif - let cpoSave = &cpo + let cpoSave = &cpo - set cpo&vim + set cpo&vim - let lines = [] + let lines = [] - for t in range(1, tabpagenr("$")) - let line = [t, ctrlspace#util#Gettabvar(t, "CtrlSpaceLabel")] - let bufs = [] - let visibles = [] + for t in range(1, tabpagenr("$")) + let line = [t, ctrlspace#util#Gettabvar(t, "CtrlSpaceLabel")] + let bufs = [] + let visibles = [] - let tabBuffers = ctrlspace#api#Buffers(t) + let tabBuffers = ctrlspace#api#Buffers(t) - for bname in values(tabBuffers) - let bufname = fnamemodify(bname, ":p") + for bname in values(tabBuffers) + let bufname = fnamemodify(bname, ":p") - if !filereadable(bufname) - continue - endif + if !filereadable(bufname) + continue + endif - call add(bufs, bufname) - endfor + call add(bufs, bufname) + endfor - for visibleBuf in tabpagebuflist(t) - if exists("tabBuffers[visibleBuf]") - let bufname = fnamemodify(tabBuffers[visibleBuf], ":p") + for visibleBuf in tabpagebuflist(t) + if exists("tabBuffers[visibleBuf]") + let bufname = fnamemodify(tabBuffers[visibleBuf], ":p") - if !filereadable(bufname) - continue - endif + if !filereadable(bufname) + continue + endif - call add(visibles, bufname) - endif - endfor + call add(visibles, bufname) + endif + endfor - call add(line, join(bufs, "|")) - call add(line, join(visibles, "|")) - call add(lines, join(line, ",")) - endfor + call add(line, join(bufs, "|")) + call add(line, join(visibles, "|")) + call add(lines, join(line, ",")) + endfor - let digest = join(lines, "&&&") + let digest = join(lines, "&&&") - if useNossl - set ssl - endif + if useNossl + set ssl + endif - let &cpo = cpoSave + let &cpo = cpoSave - return digest + return digest endfunction diff --git a/bin/file_engine_darwin_386 b/bin/file_engine_darwin_386 deleted file mode 100755 index 02ed58a7..00000000 Binary files a/bin/file_engine_darwin_386 and /dev/null differ diff --git a/bin/file_engine_darwin_amd64 b/bin/file_engine_darwin_amd64 index 67fc16ea..0152b0c4 100755 Binary files a/bin/file_engine_darwin_amd64 and b/bin/file_engine_darwin_amd64 differ diff --git a/bin/file_engine_darwin_arm b/bin/file_engine_darwin_arm new file mode 100755 index 00000000..c9eb9e51 Binary files /dev/null and b/bin/file_engine_darwin_arm differ diff --git a/bin/file_engine_freebsd_386 b/bin/file_engine_freebsd_386 deleted file mode 100755 index fae327ff..00000000 Binary files a/bin/file_engine_freebsd_386 and /dev/null differ diff --git a/bin/file_engine_freebsd_amd64 b/bin/file_engine_freebsd_amd64 deleted file mode 100755 index 6c39a91c..00000000 Binary files a/bin/file_engine_freebsd_amd64 and /dev/null differ diff --git a/bin/file_engine_freebsd_arm b/bin/file_engine_freebsd_arm deleted file mode 100755 index c6f46d4c..00000000 Binary files a/bin/file_engine_freebsd_arm and /dev/null differ diff --git a/bin/file_engine_linux_386 b/bin/file_engine_linux_386 deleted file mode 100755 index b703965a..00000000 Binary files a/bin/file_engine_linux_386 and /dev/null differ diff --git a/bin/file_engine_linux_amd64 b/bin/file_engine_linux_amd64 index 627be60e..56022049 100755 Binary files a/bin/file_engine_linux_amd64 and b/bin/file_engine_linux_amd64 differ diff --git a/bin/file_engine_linux_arm b/bin/file_engine_linux_arm index 75ac5d9d..665242ad 100755 Binary files a/bin/file_engine_linux_arm and b/bin/file_engine_linux_arm differ diff --git a/bin/file_engine_netbsd_386 b/bin/file_engine_netbsd_386 deleted file mode 100755 index 17fa4065..00000000 Binary files a/bin/file_engine_netbsd_386 and /dev/null differ diff --git a/bin/file_engine_netbsd_amd64 b/bin/file_engine_netbsd_amd64 deleted file mode 100755 index c36d3ff3..00000000 Binary files a/bin/file_engine_netbsd_amd64 and /dev/null differ diff --git a/bin/file_engine_netbsd_arm b/bin/file_engine_netbsd_arm deleted file mode 100755 index 38c62ec0..00000000 Binary files a/bin/file_engine_netbsd_arm and /dev/null differ diff --git a/bin/file_engine_openbsd_386 b/bin/file_engine_openbsd_386 deleted file mode 100755 index 63df97c5..00000000 Binary files a/bin/file_engine_openbsd_386 and /dev/null differ diff --git a/bin/file_engine_openbsd_amd64 b/bin/file_engine_openbsd_amd64 deleted file mode 100755 index 67b2418c..00000000 Binary files a/bin/file_engine_openbsd_amd64 and /dev/null differ diff --git a/bin/file_engine_windows_386.exe b/bin/file_engine_windows_386.exe deleted file mode 100755 index 12fa7b01..00000000 Binary files a/bin/file_engine_windows_386.exe and /dev/null differ diff --git a/bin/file_engine_windows_amd64.exe b/bin/file_engine_windows_amd64.exe index 0575d0cb..b2738942 100755 Binary files a/bin/file_engine_windows_amd64.exe and b/bin/file_engine_windows_amd64.exe differ diff --git a/doc/ctrlspace.txt b/doc/ctrlspace.txt index bc5cbbb7..22d5f17b 100644 --- a/doc/ctrlspace.txt +++ b/doc/ctrlspace.txt @@ -1,4 +1,4 @@ -*ctrlspace.txt* For Vim version 7.3+ Last change: 2015.11.17 +*ctrlspace.txt* For Vim version 7.3+ Last change: 2020.12.01 *ctrlspace* *vim-ctrlspace* @@ -16,14 +16,13 @@ -Copyright (c) 2013-2015 Szymon Wrozynski and Contributors +Copyright (c) 2013-2020 Szymon Wrozynski and Contributors ========================================================================== Table of Contents *ctrlspace-toc* 1. Overview |ctrlspace-overview| - 1.1 Version 5 |ctrlspace-version-5| 2. Idea by Analogy |ctrlspace-idea| 3. Getting Started |ctrlspace-getting-started| 3.1 Installation |ctrlspace-installation| @@ -61,22 +60,27 @@ Table of Contents *ctrlspace-toc* 7.5 g:CtrlSpaceKeys |g:CtrlSpaceKeys| 7.6 g:CtrlSpaceHelp |g:CtrlSpaceHelp| 7.7 g:CtrlSpaceGlobCommand |g:CtrlSpaceGlobCommand| - 7.8 g:CtrlSpaceUseTabline |g:CtrlSpaceUseTabline| - 7.9 g:CtrlSpaceUseArrowsInTerm |g:CtrlSpaceUseArrowsInTerm| - 7.10 g:CtrlSpaceUseMouseAndArrowsInTerm + 7.8 g:CtrlSpaceEnableFilesCache |g:CtrlSpaceEnableFilesCache| + 7.9 g:CtrlSpaceUseTabline |g:CtrlSpaceUseTabline| + 7.10 g:CtrlSpaceUseArrowsInTerm |g:CtrlSpaceUseArrowsInTerm| + 7.11 g:CtrlSpaceUseMouseAndArrowsInTerm |g:CtrlSpaceUseMouseAndArrowsInTerm| - 7.11 g:CtrlSpaceSaveWorkspaceOnExit |g:CtrlSpaceSaveWorkspaceOnExit| - 7.12 g:CtrlSpaceSaveWorkspaceOnSwitch |g:CtrlSpaceSaveWorkspaceOnSwitch| - 7.13 g:CtrlSpaceLoadLastWorkspaceOnStart + 7.12 g:CtrlSpaceSaveWorkspaceOnExit |g:CtrlSpaceSaveWorkspaceOnExit| + 7.13 g:CtrlSpaceSaveWorkspaceOnSwitch |g:CtrlSpaceSaveWorkspaceOnSwitch| + 7.14 g:CtrlSpaceLoadLastWorkspaceOnStart |g:CtrlSpaceLoadLastWorkspaceOnStart| - 7.14 g:CtrlSpaceCacheDir |g:CtrlSpaceCacheDir| - 7.15 g:CtrlSpaceProjectRootMarkers |g:CtrlSpaceProjectRootMarkers| - 7.16 g:CtrlSpaceUseUnicode |g:CtrlSpaceUseUnicode| - 7.17 g:CtrlSpaceSymbols |g:CtrlSpaceSymbols| - 7.18 g:CtrlSpaceIgnoredFiles |g:CtrlSpaceIgnoredFiles| - 7.19 g:CtrlSpaceStatuslineFunction |g:CtrlSpaceStatuslineFunction| - 7.20 g:CtrlSpaceSearchTiming |g:CtrlSpaceSearchTiming| - 7.21 g:CtrlSpaceFileEngine |g:CtrlSpaceFileEngine| + 7.15 g:CtrlSpaceEnableBufferTabWrapAround + |g:CtrlSpaceEnableBufferTabWrapAround| + 7.16 g:CtrlSpaceCacheDir |g:CtrlSpaceCacheDir| + 7.17 g:CtrlSpaceProjectRootMarkers |g:CtrlSpaceProjectRootMarkers| + 7.18 g:CtrlSpaceUseUnicode |g:CtrlSpaceUseUnicode| + 7.19 g:CtrlSpaceSymbols |g:CtrlSpaceSymbols| + 7.20 g:CtrlSpaceIgnoredFiles |g:CtrlSpaceIgnoredFiles| + 7.21 g:CtrlSpaceStatuslineFunction |g:CtrlSpaceStatuslineFunction| + 7.22 g:CtrlSpaceSearchTiming |g:CtrlSpaceSearchTiming| + 7.23 g:CtrlSpaceFileEngine |g:CtrlSpaceFileEngine| + 7.24 g:CtrlSpaceSortHelp |g:CtrlSpaceSortHelp| + 7.25 g:CtrlSpaceWorkspaceFile |g:CtrlSpaceWorkspaceFile| 8. API |ctrlspace-api| 8.1 Commands |ctrlspace-commands| 8.1.1 :CtrlSpace [keys] |:CtrlSpace| @@ -107,7 +111,8 @@ Table of Contents *ctrlspace-toc* 8.2.11 ctrlspace#api#TabList() |ctrlspace#api#TabList()| 8.2.12 ctrlspace#api#BufNr() |ctrlspace#api#BufNr()| 9. File Engine Specifications |ctrlspace-engine-specs| -10. Authors and License |ctrlspace-authors-and-license| +10. FAQ |ctrlspace-FAQ| +11. Authors and License |ctrlspace-authors-and-license| ========================================================================== @@ -125,44 +130,12 @@ The plugin name follows the convention of naming fuzzy search plugins after their default mappings (like Command-T or CtrlP), hence the plugin mapping is by default `Ctrl` + `Space`. -If you like the plugin please don't forget to leave a star for this -project! This will help me to estimate the plugin popularity and plan -further development :). +If you have already starred this repo, thank you! -If you have already starred this repo, thank you! Thanks to you it's my -pet project now :). If you have a question, a feature request, or a new -idea, don't hesitate to post new issues or pull requests. Collaboration -is the most awesome thing in the open source community! +If you have a question, a feature request, or a new +idea, don't hesitate to post new issues or pull requests. - |ctrlspace-toc| --------------------------------------------------------------------------- - -1.1 Version 5 *ctrlspace-version-5* - -Vim-CtrlSpace started over 2 years ago as a fork of another plugin and the -Version 5 is the result of the experience gained during that period and -cooperation with the community. - -Version 5 is the biggest upgrade in the plugin history. All plugin code -has been rewritten from scratch taking user feedback as a great resource -of ideas and challenges into account. Thanks to users the plugin has -configurable key mappings and allows you to handle projects with 100 000 -files! - -In case you're curious, Vim-CtrlSpace 5 took me 5 months of spare evenings -to complete :). - -The most exciting features of Vim-CtrlSpace 5 are: - - * better, modular, and extensible code base - * simplified, well thought-out, and clear design - * new fuzzy search engine for files (written in Go) - * more effective and responsive behavior - * fine-grained configuration - -Version 5 is not backward compatible. All configuration variables and API -functions have been renamed. Please check |ctrlspace-configuration| for -more info. +Collaboration is the most awesome thing in the open source community! |ctrlspace-toc| ========================================================================== @@ -242,11 +215,12 @@ You can also clone the repository to your `.vim` directory: > 3.2 Basic Settings *ctrlspace-basic-settings* -First please make sure that you set `nocompatible` and `hidden` options -(required by the plugin) in your `.vimrc`: > +First please make sure that you set `nocompatible` and `hidden` options, +and set `encoding=utf-8` (as required by the plugin) in your `.vimrc`: > set nocompatible set hidden + set encoding=utf-8 < If you feel brave enough turn off tabline: > @@ -668,8 +642,13 @@ Load Mode. To open Workspace List press . Then press to select the mode (toggles between Save and Load modes),, <=> to rename, and to delete. -The word "workspace" can be considered a synonym of a "session". The -ability of having so many sessions available at hand creates a lot of +The word "workspace" can be considered a synonym of a "session" and all +your buffers, tabs, and tab layouts are persisted. It's like taking a +picture of your desk with an instant camera. + +You can save multiple workspaces per project with Workspace List. + +The ability of having so many sessions available at hand creates a lot of interesting use cases! For example, you can have a workspace for each task or feature you are working on. It's very easy to switch from one workspace to another. @@ -940,7 +919,25 @@ You can even make `Ag` to show hidden files by providing `--hidden` option: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.8 *g:CtrlSpaceUseTabline* +7.8 *g:CtrlSpaceEnableFilesCache* + +Enable to store a cache file (cs_files) inside .git/ of each project. More +suited for very large projects (>10k+ files at least, likely even more). + +Disable to load project files by simply re-globbing each time FILE mode is +activated. More suited for small to medium sized projects, or for projects +where switching to branches with different file layouts is common. + +Supported globbers are: rg, fd & ag (auto-detected in that order) + +Default value: > + + let g:CtrlSpaceEnableFilesCache = 1 +< + |ctrlspace-toc| +-------------------------------------------------------------------------- + +7.9 *g:CtrlSpaceUseTabline* Should Vim-CtrlSpace change your default tabline to its own? @@ -951,7 +948,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.9 *g:CtrlSpaceUseArrowsInTerm* +7.10 *g:CtrlSpaceUseArrowsInTerm* Should the plugin use arrows and , , , keys in a terminal Vim. @@ -963,7 +960,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.10 *g:CtrlSpaceUseMouseAndArrowsInTerm* +7.11 *g:CtrlSpaceUseMouseAndArrowsInTerm* Should the plugin use mouse, arrows and , , , keys in a terminal Vim. Disables the key if turned on. @@ -975,7 +972,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.11 *g:CtrlSpaceSaveWorkspaceOnExit* +7.12 *g:CtrlSpaceSaveWorkspaceOnExit* Saves the active workspace (if present) on Vim quit. If this option is set, the Vim quit ( ) action in the plugin does not check for workspace @@ -988,7 +985,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.12 *g:CtrlSpaceSaveWorkspaceOnSwitch* +7.13 *g:CtrlSpaceSaveWorkspaceOnSwitch* Saves the active workspace (if present) on switching to another workspace or clearing (closing) the current one. If this option is set, the plugin @@ -1001,7 +998,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.13 *g:CtrlSpaceLoadLastWorkspaceOnStart* +7.14 *g:CtrlSpaceLoadLastWorkspaceOnStart* Loads the last active workspace (if found) on Vim startup. @@ -1012,7 +1009,24 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.14 *g:CtrlSpaceCacheDir* +7.15 *g:CtrlSpaceEnableBufferTabWrapAround* + +Determines whether changing (i.e. switching, moving or copying) buffers or +tabs in BUFFER and TAB LIST modes wraps-around when the active/selected +buffer/tab is the first or last one. + +For instance, when enabled, switching to the previous tab from the first +tab in BUFFER LIST mode (using '[' key) takes one to the last tab. While +if this option is disabled, the same key performs a null operation. + +Default value: > + + let g:CtrlSpaceEnableBufferTabWrapAround = 1 +< + |ctrlspace-toc| +-------------------------------------------------------------------------- + +7.16 *g:CtrlSpaceCacheDir* A directory for the Vim-CtrlSpace cache file (`.cs_cache`). By default your `$HOME` directory will be used. @@ -1024,7 +1038,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.15 *g:CtrlSpaceProjectRootMarkers* +7.17 *g:CtrlSpaceProjectRootMarkers* An array of directory names which presence indicates the project root. If no marker is found, you will be asked to confirm the project root @@ -1042,13 +1056,14 @@ Default value: > \ ".svn", \ ".bzr", \ "_darcs", - \ "CVS" + \ "CVS", + \ ".cs_workspaces" \ ] < |ctrlspace-toc| -------------------------------------------------------------------------- -7.16 *g:CtrlSpaceUseUnicode* +7.18 *g:CtrlSpaceUseUnicode* Set to `1` if you want to use Unicode symbols, or `0` otherwise. @@ -1059,7 +1074,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.17 *g:CtrlSpaceSymbols* +7.19 *g:CtrlSpaceSymbols* Enables you to provide your own symbols. It's useful if, for example, your font doesn't contain enough symbols or the glyphs are poorly rendered. @@ -1099,7 +1114,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.18 *g:CtrlSpaceIgnoredFiles* +7.20 *g:CtrlSpaceIgnoredFiles* The expression used to ignore some files during file collecting. It is used in addition to the `wildignore` option in Vim (see |wildignore|). @@ -1114,7 +1129,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.19 *g:CtrlSpaceStatuslineFunction* +7.21 *g:CtrlSpaceStatuslineFunction* Allows to provide custom statusline function used by the CtrlSpace window. @@ -1125,7 +1140,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.20 *g:CtrlSpaceSearchTiming* +7.22 *g:CtrlSpaceSearchTiming* Allows you to adjust search smoothness by providing a delay on search input. By default the delay is set to 200 ms. That way the plugin ensures @@ -1138,7 +1153,7 @@ Default value: > |ctrlspace-toc| -------------------------------------------------------------------------- -7.21 *g:CtrlSpaceFileEngine* +7.23 *g:CtrlSpaceFileEngine* The plugin provides fuzzy search engine written in Go and compiled for several architectures: @@ -1151,6 +1166,11 @@ several architectures: * `file_engine_linux_386` * `file_engine_linux_amd64` * `file_engine_linux_arm` + * `file_engine_linux_mips` + * `file_engine_linux_mips64` + * `file_engine_linux_mips64le` + * `file_engine_linux_mipsle` + * `file_engine_linux_s390x` * `file_engine_netbsd_386` * `file_engine_netbsd_amd64` * `file_engine_netbsd_arm` @@ -1188,6 +1208,39 @@ Default value: > let g:CtrlSpaceFileEngine = "auto" < + |ctrlspace-toc| +-------------------------------------------------------------------------- + +7.24 *g:CtrlSpaceSortHelp* + +Enables sorting the lines in help mode by the description. This is disabled by +default for backwards compatibility. In a future version sorting might become +the new default though. + +Default value: > + + let g:CtrlSpaceSortHelp = 0 +< + |ctrlspace-toc| +-------------------------------------------------------------------------- + +7.25 *g:CtrlSpaceWorkspaceFile* + +Set a custom path for the workspace file to store all your workspace +configurations for different projects. If unset, the default internal file +path 'cs_workspaces' in the project root directory is used. +It is unset by default. + +Example: > + + let g:CtrlSpaceWorkspaceFile = '~/.vim/ctrlspace_workspaces' +< + +Note: Make sure the directory exists before setting this variable. The plugin +will not automatically create the directory for you. + +Default: '' (empty string, which means use the default internal file path) + |ctrlspace-toc| ========================================================================== @@ -1225,8 +1278,8 @@ in the plugin window. 8.1.2 *:CtrlSpaceGoUp* -Opens the previous buffer from the current Buffer List in Single Mode -(without opening the plugin window). +Opens the previous buffer from the current Buffer List in Single Mode (without +opening the plugin window). |ctrlspace-toc| -------------------------------------------------------------------------- @@ -1443,6 +1496,15 @@ pure Vim Script (like `CtrlP`) thus it affects the performance too. General Assumptions~ +The file engine binaries have been compiled for various OS's and CPU +types, but only those for Linux, MacOS and Windows on 64 bit architectures +are available in the git repository. The other versions for their 32 bit +architecture counterparts, as well as for FreeBSD, NetBSD and OpenBSD +on 32 and 64 bit architectures can still be dowloaded from a specific +release `all_os_file_engines`, downloadable at: + + https://git.io/vim-ctrlspace-release-all_os_file_engines + By default the plugin shows at most 500 items per list and 200 when fuzzy searched. That rule is enforced by internal fuzzy searcher implementation and by the external engine written in Go. @@ -1564,9 +1626,20 @@ should be placed at the bottom (as last ones). |ctrlspace-toc| ========================================================================== -10. Authors and License *ctrlspace-authors-and-license* +10. FAQ *ctrlspace-FAQ* + +Q: How to delete a buffer while leaving the tab page intact? +A: Make good use of *CtrlSpace* [keys]! For example, the mapping +> + nnoremapQ : CtrlSpace p pcq +< + opens the alternate buffer instead and keeps the tab page. -Copyright (c) 2013-2015 Szymon Wrozynski and Contributors. +========================================================================== + +11. Authors and License *ctrlspace-authors-and-license* + +Copyright (c) 2013-2020 Szymon Wrozynski and Contributors. * https://github.com/vim-ctrlspace/vim-ctrlspace/commits/master @@ -1581,6 +1654,8 @@ Vim-Tabber by Jim Steward and Tabline by Matthew Kitt. Special thanks to Wojtek Ryrych (https://github.com/ryrych) for help and patience ;) and all Contributors. +See `CHANGELOG.md` and the `git log` for descriptions of significant changes. + |ctrlspace-toc| ========================================================================== diff --git a/plugin/ctrlspace.vim b/plugin/ctrlspace.vim index a7222728..2d0e82c3 100644 --- a/plugin/ctrlspace.vim +++ b/plugin/ctrlspace.vim @@ -31,32 +31,32 @@ scriptencoding utf-8 if exists("g:CtrlSpaceLoaded") - finish + finish endif let g:CtrlSpaceLoaded = 1 let s:errors = [] if &cp - call add(s:errors, "CtrlSpace requires 'nocompatible' option enabled!") + call add(s:errors, "CtrlSpace requires 'nocompatible' option enabled!") endif if !&hid - call add(s:errors, "CtrlSpace requires 'hidden' option enabled!") + call add(s:errors, "CtrlSpace requires 'hidden' option enabled!") endif if v:version < 703 - call add(s:errors, "CtrlSpace requires Vim 7.3 or higher!") + call add(s:errors, "CtrlSpace requires Vim 7.3 or higher!") endif if !empty(s:errors) - echohl WarningMsg - for msg in s:errors - echom msg - endfor - echohl None + echohl WarningMsg + for msg in s:errors + echom msg + endfor + echohl None - finish + finish endif call ctrlspace#init#Init()