-
Notifications
You must be signed in to change notification settings - Fork 100
Toggle between stack mode #158
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is comparing by |
||
| 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming scheme is inconsistent here, it should be |
||
|
|
||
| function! s:init(file) | ||
| if g:bookmark_auto_save ==# 1 || g:bookmark_manage_per_buffer ==# 1 | ||
|
|
@@ -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() | ||
|
|
@@ -491,6 +486,26 @@ function! s:is_quickfix_win() | |
| return getbufvar(winbufnr('.'), '&buftype') == 'quickfix' | ||
| endfunction | ||
|
|
||
| function! s:show_location() | ||
| if g:bm_stack_mode | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Untested code: |
||
| 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) | ||
|
|
||
There was a problem hiding this comment.
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.