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
30 changes: 30 additions & 0 deletions autoload/bm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ function! bm#all_lines(file)
return keys(g:line_map[a:file])
endfunction

function! bm#location_list_stack_mode()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of duplication created due to this new function. It would be much nicer to have a sorting param passed to the existing function. The added benefit would be that we would not have two different function that use slightly different logic.

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 = []
Expand Down Expand Up @@ -199,6 +223,12 @@ endfunction

" Private {{{

function! bm#compare_bm(bm1, bm2)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is comparing by sign_idx, maybe bm#compare_sign_idx would be a more descriptive name? In fact in order to make it consistent with the existing behaviour of bm#compare_lines we could just pass in the sign_idx.

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)
Expand Down
29 changes: 22 additions & 7 deletions plugin/bookmark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ 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:bookmark_display_annotation', 0 )
call s:set('g:bm_stack_mode', 0 )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming scheme is inconsistent here, it should be g:bookmark_stack_mode.


function! s:init(file)
if g:bookmark_auto_save ==# 1 || g:bookmark_manage_per_buffer ==# 1
Expand Down Expand Up @@ -184,13 +185,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()
Expand Down Expand Up @@ -491,6 +486,26 @@ function! s:is_quickfix_win()
return getbufvar(winbufnr('.'), '&buftype') == 'quickfix'
endfunction

function! s:show_location()
if g:bm_stack_mode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you extracted this into it's own function as it gets more complicated now. If we could just parametrize bm#location_list() this whole function would become more readable.

Untested code:

function! s:show_location()
  lgetexpr bm#location_list(g:bm_stack_mode)
  if g:bookmark_location_list
    belowright lopen
  else
    belowright copen
  endif
endfunction

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)
Expand Down