Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes to workspace list and bookmark list #198

Open
wants to merge 32 commits into
base: pull-reqs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fefc793
20170903 - Change bookmark list as files bookmark
Sep 3, 2017
f7f5359
20170903 - Fix: can't add bookmark file of same directory; Fix: ctrls…
Sep 3, 2017
101cd84
20170904 - Do Not add directory of bookmark to project root list
Sep 3, 2017
5de6c01
20170905 - Change promot of add bookmark
Sep 4, 2017
6aa636c
20170905 - Change Add, Load, Save, Appen function of workspace list a…
Sep 4, 2017
016db1a
20170905 - Change workspace list to show all workspaces of all projec…
Sep 5, 2017
19f09ec
20170905 - Change the sort function of workspace list and bookmark list
Sep 5, 2017
5eb6694
20170905 - Add clearing redundance workspace function
Sep 5, 2017
76a938d
20170905 - Add keys-actions content for README.md
Sep 5, 2017
c14c9b5
20170906 - Add tabedit for bookmark
Sep 6, 2017
11fe225
20170906 - Change back that when it's empty list for bookmark and wor…
Sep 6, 2017
ee7fe89
20170907 - Add split open for bookmark list
Sep 7, 2017
c46dc31
20170912 - Change: display help into 2 blocks that are common keys an…
Sep 12, 2017
5658621
20170925 - Add: setlocal nofoldenable and setlocal foldcolumn=1
Sep 25, 2017
2d9fe46
20171012 - Update comment
Oct 12, 2017
3dfa815
docs(README.md): Update README.md
Oct 20, 2017
d1a87e5
refactor(workspace): Change the symbol of workspace
Oct 26, 2017
5f299c1
feat(WorkSpace, BookMark): Add sort mode
Oct 31, 2017
aff7205
refactor(WorkSpace, BookList): Use s.modes.SetData
Oct 31, 2017
3b206b3
fix(cs_cache): Store directory with /
Nov 1, 2017
93b309b
reat(WorkSpace): Auto add workspace found in project root
Nov 1, 2017
2452ad4
refactor(WorkSpace, BookMark): Remove ChDir
Nov 1, 2017
64185cf
style: Update comment
Nov 1, 2017
f355cf5
fix(WorkSpace): Add existed workspace to cs_cache file
Nov 2, 2017
8808aa4
refactor(WorkSpace): Use writeCacheWorkspaces
Nov 2, 2017
c72dfa9
refactor(WorkSpace, BookMark): Remove ChDir
Nov 1, 2017
c2b9843
refactor(WorkSpace): Change ctrlspacewindow#toggle postion
Nov 2, 2017
8871d01
fix(WorkSpace): Fix CtrlSpaceSaveWorkSpace command
Nov 2, 2017
7e62c61
fix(roots): Fix Save and Remove ProjectRoot command
Nov 2, 2017
36cff44
fix(WorkSpace): Remove not required writing cs_cache file
Nov 3, 2017
3ac8c27
style: fix style of files
Jan 30, 2018
7347c51
fix(roots): fix problem of projects path match
Mar 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tags
*.swp
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
<div align="center">
<img alt="Vim-CtrlSpace" src="https://raw.github.com/vim-ctrlspace/vim-ctrlspace/master/gfx/logo5.png" />
<img alt="Vim-CtrlSpace" src="https://raw.github.com/yehuohan/vim-ctrlspace/master/gfx/logo5.png" />
<br><br>
</div>


