/
neomru.vim
143 lines (132 loc) · 4.77 KB
/
neomru.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"=============================================================================
" FILE: neomru.vim
" AUTHOR: Zhao Cai <caizhaoff@gmail.com>
" Shougo Matsushita <Shougo.Matsu at gmail.com>
" License: MIT license
"=============================================================================
let s:save_cpo = &cpo
set cpo&vim
" Source "{{{
call neomru#init()
function! unite#sources#neomru#define() abort "{{{
return [s:file_mru_source, s:dir_mru_source]
endfunction"}}}
let s:file_mru_source = {
\ 'name' : 'neomru/file',
\ 'description' : 'candidates from file MRU list',
\ 'hooks' : {},
\ 'action_table' : {},
\ 'syntax' : 'uniteSource__FileMru',
\ 'default_kind' : 'file',
\ 'ignore_pattern' : g:neomru#file_mru_ignore_pattern,
\ 'max_candidates' : 200,
\}
let s:dir_mru_source = {
\ 'name' : 'neomru/directory',
\ 'description' : 'candidates from directory MRU list',
\ 'hooks' : {},
\ 'action_table' : {},
\ 'syntax' : 'uniteSource__DirectoryMru',
\ 'default_kind' : 'directory',
\ 'ignore_pattern' :
\ g:neomru#directory_mru_ignore_pattern,
\ 'alias_table' : { 'unite__new_candidate' : 'vimfiler__mkdir' },
\ 'max_candidates' : 200,
\}
function! s:file_mru_source.hooks.on_syntax(args, context) abort "{{{
syntax match uniteSource__FileMru_Time
\ /([^)]*)\s\+/
\ contained containedin=uniteSource__FileMru
highlight default link uniteSource__FileMru_Time Statement
endfunction"}}}
function! s:dir_mru_source.hooks.on_syntax(args, context) abort "{{{
syntax match uniteSource__DirectoryMru_Time
\ /([^)]*)\s\+/
\ contained containedin=uniteSource__DirectoryMru
highlight default link uniteSource__DirectoryMru_Time Statement
endfunction"}}}
function! s:file_mru_source.hooks.on_post_filter(args, context) abort "{{{
return s:on_post_filter(a:args, a:context)
endfunction"}}}
function! s:dir_mru_source.hooks.on_post_filter(args, context) abort "{{{
for candidate in a:context.candidates
if !has_key(candidate, 'abbr')
let candidate.abbr = candidate.word
endif
if candidate.abbr !~ '/$'
let candidate.abbr .= '/'
endif
endfor
return s:on_post_filter(a:args, a:context)
endfunction"}}}
function! s:file_mru_source.gather_candidates(args, context) abort "{{{
let mru = neomru#_get_mrus().file
return mru.gather_candidates(a:args, a:context)
endfunction"}}}
function! s:dir_mru_source.gather_candidates(args, context) abort "{{{
let mru = neomru#_get_mrus().directory
return mru.gather_candidates(a:args, a:context)
endfunction"}}}
"}}}
" Actions "{{{
let s:file_mru_source.action_table.delete = {
\ 'description' : 'delete from file_mru list',
\ 'is_invalidate_cache' : 1,
\ 'is_quit' : 0,
\ 'is_selectable' : 1,
\ }
function! s:file_mru_source.action_table.delete.func(candidates) abort "{{{
call neomru#_get_mrus().file.delete(a:candidates)
endfunction"}}}
let s:dir_mru_source.action_table.delete = {
\ 'description' : 'delete from directory_mru list',
\ 'is_invalidate_cache' : 1,
\ 'is_quit' : 0,
\ 'is_selectable' : 1,
\ }
function! s:dir_mru_source.action_table.delete.func(candidates) abort "{{{
call neomru#_get_mrus().directory.delete(a:candidates)
endfunction"}}}
"}}}
" Filters "{{{
function! s:converter(candidates, context) abort "{{{
if g:neomru#filename_format == '' && g:neomru#time_format == ''
return a:candidates
endif
for candidate in filter(copy(a:candidates),
\ "!has_key(v:val, 'abbr')")
let path = (g:neomru#filename_format == '') ? candidate.action__path :
\ unite#util#substitute_path_separator(
\ fnamemodify(candidate.action__path, g:neomru#filename_format))
if path == ''
let path = candidate.action__path
endif
" Set default abbr.
let candidate.abbr = (g:neomru#time_format == '') ? '' :
\ strftime(g:neomru#time_format,
\ getftime(candidate.action__path))
let candidate.abbr .= path
endfor
return a:candidates
endfunction"}}}
function! s:file_mru_source.source__converter(candidates, context) abort "{{{
return s:converter(a:candidates, a:context)
endfunction"}}}
let s:file_mru_source.converters = [ s:file_mru_source.source__converter ]
function! s:dir_mru_source.source__converter(candidates, context) abort "{{{
return s:converter(a:candidates, a:context)
endfunction"}}}
let s:dir_mru_source.converters = [ s:dir_mru_source.source__converter ]
"}}}
" Misc "{{{
function! s:on_post_filter(args, context) abort "{{{
for candidate in a:context.candidates
let candidate.action__directory =
\ unite#util#path2directory(candidate.action__path)
endfor
endfunction"}}}
"}}}
"
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker