Skip to content

Commit

Permalink
feat!: ✨ remove needless loads,dont write if no update
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasky committed Jun 29, 2022
1 parent b7508ab commit 1e7154a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 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 @@ -162,7 +163,7 @@ endfunction

function! bm#serialize()
let sign_index = "let l:bm_sign_index = ". g:bm_sign_index
let file_version = "let l:bm_file_version = 1"
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 @@ -186,8 +187,9 @@ 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 g:bm_sessions = ses
let result = []
for file in keys(ses)
for bm in ses[file]
Expand Down
7 changes: 5 additions & 2 deletions plugin/bookmark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ call s:set('g:bookmark_disable_ctrlp', 0 )
call s:set('g:bookmark_display_annotation', 0 )

function! s:init(file)
if g:bookmark_auto_save ==# 1 || g:bookmark_manage_per_buffer ==# 1
if g:bookmark_auto_save ==# 1 && g:bookmark_manage_per_buffer ==# 1
augroup bm_vim_enter
autocmd!
autocmd BufEnter * call s:set_up_auto_save(expand('<afile>:p'))
Expand Down Expand Up @@ -211,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

0 comments on commit 1e7154a

Please sign in to comment.