1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:50:06 +08:00

feat(bookmarks): add leaderf support for vim-bookmarks

This commit is contained in:
wsdjeg 2022-04-10 16:40:31 +08:00
parent 88eb4db751
commit 72814fb13f
2 changed files with 44 additions and 0 deletions

View File

@ -195,6 +195,21 @@ function! SpaceVim#layers#leaderf#config() abort
\ 'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
\ }
let g:Lf_Extensions.bookmarks =
\ {
\ 'source': string(s:_function('s:bookmarks', 1))[10:-3],
\ 'accept': string(s:_function('s:bookmarks_acp', 1))[10:-3],
\ 'highlights_def': {
\ 'Lf_register_name': '^".',
\ 'Lf_register_content': '\s\+.*',
\ },
\ 'highlights_cmd': [
\ 'hi def link Lf_register_name ModeMsg',
\ 'hi def link Lf_register_content Normal',
\ ],
\ 'after_enter' : string(s:_function('s:init_leaderf_win', 1))[10:-3]
\ }
let g:Lf_Extensions.locationlist =
\ {
\ 'source': string(s:_function('s:locationlist', 1))[10:-3],
@ -462,6 +477,33 @@ function! s:manpage_acp(line, args) abort
endif
endfunction
function! s:bookmarks(...) abort
let bookmarks = []
let files = sort(bm#all_files())
for file in files
let line_nrs = sort(bm#all_lines(file), "bm#compare_lines")
for line_nr in line_nrs
let bookmark = bm#get_bookmark_by_line(file, line_nr)
call add(bookmarks, printf("%s:%d:1:%s", file, line_nr,
\ bookmark.annotation !=# ''
\ ? "Annotation: " . bookmark.annotation
\ : (bookmark.content !=# "" ? bookmark.content
\ : "empty line")
\ ))
endfor
endfor
return bookmarks
endfunction
function! s:bookmarks_acp(line, argvs) abort
let line = a:line
let filename = fnameescape(split(line, ':\d\+:')[0])
let linenr = matchstr(line, ':\d\+:')[1:-2]
let colum = matchstr(line, '\(:\d\+\)\@<=:\d\+:')[1:-2]
exe 'e ' . filename
call cursor(linenr, colum)
endfunction
func! s:neoyank(...) abort
let yank = []
for text in neoyank#_get_yank_histories()['"']

View File

@ -177,6 +177,8 @@ function! BookmarkShowAll()
exec ":Unite vim_bookmarks"
elseif exists(':CtrlP') == 2 && g:bookmark_disable_ctrlp == 0
exec ":CtrlPBookmark"
elseif exists(':Leaderf')
exe ':Leaderf bookmarks'
else
let oldformat = &errorformat " backup original format
let &errorformat = "%f:%l:%m" " custom format for bookmarks