Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions autoload/bm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function! bm#prev(file, current_line_nr)
endfunction

function! bm#del_bookmark_at_line(file, line_nr)
let g:bm_file_version = g:bm_file_version - 1
let bookmark = bm#get_bookmark_by_line(a:file, a:line_nr)
unlet g:line_map[a:file][a:line_nr]
unlet g:sign_map[a:file][bookmark['sign_idx']]
Expand Down Expand Up @@ -161,7 +162,8 @@ function! bm#del_all()
endfunction

function! bm#serialize()
let file_version = "let l:bm_file_version = 1"
let sign_index = "let l:bm_sign_index = ". g:bm_sign_index
let file_version = "let l:bm_file_version = " . (g:bm_file_version == g:bm_sign_index ? 1 : 0)
let sessions = "let l:bm_sessions = {'default': {"
for file in bm#all_files()
let sessions .= "'". file ."': ["
Expand All @@ -175,12 +177,19 @@ function! bm#serialize()
endfor
let sessions .= "}}"
let current_session = "let l:bm_current_session = 'default'"
return [file_version, sessions, current_session]
return [sign_index, file_version, sessions, current_session]
endfunction

function! bm#checkKey(file)
return has_key(g:bm_sessions,a:file)
endfunction

function! bm#deserialize(data)
exec join(a:data, " | ")
let g:bm_sign_index = l:bm_sign_index
let g:bm_file_version = l:bm_sign_index
let ses = l:bm_sessions["default"]
" let g:bm_sessions = ses
let result = []
for file in keys(ses)
for bm in ses[file]
Expand Down
27 changes: 26 additions & 1 deletion autoload/bm_sign.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function! bm_sign#define_highlights()
endfunction

function! bm_sign#add(file, line_nr, is_annotation)
call bm_sign#lazy_init()
" call bm_sign#lazy_init()
let sign_idx = g:bm_sign_index
call bm_sign#add_at(a:file, sign_idx, a:line_nr, a:is_annotation)
return sign_idx
Expand All @@ -54,6 +54,31 @@ function! bm_sign#add_at(file, sign_idx, line_nr, is_annotation)
endif
endfunction