**This is a fork of [vim-ctrlspace](https://github.com/vim-ctrlspace/vim-ctrlspace). The main changes are listed following:**
- **(20170903) Change bookmark list as files bookmark list.**
All your bookmarked files will be listed with filename and filepath. For example, there 3 bookmarked files in the list in the picutre following.

<div align="center">
<img alt="Vim-CtrlSpace" src="https://raw.github.com/yehuohan/vim-ctrlspace/master/gfx/new_bm.png" />
</div>

| **Key** | **Action** |
| :---: | :--- |
| Tab, CR, Space | Edit bookmarked file (Tab - goto buffer, CR - close, Space - stay) |
| a | Add bookmark |
| d | Delete bookmark |
| t | Append bookmarked file in new tab |
| s | Append bookmarked file in split window |
| v | Append bookmarked file in vsplit window |
| g | Toggle sort mode between path and name |

- **(20170905) Change workspace list as all workspace list.**
Now workspace list will show all workspaces of projects with workspace name and projects path. For example, there 2 projects and 4 workspaces in the picture following.

<div align="center">
<img alt="Vim-CtrlSpace" src="https://raw.github.com/yehuohan/vim-ctrlspace/master/gfx/new_ws.png" />
</div>

| **Key** | **Action** |
| :---: | :--- |
| Tab, CR, Space | Load workspace (Tab - goto buffer, CR - close, Space - stay) |
| t | Append workspace in new tab |
| a | Add new workspace |
| s | Save workspace |
| d | Delete workspace |
| m, = | Rename workspace |
| g | Toggle sort mode between path and name |
| C | Clear all buffers and tabs of workspace |

<br><br>

---

Welcome to **Vim-CtrlSpace**, a comprehensive solution for your Vim editor
providing:

Expand Down Expand Up @@ -64,7 +105,7 @@ Vim-CtrlSpace interface is a window you can invoke by pressing
items with `<h>`, `<j>`, and `<CR>` keys.

<p align="center">
<img alt="Vim-CtrlSpace" src="https://raw.github.com/vim-ctrlspace/vim-ctrlspace/master/gfx/cs5_window.png" />
<img alt="Vim-CtrlSpace" src="https://raw.github.com/yehuohan/vim-ctrlspace/master/gfx/cs5_window.png" />
</p>

Generally speaking Vim-CtrlSpace can display 5 types of lists:
Expand Down
6 changes: 1 addition & 5 deletions autoload/ctrlspace/api.vim
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ function! ctrlspace#api#StatuslineModeSegment(...)
let clv = ctrlspace#modes#CurrentListView()

if clv.Name ==# "Workspace"
if clv.Data.SubMode ==# "load"
call add(statuslineElements, s:config.Symbols.WLoad)
elseif clv.Data.SubMode ==# "save"
call add(statuslineElements, s:config.Symbols.WSave)
endif
call add(statuslineElements, s:config.Symbols.WS)
elseif clv.Name ==# "Tab"
call add(statuslineElements, s:createStatusTabline())
elseif clv.Name ==# "Bookmark"
Expand Down
266 changes: 106 additions & 160 deletions autoload/ctrlspace/bookmarks.vim
Original file line number Diff line number Diff line change
@@ -1,202 +1,148 @@

let s:config = ctrlspace#context#Configuration()
let s:modes = ctrlspace#modes#Modes()
" s:bookmarks is for cache_bookmarks
let s:bookmarks = []

function! ctrlspace#bookmarks#Bookmarks()
return s:bookmarks
return s:bookmarks
endfunction

function! ctrlspace#bookmarks#SetBookmarks(value)
let s:bookmarks = a:value
return s:bookmarks
let s:bookmarks = a:value
return s:bookmarks
endfunction

" FUNCTION: ctrlspace#bookmarks#GoToBookmark(nr) {{{
function! ctrlspace#bookmarks#GoToBookmark(nr)
let newBookmark = s:bookmarks[a:nr]
call ctrlspace#util#ChDir(newBookmark.Directory)
call ctrlspace#ui#DelayedMsg("CWD is now: " . newBookmark.Directory)
endfunction

function! ctrlspace#bookmarks#ChangeBookmarkName(nr)
let bookmark = s:bookmarks[a:nr]
let newName = ctrlspace#ui#GetInput("New bookmark name: ", bookmark.Name)

if !empty(newName)
call ctrlspace#bookmarks#AddToBookmarks(bookmark.Directory, newName)
call ctrlspace#ui#DelayedMsg("Bookmark '" . bookmark.Name . "' has been renamed to '" . newName . "'.")
endif
endfunction

function! ctrlspace#bookmarks#ChangeBookmarkDirectory(nr)
let bookmark = s:bookmarks[a:nr]
let current = bookmark.Directory
let name = bookmark.Name
let directory = ctrlspace#ui#GetInput("Edit directory for bookmark '" . name . "': ", current, "dir")

if empty(directory)
return 0
endif

let directory = ctrlspace#util#NormalizeDirectory(directory)

if !isdirectory(directory)
call ctrlspace#ui#Msg("Directory incorrect.")
return 0
endif
let newBookmark = s:bookmarks[a:nr]

for bookmark in s:bookmarks
if bookmark.Directory ==# directory
call ctrlspace#ui#Msg("This directory has been already bookmarked under name '" . name . "'.")
return 0
endif
endfor

call remove(s:bookmarks, a:nr)

call ctrlspace#bookmarks#AddToBookmarks(directory, name)
call ctrlspace#ui#DelayedMsg("Directory '" . directory . "' has been bookmarked under name '" . name . "'.")

return 1
" Edit bookmarked file
execute "edit " . newBookmark.Directory. "/" . newBookmark.Name
call ctrlspace#ui#DelayedMsg("Directory: " . newBookmark.Directory)
endfunction
" }}}

" FUNCTION: ctrlspace#bookmarks#RemoveBookmark(nr) {{{
function! ctrlspace#bookmarks#RemoveBookmark(nr)
let name = s:bookmarks[a:nr].Name
let name = s:bookmarks[a:nr].Name

if !ctrlspace#ui#Confirmed("Delete bookmark '" . name . "'?")
return
endif
if !ctrlspace#ui#Confirmed("Delete bookmark '" . name . "'?")
return
endif

call remove(s:bookmarks, a:nr)
call remove(s:bookmarks, a:nr)

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_BOOKMARK: "
call add(lines, oldLine)
endif
endfor
endif
if filereadable(cacheFile)
for oldLine in readfile(cacheFile)
" cache non-bookmark lines
if oldLine !~# "CS_BOOKMARK: "
call add(lines, oldLine)
endif
endfor
endif

for bm in s:bookmarks
call add(lines, "CS_BOOKMARK: " . bm.Directory . ctrlspace#context#Separator() . bm.Name)
endfor
for bm in s:bookmarks
call add(lines, "CS_BOOKMARK: " . bm.Directory . ctrlspace#context#Separator() . bm.Name)
endfor

call writefile(lines, cacheFile)
call writefile(lines, cacheFile)

call ctrlspace#ui#DelayedMsg("Bookmark '" . name . "' has been deleted.")
call ctrlspace#ui#DelayedMsg("Bookmark '" . name . "' has been deleted.")
endfunction
" }}}

" FUNCTION: ctrlspace#bookmarks#AddFirstBookmark() {{{
function! ctrlspace#bookmarks#AddFirstBookmark()
if ctrlspace#bookmarks#AddNewBookmark()
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)
endif
if ctrlspace#bookmarks#AddNewBookmark()
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)
endif
endfunction
" }}}

" FUNCTION: ctrlspace#bookmarks#AddNewBookmark() {{{
function! ctrlspace#bookmarks#AddNewBookmark()
" Get current filename and directory.
let l:start_file = ctrlspace#util#NormalizeDirectory(ctrlspace#window#GetStartFile())
let l:filename = fnamemodify(l:start_file, ":p:t")
let l:directory = fnamemodify(l:start_file, ":p:h")

" Detect whether existing
for bm in s:bookmarks
if ctrlspace#util#IsSameDirectory(bm.Directory, l:directory) && bm.Name == l:filename
call ctrlspace#ui#Msg("'" . l:filename . "' bookmark has been already existed")
return 0
endif
endfor

if !ctrlspace#ui#Confirmed("Add to bookmarks: " . l:start_file . " ?")
return 0
endif

call ctrlspace#bookmarks#AddToBookmarks(l:directory, l:filename)
call ctrlspace#ui#DelayedMsg("'" . l:filename . "' was bookmarked successful")

return 1
endfunction
" }}}

function! ctrlspace#bookmarks#AddNewBookmark(...)
if a:0
let current = s:bookmarks[a:1].Directory
else
let root = ctrlspace#roots#CurrentProjectRoot()
let current = empty(root) ? fnamemodify(".", ":p:h") : root
endif

let directory = ctrlspace#ui#GetInput("Add directory to bookmarks: ", current, "dir")

if empty(directory)
return 0
endif
" FUNCTION: ctrlspace#bookmarks#AddToBookmarks(directory, name) {{{
function! ctrlspace#bookmarks#AddToBookmarks(directory, name)
let directory = ctrlspace#util#NormalizeDirectory(a:directory)
let jumpCounter = 0

let directory = ctrlspace#util#NormalizeDirectory(directory)
let bookmark = { "Name": a:name,
\ "Directory": ctrlspace#util#UseSlashDir(directory),
\ "JumpCounter": jumpCounter }

if !isdirectory(directory)
call ctrlspace#ui#Msg("Directory incorrect.")
return 0
endif
call add(s:bookmarks, bookmark)

for bm in s:bookmarks
if bm.Directory == directory
call ctrlspace#ui#Msg("This directory has been already bookmarked under name '" . bm.Name . "'.")
return 0
endif
endfor
let lines = []
let cacheFile = s:config.CacheDir . "/.cs_cache"

let name = ctrlspace#ui#GetInput("New bookmark name: ", fnamemodify(directory, ":t"))
if filereadable(cacheFile)
for oldLine in readfile(cacheFile)
" cache non-bookmark lines
if (oldLine !~# "CS_BOOKMARK: ")
call add(lines, oldLine)
endif
endfor
endif

if empty(name)
return 0
endif
for bm in s:bookmarks
call add(lines, "CS_BOOKMARK: " . bm.Directory . ctrlspace#context#Separator() . bm.Name)
endfor

call ctrlspace#bookmarks#AddToBookmarks(directory, name)
call ctrlspace#ui#DelayedMsg("Directory '" . directory . "' has been bookmarked under name '" . name . "'.")
return 1
endfunction
call writefile(lines, cacheFile)

function! ctrlspace#bookmarks#AddToBookmarks(directory, name)
let directory = ctrlspace#util#NormalizeDirectory(a:directory)
let jumpCounter = 0

for i in range(len(s:bookmarks))
if s:bookmarks[i].Directory == directory
let jumpCounter = s:bookmarks[i].JumpCounter
call remove(s:bookmarks, i)
break
endif
endfor

let bookmark = { "Name": a:name, "Directory": directory, "JumpCounter": jumpCounter }

call add(s:bookmarks, bookmark)

let lines = []
let bmRoots = {}
let cacheFile = s:config.CacheDir . "/.cs_cache"

if filereadable(cacheFile)
for oldLine in readfile(cacheFile)
if (oldLine !~# "CS_BOOKMARK: ") && (oldLine !~# "CS_PROJECT_ROOT: ")
call add(lines, oldLine)
endif
endfor
endif

for bm in s:bookmarks
call add(lines, "CS_BOOKMARK: " . bm.Directory . ctrlspace#context#Separator() . bm.Name)
let bmRoots[bm.Directory] = 1
endfor

for root in keys(ctrlspace#roots#ProjectRoots())
if !has_key(bmRoots, root)
call add(lines, "CS_PROJECT_ROOT: " . root)
endif
endfor

call writefile(lines, cacheFile)
call extend(ctrlspace#roots#ProjectRoots(), { bookmark.Directory: 1 })

return bookmark
return bookmark
endfunction
" }}}

" FUNCTION: ctrlspace#bookmarks#FindActiveBookmark() {{{
function! ctrlspace#bookmarks#FindActiveBookmark()
let root = ctrlspace#roots#CurrentProjectRoot()
let root = ctrlspace#roots#CurrentProjectRoot()

if empty(root)
let root = fnamemodify(".", ":p:h")
endif
if empty(root)
let root = fnamemodify(".", ":p:h")
endif

let root = ctrlspace#util#NormalizeDirectory(root)
let root = ctrlspace#util#NormalizeDirectory(root)

for bm in s:bookmarks
if ctrlspace#util#NormalizeDirectory(bm.Directory) == root
let bm.JumpCounter = ctrlspace#jumps#IncrementJumpCounter()
return bm
endif
endfor
for bm in s:bookmarks
if ctrlspace#util#NormalizeDirectory(bm.Directory) == root
let bm.JumpCounter = ctrlspace#jumps#IncrementJumpCounter()
return bm
endif
endfor

return {}
return {}
endfunction
" }}}
Loading