└── autoload └── unite └── sources └── mark.vim /autoload/unite/sources/mark.vim: -------------------------------------------------------------------------------- 1 | let s:save_cpo = &cpo 2 | set cpo&vim 3 | 4 | if !exists('g:unite_source_mark_marks') 5 | let g:unite_source_mark_marks = "abcdefghijklmnopqrstuvwxyz" 6 | 7 | " or all marks? 8 | " let g:unite_source_mark_marks = 9 | " \ "abcdefghijklmnopqrstuvwxyz" 10 | " \ . "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 11 | " \ . "0123456789.'`^<>[]{}()\"" 12 | endif 13 | 14 | function! s:str2list(str) 15 | return split(a:str, '\zs') 16 | endfunction 17 | 18 | let s:mark_info_list = [] 19 | 20 | let s:source_mark = { 21 | \ 'name': 'mark', 22 | \ 'hooks': {}, 23 | \ 'action_table': {}, 24 | \ } 25 | 26 | function! s:source_mark.hooks.on_init(args, context) 27 | if empty(a:args) 28 | let s:marks = s:str2list(g:unite_source_mark_marks) 29 | else 30 | let s:marks = s:str2list(a:args[0]) 31 | endif 32 | let s:marks_bufnr = bufnr('%') 33 | let s:mark_info_list = s:collect_mark_info(s:marks) 34 | endfunction 35 | 36 | function! s:source_mark.gather_candidates(args, context) 37 | return map(copy(s:mark_info_list), '{ 38 | \ "word": v:val.mark . ":" . v:val.buf_name . ":" . v:val.line, 39 | \ "abbr": printf("%s: %s [%4d] %s", 40 | \ v:val.mark, v:val.buf_name, v:val.line, v:val.snippet), 41 | \ "source": "mark", 42 | \ "kind": "jump_list", 43 | \ "action__path": v:val.path, 44 | \ "action__line": v:val.line, 45 | \ "action__mark": v:val.mark, 46 | \ "action__bufnr": v:val.bufnr, 47 | \ }') 48 | endfunction 49 | 50 | let s:source_mark.action_table.delete = { 51 | \ 'description' : 'delete from mark list', 52 | \ 'is_invalidate_cache' : 1, 53 | \ 'is_quit' : 0, 54 | \ 'is_selectable' : 1, 55 | \ } 56 | function! s:source_mark.action_table.delete.func(candidates) "{{{ 57 | let unite_bufnr = bufnr('%') 58 | for candidate in a:candidates 59 | if candidate.action__mark =~ '\a' 60 | execute "buffer! " . candidate.action__bufnr 61 | execute "delmark " . candidate.action__mark 62 | else 63 | echoerr "Special marks can't be deleted! :" . candidate.action__mark 64 | endif 65 | endfor 66 | " restore original bufnr so that gathering marks will be based on that buffer 67 | execute "buffer! " . s:marks_bufnr 68 | let s:mark_info_list = s:collect_mark_info(s:marks) 69 | " restore unite buffer 70 | execute "buffer! " . unite_bufnr 71 | endfunction"}}} 72 | 73 | function! s:collect_mark_info(marks) 74 | let l:curr_buf_name = bufname('%') 75 | let l:mark_info_list = [] 76 | for l:mark in a:marks 77 | let l:mark_info = s:get_mark_info(l:mark, l:curr_buf_name) 78 | if !empty(l:mark_info) 79 | call add(l:mark_info_list, l:mark_info) 80 | endif 81 | endfor 82 | return l:mark_info_list 83 | endfunction 84 | 85 | function! s:get_mark_info(mark, curr_buf_name) 86 | let l:pos = getpos("'" . a:mark) 87 | let l:line = l:pos[1] 88 | if l:line == 0 " mark does not exist 89 | return {} 90 | endif 91 | if l:pos[0] == 0 92 | let l:buf_name = '%' 93 | let l:path = a:curr_buf_name 94 | let l:snippet = getline(l:line) 95 | let l:bufnr = bufnr('%') 96 | else 97 | let l:buf_name = bufname(l:pos[0]) 98 | let l:path = l:buf_name 99 | let l:snippet = '' 100 | let l:bufnr = l:pos[0] 101 | endif 102 | let l:mark_info = { 103 | \ 'mark': a:mark, 104 | \ 'buf_name': l:buf_name, 105 | \ 'bufnr' : l:bufnr, 106 | \ 'path': l:path, 107 | \ 'line': l:line, 108 | \ 'snippet': l:snippet, 109 | \ } 110 | return l:mark_info 111 | endfunction 112 | 113 | function! unite#sources#mark#define() 114 | return s:source_mark 115 | endfunction 116 | 117 | let &cpo = s:save_cpo 118 | unlet s:save_cpo 119 | --------------------------------------------------------------------------------