function! s:startsWith(longer, shorter)
return a:longer[0:len(a:shorter)-1] ==# a:shorter
endfunction
let g:icondict = {'@t': "☑️", '@f': "⛏", '@w': "⚠️", '@n': ""}
function! bm_sign#add_atannotation(file, sign_idx, line_nr, annotation)
call bm_sign#lazy_init()
let is_annotation = a:annotation !=# ""
let name = is_annotation ==# 1 ? "BookmarkAnnotation" : "Bookmark"
let pref = ""
if is_annotation ==# 1
let prefix = "sign define BookmarkAnnotation"
let pref = a:annotation[0:1]
let text = get(g:icondict,pref,"♠")
if pref[0] ==# "@"
execute prefix . pref. " text=" .text
else
let pref = ""
endif
endif
execute "sign place ". a:sign_idx . " line=" . a:line_nr ." name=". name . pref ." file=". a:file
if (a:sign_idx >=# g:bm_sign_index)
let g:bm_sign_index = a:sign_idx + 1
endif
endfunction

function! bm_sign#update_at(file, sign_idx, line_nr, is_annotation)
call bm_sign#del(a:file, a:sign_idx)
call bm_sign#add_at(a:file, a:sign_idx, a:line_nr, a:is_annotation)
Expand Down
25 changes: 14 additions & 11 deletions plugin/bookmark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function! s:init(file)
autocmd CursorMoved * call s:display_annotation()
endif
if a:file !=# ''
call s:startup_load_bookmarks(a:file)
call s:set_up_auto_save(a:file)
elseif g:bookmark_manage_per_buffer ==# 0 && g:bookmark_save_per_working_dir ==# 0
call BookmarkLoad(s:bookmark_save_file(''), 1, 1)
Expand Down Expand Up @@ -162,14 +163,14 @@ command! ClearAllBookmarks call CallDeprecatedCommand('BookmarkClearAll', [0])
command! BookmarkClearAll call BookmarkClearAll(0)

function! BookmarkNext()
call s:refresh_line_numbers()
" call s:refresh_line_numbers()
call s:jump_to_bookmark('next')
endfunction
command! NextBookmark call CallDeprecatedCommand('BookmarkNext')
command! BookmarkNext call BookmarkNext()

function! BookmarkPrev()
call s:refresh_line_numbers()
" call s:refresh_line_numbers()
call s:jump_to_bookmark('prev')
endfunction
command! PrevBookmark call CallDeprecatedCommand('BookmarkPrev')
Expand Down Expand Up @@ -210,7 +211,10 @@ function! BookmarkSave(target_file, silent)
call s:refresh_line_numbers()
if (bm#total_count() > 0 || (!g:bookmark_save_per_working_dir && !g:bookmark_manage_per_buffer))
let serialized_bookmarks = bm#serialize()
call writefile(serialized_bookmarks, a:target_file)
let file_version = "let l:bm_file_version = 0"
if file_version ==# serialized_bookmarks[1]
call writefile(serialized_bookmarks, a:target_file)
endif
if (!a:silent)
echo "All bookmarks saved"
endif
Expand Down Expand Up @@ -406,8 +410,8 @@ function! s:refresh_line_numbers()
call s:lazy_init()
let file = expand("%:p")
if file ==# "" || !bm#has_bookmarks_in_file(file)
return
endif
return
let bufnr = bufnr(file)
let sign_line_map = bm_sign#lines_for_signs(file)
for sign_idx in keys(sign_line_map)
Expand Down Expand Up @@ -459,7 +463,7 @@ function! s:remove_all_bookmarks()
endfunction

function! s:startup_load_bookmarks(file)
call BookmarkLoad(s:bookmark_save_file(a:file), 1, 1)
call BookmarkLoad(s:bookmark_save_file(""), 1, 1)
call s:add_missing_signs(a:file)
endfunction

Expand Down Expand Up @@ -487,7 +491,7 @@ endfunction
function! s:add_missing_signs(file)
let bookmarks = values(bm#all_bookmarks_by_line(a:file))
for bookmark in bookmarks
call bm_sign#add_at(a:file, bookmark['sign_idx'], bookmark['line_nr'], bookmark['annotation'] !=# "")
call bm_sign#add_atannotation(a:file, bookmark['sign_idx'], bookmark['line_nr'], bookmark['annotation'] )
endfor
endfunction

Expand Down Expand Up @@ -517,22 +521,21 @@ function! s:remove_auto_close()
endfunction

function! s:auto_save()
if g:bm_current_file !=# ''
call BookmarkSave(s:bookmark_save_file(g:bm_current_file), 1)
endif
" if g:bm_current_file !=# '' && !bm#checkKey(g:bm_current_file)
call BookmarkSave(s:bookmark_save_file(""), 1)
" endif
augroup bm_auto_save
autocmd!
augroup END
endfunction

function! s:set_up_auto_save(file)
if g:bookmark_auto_save ==# 1 || g:bookmark_manage_per_buffer ==# 1
call s:startup_load_bookmarks(a:file)
let g:bm_current_file = a:file
augroup bm_auto_save
autocmd!
autocmd BufWinEnter * call s:add_missing_signs(expand('<afile>:p'))
autocmd BufLeave,VimLeave,BufReadPre * call s:auto_save()
autocmd VimLeave * call s:auto_save()
augroup END
endif
endfunction
Expand Down
Binary file removed release/vim-bookmarks-0.1.0.zip
Binary file not shown.
Binary file removed release/vim-bookmarks-0.2.0.zip
Binary file not shown.
Binary file removed release/vim-bookmarks-1.0.0.zip
Binary file not shown.
Binary file removed release/vim-bookmarks-1.1.0.zip
Binary file not shown.