From 948b025d8a1e492c73e62b24103f8d4cc412664f Mon Sep 17 00:00:00 2001 From: Muhit Sarwar Date: Sun, 6 Sep 2020 20:14:39 +0800 Subject: [PATCH 1/2] Toggle between stack mode use g:bm_stack_mode = 1 to enable stack mode --- autoload/bm.vim | 30 ++++++++++++++++++++++++++++++ plugin/bookmark.vim | 29 ++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/autoload/bm.vim b/autoload/bm.vim index 3a6d83d..5a9d0e2 100644 --- a/autoload/bm.vim +++ b/autoload/bm.vim @@ -127,6 +127,30 @@ function! bm#all_lines(file) return keys(g:line_map[a:file]) endfunction +function! bm#location_list_stack_mode() + let files = bm#all_files() + let locations = [] + let bms = [] + for file in files + let line_nrs = bm#all_lines(file) + for line_nr in line_nrs + let bookmark = bm#get_bookmark_by_line(file, line_nr) + let bookmark['file'] = file + let bookmark['line_nr'] = line_nr + call add(bms, bookmark) + endfor + endfor + for bookmark in sort(bms, 'bm#compare_bm') + let content = bookmark['annotation'] !=# '' + \ ? "Annotation: ". bookmark['annotation'] + \ : (bookmark['content'] !=# "" + \ ? bookmark['content'] + \ : "empty line") + call add(locations, bookmark['file'] .":". bookmark['line_nr'].":". content) + endfor + return locations +endfunction + function! bm#location_list() let files = sort(bm#all_files()) let locations = [] @@ -199,6 +223,12 @@ endfunction " Private {{{ +function! bm#compare_bm(bm1, bm2) + let bm1 = str2nr(a:bm1['sign_idx']) + let bm2 = str2nr(a:bm2['sign_idx']) + return bm1 ==# bm2 ? 0 : bm1 > bm2 ? -1 : 1 +endfunc + function! bm#compare_lines(line_str1, line_str2) let line1 = str2nr(a:line_str1) let line2 = str2nr(a:line_str2) diff --git a/plugin/bookmark.vim b/plugin/bookmark.vim index 3515fa9..0c200f2 100644 --- a/plugin/bookmark.vim +++ b/plugin/bookmark.vim @@ -6,6 +6,7 @@ scriptencoding utf-8 let g:bm_has_any = 0 let g:bm_sign_index = 9500 let g:bm_current_file = '' +let g:bm_stack_mode = 0 " Configuration {{{ @@ -180,13 +181,7 @@ function! BookmarkShowAll() else let oldformat = &errorformat " backup original format let &errorformat = "%f:%l:%m" " custom format for bookmarks - if g:bookmark_location_list - lgetexpr bm#location_list() - belowright lopen - else - cgetexpr bm#location_list() - belowright copen - endif + call s:show_location() augroup BM_AutoCloseCommand autocmd! autocmd WinLeave * call s:auto_close() @@ -487,6 +482,26 @@ function! s:is_quickfix_win() return getbufvar(winbufnr('.'), '&buftype') == 'quickfix' endfunction +function! s:show_location() + if g:bm_stack_mode + if g:bookmark_location_list + lgetexpr bm#location_list_stack_mode() + belowright lopen + else + cgetexpr bm#location_list_stack_mode() + belowright copen + endif + else + if g:bookmark_location_list + lgetexpr bm#location_list() + belowright lopen + else + cgetexpr bm#location_list() + belowright copen + endif + endif +endfunction + function! s:auto_close() if s:is_quickfix_win() if (g:bookmark_auto_close) From f5c5da569300a5eddd87d8809f927b2c7fd953de Mon Sep 17 00:00:00 2001 From: Muhit Sarwar Date: Sun, 6 Sep 2020 21:08:13 +0800 Subject: [PATCH 2/2] Fix bm_stack_mode initialization --- plugin/bookmark.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/bookmark.vim b/plugin/bookmark.vim index 0c200f2..c251de3 100644 --- a/plugin/bookmark.vim +++ b/plugin/bookmark.vim @@ -6,7 +6,6 @@ scriptencoding utf-8 let g:bm_has_any = 0 let g:bm_sign_index = 9500 let g:bm_current_file = '' -let g:bm_stack_mode = 0 " Configuration {{{ @@ -33,6 +32,7 @@ call s:set('g:bookmark_auto_close', 0 ) call s:set('g:bookmark_center', 0 ) call s:set('g:bookmark_location_list', 0 ) call s:set('g:bookmark_disable_ctrlp', 0 ) +call s:set('g:bm_stack_mode', 0 ) function! s:init(file) if g:bookmark_auto_save ==# 1 || g:bookmark_manage_per_buffer ==# 1