mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 07:09:11 +08:00
refactor(bundle): use bundle neomru
This commit is contained in:
parent
e61e78b0bc
commit
e48c7c22b0
@ -19,7 +19,7 @@ function! SpaceVim#layers#denite#plugins() abort
|
||||
call add(plugins, ['Shougo/unite-outline', {'merged' : 0}])
|
||||
call add(plugins, ['ozelentok/denite-gtags', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neoyank.vim', {'merged' : 0}])
|
||||
call add(plugins, ['Shougo/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, ['SpaceVim/Denite-sources', {'merged' : 0}])
|
||||
|
||||
return plugins
|
||||
|
@ -48,7 +48,7 @@ function! SpaceVim#layers#fzf#plugins() abort
|
||||
let plugins = []
|
||||
call add(plugins, ['junegunn/fzf', { 'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neoyank.vim', {'merged' : 0}])
|
||||
call add(plugins, ['Shougo/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, ['SpaceVim/fzf-neoyank', { 'merged' : 0}])
|
||||
return plugins
|
||||
endfunction
|
||||
|
@ -56,7 +56,7 @@ function! SpaceVim#layers#leaderf#plugins() abort
|
||||
\ 'loadconf' : 1,
|
||||
\ 'merged' : 0,
|
||||
\ }])
|
||||
call add(plugins, ['Shougo/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neoyank.vim', { 'merged' : 0}])
|
||||
|
||||
" use this repo unicode data
|
||||
|
@ -60,7 +60,7 @@ function! SpaceVim#layers#unite#plugins() abort
|
||||
call add(plugins, ['osyo-manga/unite-quickfix', {'merged' : 0}])
|
||||
" outline source <Leader>fo
|
||||
call add(plugins, ['Shougo/unite-outline', {'merged' : 0}])
|
||||
call add(plugins, ['Shougo/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neomru.vim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-van', {'merged' : 0}])
|
||||
|
||||
if g:spacevim_enable_googlesuggest
|
||||
|
2
bundle/neomru.vim/.gitignore
vendored
Normal file
2
bundle/neomru.vim/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/doc/tags
|
||||
*.py[cod]
|
21
bundle/neomru.vim/LICENSE
Normal file
21
bundle/neomru.vim/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
License: MIT license
|
||||
AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
455
bundle/neomru.vim/autoload/neomru.vim
Normal file
455
bundle/neomru.vim/autoload/neomru.vim
Normal file
@ -0,0 +1,455 @@
|
||||
"=============================================================================
|
||||
" FILE: neomru.vim
|
||||
" AUTHOR: Zhao Cai <caizhaoff@gmail.com>
|
||||
" Shougo Matsushita <Shougo.Matsu at gmail.com>
|
||||
" License: MIT license
|
||||
"=============================================================================
|
||||
|
||||
function! neomru#set_default(var, val, ...) abort
|
||||
if !exists(a:var) || type({a:var}) != type(a:val)
|
||||
let alternate_var = get(a:000, 0, '')
|
||||
|
||||
let {a:var} = exists(alternate_var) ?
|
||||
\ {alternate_var} : a:val
|
||||
endif
|
||||
endfunction
|
||||
function! s:substitute_path_separator(path) abort
|
||||
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
|
||||
endfunction
|
||||
function! s:expand(path) abort
|
||||
return s:substitute_path_separator(expand(a:path))
|
||||
endfunction
|
||||
function! s:fnamemodify(fname, mods) abort
|
||||
return s:substitute_path_separator(fnamemodify(a:fname, a:mods))
|
||||
endfunction
|
||||
|
||||
" Variables
|
||||
" The version of MRU file format.
|
||||
let s:VERSION = '0.3.0'
|
||||
|
||||
let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
|
||||
|
||||
let s:base = s:expand($XDG_CACHE_HOME != '' ?
|
||||
\ $XDG_CACHE_HOME . '/neomru' : '~/.cache/neomru')
|
||||
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#do_validate', 1,
|
||||
\ 'g:unite_source_mru_do_validate')
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#update_interval', 0,
|
||||
\ 'g:unite_source_mru_update_interval')
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#time_format', '',
|
||||
\ 'g:unite_source_file_mru_time_format')
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#filename_format', '',
|
||||
\ 'g:unite_source_file_mru_filename_format')
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#file_mru_path',
|
||||
\ s:substitute_path_separator(s:base.'/file'))
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#file_mru_limit',
|
||||
\ 1000, 'g:unite_source_file_mru_limit')
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#file_mru_ignore_pattern',
|
||||
\'\~$\|\.\%(o\|exe\|dll\|bak\|zwc\|pyc\|sw[po]\)$'.
|
||||
\'\|\%(^\|/\)\.\%(hg\|git\|bzr\|svn\)\%($\|/\)'.
|
||||
\'\|^\%(\\\\\|/mnt/\|/media/\|/temp/\|/tmp/\|\%(/private\)\=/var/folders/\)'.
|
||||
\'\|\%(^\%(fugitive\)://\)'.
|
||||
\'\|\%(^\%(term\)://\)'
|
||||
\, 'g:unite_source_file_mru_ignore_pattern')
|
||||
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#directory_mru_path',
|
||||
\ s:substitute_path_separator(s:base.'/directory'))
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#directory_mru_limit',
|
||||
\ 1000, 'g:unite_source_directory_mru_limit')
|
||||
call neomru#set_default(
|
||||
\ 'g:neomru#directory_mru_ignore_pattern',
|
||||
\'\%(^\|/\)\.\%(hg\|git\|bzr\|svn\)\%($\|/\)'.
|
||||
\'\|^\%(\\\\\|/mnt/\|/media/\|/temp/\|/tmp/\|\%(/private\)\=/var/folders/\)',
|
||||
\ 'g:unite_source_directory_mru_ignore_pattern')
|
||||
call neomru#set_default('g:neomru#follow_links', 0)
|
||||
|
||||
|
||||
" MRUs
|
||||
let s:MRUs = {}
|
||||
|
||||
" Template MRU: 2
|
||||
"---------------------%>---------------------
|
||||
" @candidates:
|
||||
" ------------
|
||||
" [full_path, ... ]
|
||||
"
|
||||
" @mtime
|
||||
" ------
|
||||
" the last modified time of the mru file.
|
||||
" - set once when loading the mru_file
|
||||
" - update when #save()
|
||||
"
|
||||
" @is_loaded
|
||||
" ----------
|
||||
" 0: empty
|
||||
" 1: loaded
|
||||
" -------------------%<---------------------
|
||||
|
||||
let s:mru = {
|
||||
\ 'candidates' : [],
|
||||
\ 'type' : '',
|
||||
\ 'mtime' : 0,
|
||||
\ 'update_interval' : g:neomru#update_interval,
|
||||
\ 'mru_file' : '',
|
||||
\ 'limit' : {},
|
||||
\ 'do_validate' : g:neomru#do_validate,
|
||||
\ 'is_loaded' : 0,
|
||||
\ 'version' : s:VERSION,
|
||||
\ }
|
||||
|
||||
function! s:mru.is_a(type) abort
|
||||
return self.type == a:type
|
||||
endfunction
|
||||
function! s:mru.validate() abort
|
||||
throw 'unite(mru) umimplemented method: validate()!'
|
||||
endfunction
|
||||
|
||||
function! s:mru.gather_candidates(args, context) abort
|
||||
if !self.is_loaded
|
||||
call self.load()
|
||||
endif
|
||||
|
||||
if a:context.is_redraw && g:neomru#do_validate
|
||||
call self.reload()
|
||||
endif
|
||||
|
||||
return copy(self.candidates)
|
||||
endfunction
|
||||
function! s:mru.delete(candidates) abort
|
||||
for candidate in a:candidates
|
||||
call filter(self.candidates,
|
||||
\ 'v:val !=# candidate.action__path')
|
||||
endfor
|
||||
|
||||
call self.save()
|
||||
endfunction
|
||||
function! s:mru.has_external_update() abort
|
||||
return self.mtime < getftime(self.mru_file)
|
||||
endfunction
|
||||
|
||||
function! s:mru.save(...) abort
|
||||
if s:is_sudo()
|
||||
return
|
||||
endif
|
||||
|
||||
let opts = a:0 >= 1 && type(a:1) == type({}) ? a:1 : {}
|
||||
|
||||
if self.has_external_update() && filereadable(self.mru_file)
|
||||
" only need to get the list which contains the latest MRUs
|
||||
let lines = readfile(self.mru_file)
|
||||
if !empty(lines)
|
||||
let [ver; items] = lines
|
||||
if self.version_check(ver)
|
||||
call extend(self.candidates, items)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let self.candidates = s:uniq(self.candidates)
|
||||
if len(self.candidates) > self.limit
|
||||
let self.candidates = self.candidates[: self.limit - 1]
|
||||
endif
|
||||
|
||||
if get(opts, 'event') ==# 'VimLeavePre'
|
||||
call self.validate()
|
||||
endif
|
||||
|
||||
call s:writefile(self.mru_file,
|
||||
\ [self.version] + self.candidates)
|
||||
|
||||
let self.mtime = getftime(self.mru_file)
|
||||
endfunction
|
||||
|
||||
function! s:mru.load(...) abort
|
||||
let is_force = get(a:000, 0, 0)
|
||||
|
||||
" everything is loaded, done!
|
||||
if !is_force && self.is_loaded && !self.has_external_update()
|
||||
return
|
||||
endif
|
||||
|
||||
let mru_file = self.mru_file
|
||||
|
||||
if !filereadable(mru_file)
|
||||
return
|
||||
endif
|
||||
|
||||
let file = readfile(mru_file)
|
||||
if empty(file)
|
||||
return
|
||||
endif
|
||||
|
||||
let [ver; items] = file
|
||||
if !self.version_check(ver)
|
||||
return
|
||||
endif
|
||||
|
||||
if self.type ==# 'file'
|
||||
endif
|
||||
|
||||
" Assume properly saved and sorted. unique sort is not necessary here
|
||||
call extend(self.candidates, items)
|
||||
|
||||
if self.is_loaded
|
||||
let self.candidates = s:uniq(self.candidates)
|
||||
endif
|
||||
|
||||
let self.mtime = getftime(mru_file)
|
||||
let self.is_loaded = 1
|
||||
endfunction
|
||||
function! s:mru.reload() abort
|
||||
call self.load(1)
|
||||
|
||||
call filter(self.candidates,
|
||||
\ ((self.type == 'file') ?
|
||||
\ "s:is_file_exist(v:val)" : "s:is_directory_exist(v:val)"))
|
||||
endfunction
|
||||
function! s:mru.append(path) abort
|
||||
call self.load()
|
||||
let index = index(self.candidates, a:path)
|
||||
if index == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if index > 0
|
||||
call remove(self.candidates, index)
|
||||
endif
|
||||
call insert(self.candidates, a:path)
|
||||
|
||||
if len(self.candidates) > self.limit
|
||||
let self.candidates = self.candidates[: self.limit - 1]
|
||||
endif
|
||||
|
||||
if localtime() > getftime(self.mru_file) + self.update_interval
|
||||
call self.save()
|
||||
endif
|
||||
endfunction
|
||||
function! s:mru.version_check(ver) abort
|
||||
let check = 1
|
||||
try
|
||||
let check = str2float(string(a:ver)) < str2float(string(self.version))
|
||||
catch
|
||||
" Ignore errors
|
||||
endtry
|
||||
|
||||
if check
|
||||
call s:print_error('Sorry, the version of MRU file is too old.')
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:resolve(fpath) abort
|
||||
return g:neomru#follow_links ? resolve(a:fpath) : a:fpath
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
" File MRU: 2
|
||||
"
|
||||
let s:file_mru = extend(deepcopy(s:mru), {
|
||||
\ 'type' : 'file',
|
||||
\ 'mru_file' : s:expand(g:neomru#file_mru_path),
|
||||
\ 'limit' : g:neomru#file_mru_limit,
|
||||
\ }
|
||||
\)
|
||||
function! s:file_mru.validate() abort
|
||||
if self.do_validate
|
||||
call filter(self.candidates, 's:is_file_exist(v:val)')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Directory MRU: 2
|
||||
let s:directory_mru = extend(deepcopy(s:mru), {
|
||||
\ 'type' : 'directory',
|
||||
\ 'mru_file' : s:expand(g:neomru#directory_mru_path),
|
||||
\ 'limit' : g:neomru#directory_mru_limit,
|
||||
\ }
|
||||
\)
|
||||
|
||||
function! s:directory_mru.validate() abort
|
||||
if self.do_validate
|
||||
call filter(self.candidates, 'getftype(v:val) ==# "dir"')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" Public Interface: 2
|
||||
|
||||
let s:MRUs.file = s:file_mru
|
||||
let s:MRUs.directory = s:directory_mru
|
||||
function! neomru#init() abort
|
||||
endfunction
|
||||
function! neomru#_import_file(path) abort
|
||||
let path = a:path
|
||||
if path == ''
|
||||
let path = s:expand('~/.unite/file_mru')
|
||||
endif
|
||||
|
||||
let candidates = s:file_mru.candidates
|
||||
let candidates += s:import(path)
|
||||
|
||||
" Load from v:oldfiles
|
||||
let candidates += map(v:oldfiles, "s:substitute_path_separator(v:val)")
|
||||
|
||||
let s:file_mru.candidates = s:uniq(candidates)
|
||||
call s:file_mru.save()
|
||||
endfunction
|
||||
function! neomru#_import_directory(path) abort
|
||||
let path = a:path
|
||||
if path == ''
|
||||
let path = s:expand('~/.unite/directory_mru')
|
||||
endif
|
||||
|
||||
let s:directory_mru.candidates = s:uniq(
|
||||
\ s:directory_mru.candidates + s:import(path))
|
||||
call s:directory_mru.save()
|
||||
endfunction
|
||||
function! neomru#_get_mrus() abort
|
||||
return s:MRUs
|
||||
endfunction
|
||||
function! neomru#_append() abort
|
||||
if &l:buftype =~ 'help\|nofile' || &l:previewwindow
|
||||
return
|
||||
endif
|
||||
call neomru#append(s:expand('%:p'))
|
||||
endfunction
|
||||
function! neomru#_gather_file_candidates() abort
|
||||
return neomru#_get_mrus().file.gather_candidates([], {'is_redraw': 0})
|
||||
endfunction
|
||||
function! neomru#_gather_directory_candidates() abort
|
||||
return neomru#_get_mrus().directory.gather_candidates([], {'is_redraw': 0})
|
||||
endfunction
|
||||
|
||||
function! neomru#append(filename) abort
|
||||
let path = s:fnamemodify(a:filename, ':p')
|
||||
if path !~ '\a\+:'
|
||||
let path = s:substitute_path_separator(
|
||||
\ simplify(s:resolve(path)))
|
||||
endif
|
||||
|
||||
" Append the current buffer to the mru list.
|
||||
if s:is_file_exist(path)
|
||||
call s:file_mru.append(path)
|
||||
endif
|
||||
|
||||
let filetype = getbufvar(bufnr(a:filename), '&filetype')
|
||||
if filetype ==# 'vimfiler' &&
|
||||
\ type(getbufvar(bufnr(a:filename), 'vimfiler')) == type({})
|
||||
let path = getbufvar(bufnr(a:filename), 'vimfiler').current_dir
|
||||
elseif filetype ==# 'vimshell' &&
|
||||
\ type(getbufvar(bufnr(a:filename), 'vimshell')) == type({})
|
||||
let path = getbufvar(bufnr(a:filename), 'vimshell').current_dir
|
||||
else
|
||||
let path = s:fnamemodify(path, ':p:h')
|
||||
endif
|
||||
|
||||
let path = s:substitute_path_separator(simplify(s:resolve(path)))
|
||||
" Chomp last /.
|
||||
let path = substitute(path, '/$', '', '')
|
||||
|
||||
" Append the current buffer to the mru list.
|
||||
if s:is_directory_exist(path)
|
||||
call s:directory_mru.append(path)
|
||||
endif
|
||||
endfunction
|
||||
function! neomru#_reload() abort
|
||||
for m in values(s:MRUs)
|
||||
call m.reload()
|
||||
endfor
|
||||
endfunction
|
||||
function! neomru#_save(...) abort
|
||||
let opts = a:0 >= 1 && type(a:1) == type({}) ? a:1 : {}
|
||||
|
||||
for m in values(s:MRUs)
|
||||
call m.save(opts)
|
||||
endfor
|
||||
endfunction
|
||||
function! neomru#_abbr(path, time) abort
|
||||
let abbr = (g:neomru#time_format == '') ? '' :
|
||||
\ strftime('(' . g:neomru#time_format . ') ', a:time)
|
||||
let abbr .= a:path
|
||||
return abbr
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
" Misc
|
||||
function! s:writefile(path, list) abort
|
||||
let path = fnamemodify(a:path, ':p')
|
||||
if !isdirectory(fnamemodify(path, ':h'))
|
||||
call mkdir(fnamemodify(path, ':h'), 'p')
|
||||
endif
|
||||
|
||||
call writefile(a:list, path)
|
||||
endfunction
|
||||
function! s:uniq(list, ...) abort
|
||||
return s:uniq_by(a:list, 'tolower(v:val)')
|
||||
endfunction
|
||||
function! s:uniq_by(list, f) abort
|
||||
let list = map(copy(a:list), printf('[v:val, %s]', a:f))
|
||||
let i = 0
|
||||
let seen = {}
|
||||
while i < len(list)
|
||||
let key = string(list[i][1])
|
||||
if has_key(seen, key)
|
||||
call remove(list, i)
|
||||
else
|
||||
let seen[key] = 1
|
||||
let i += 1
|
||||
endif
|
||||
endwhile
|
||||
return map(list, 'v:val[0]')
|
||||
endfunction
|
||||
function! s:is_file_exist(path) abort
|
||||
let ignore = !empty(g:neomru#file_mru_ignore_pattern)
|
||||
\ && a:path =~ g:neomru#file_mru_ignore_pattern
|
||||
return !ignore && (getftype(a:path) ==# 'file' ||
|
||||
\ getftype(a:path) ==# 'link' ||
|
||||
\ a:path =~ '^\h\w\+:')
|
||||
endfunction
|
||||
function! s:is_directory_exist(path) abort
|
||||
let ignore = !empty(g:neomru#directory_mru_ignore_pattern)
|
||||
\ && a:path =~ g:neomru#directory_mru_ignore_pattern
|
||||
return !ignore && (isdirectory(a:path) || a:path =~ '^\h\w\+:')
|
||||
endfunction
|
||||
function! s:import(path) abort
|
||||
if !filereadable(a:path)
|
||||
call s:print_error(printf('path "%s" is not found.', a:path))
|
||||
return []
|
||||
endif
|
||||
|
||||
let [ver; items] = readfile(a:path)
|
||||
if ver != '0.2.0'
|
||||
call s:print_error('Sorry, the version of MRU file is too old.')
|
||||
return []
|
||||
endif
|
||||
|
||||
let candidates = map(items, "split(v:val, '\t')[0]")
|
||||
" Load long file.
|
||||
if filereadable(a:path . '_long')
|
||||
let [ver; items] = readfile(a:path . '_long')
|
||||
let candidates += map(items, "split(v:val, '\t')[0]")
|
||||
endif
|
||||
|
||||
return map(candidates, "substitute(s:substitute_path_separator(
|
||||
\ v:val), '/$', '', '')")
|
||||
endfunction
|
||||
function! s:print_error(msg) abort
|
||||
echohl Error | echomsg '[neomru] ' . a:msg | echohl None
|
||||
endfunction
|
||||
function! s:is_sudo() abort
|
||||
return $SUDO_USER != '' && $USER !=# $SUDO_USER
|
||||
\ && $HOME !=# expand('~'.$USER)
|
||||
\ && $HOME ==# expand('~'.$SUDO_USER)
|
||||
endfunction
|
14
bundle/neomru.vim/autoload/unite/sources/mru.vim
Normal file
14
bundle/neomru.vim/autoload/unite/sources/mru.vim
Normal file
@ -0,0 +1,14 @@
|
||||
"=============================================================================
|
||||
" FILE: mru.vim
|
||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
|
||||
" License: MIT license
|
||||
"=============================================================================
|
||||
|
||||
" For compatibility
|
||||
function! unite#sources#mru#define() abort
|
||||
let [file_mru_source, dir_mru_source] =
|
||||
\ deepcopy(unite#sources#neomru#define())
|
||||
let file_mru_source.name = 'file_mru'
|
||||
let dir_mru_source.name = 'directory_mru'
|
||||
return [file_mru_source, dir_mru_source]
|
||||
endfunction
|
142
bundle/neomru.vim/autoload/unite/sources/neomru.vim
Normal file
142
bundle/neomru.vim/autoload/unite/sources/neomru.vim
Normal file
@ -0,0 +1,142 @@
|
||||
"=============================================================================
|
||||
" FILE: neomru.vim
|
||||
" AUTHOR: Zhao Cai <caizhaoff@gmail.com>
|
||||
" Shougo Matsushita <Shougo.Matsu at gmail.com>
|
||||
" License: MIT license
|
||||
"=============================================================================
|
||||
|
||||
" 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
|
||||
let candidates = mru.gather_candidates(a:args, a:context)
|
||||
return exists('*unite#helper#paths2candidates') ?
|
||||
\ unite#helper#paths2candidates(candidates) :
|
||||
\ map(copy(candidates), "{
|
||||
\ 'word' : v:val,
|
||||
\ 'action__path' : v:val,
|
||||
\}")
|
||||
endfunction
|
||||
function! s:dir_mru_source.gather_candidates(args, context) abort
|
||||
let mru = neomru#_get_mrus().directory
|
||||
let candidates = mru.gather_candidates(a:args, a:context)
|
||||
return exists('*unite#helper#paths2candidates') ?
|
||||
\ unite#helper#paths2candidates(candidates) :
|
||||
\ map(copy(candidates), "{
|
||||
\ 'word' : v:val,
|
||||
\ 'action__path' : v:val,
|
||||
\}")
|
||||
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 = neomru#_abbr(path, getftime(candidate.action__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
|
185
bundle/neomru.vim/doc/neomru.txt
Normal file
185
bundle/neomru.vim/doc/neomru.txt
Normal file
@ -0,0 +1,185 @@
|
||||
*neomru.txt* MRU plugin includes unite.vim MRU sources.
|
||||
|
||||
Version: 1.0
|
||||
Author : Shougo <Shougo.Matsu@gmail.com>
|
||||
License: MIT license
|
||||
|
||||
CONTENTS *neomru-contents*
|
||||
|
||||
Usage |neomru-usage|
|
||||
Install |neomru-install|
|
||||
Configuration Examples |neomru-examples|
|
||||
Interface |neomru-interface|
|
||||
Variables |neomru-variables|
|
||||
Sources |neomru-sources|
|
||||
Commands |neomru-commands|
|
||||
Functions |neomru-functions|
|
||||
FAQ |neomru-faq|
|
||||
|
||||
==============================================================================
|
||||
USAGE *neomru-usage*
|
||||
|
||||
To browse a list of mru files.
|
||||
>
|
||||
:Unite neomru/file
|
||||
:Unite file_mru
|
||||
<
|
||||
To browse a list of mru directories.
|
||||
>
|
||||
:Unite neomru/directory
|
||||
:Unite directory_mru
|
||||
>
|
||||
nnoremap <silent> [unite]d
|
||||
\ :<C-u>Unite -buffer-name=files -default-action=lcd neomru/directory<CR>
|
||||
<
|
||||
Note: To import previous version of unite mru candidates, you must use
|
||||
|:NeoMRUImportFile| and |:NeoMRUImportDirectory| commands.
|
||||
|
||||
==============================================================================
|
||||
INSTALL *neomru-install*
|
||||
|
||||
Requirements: unite.vim
|
||||
|
||||
https://github.com/Shougo/unite.vim
|
||||
|
||||
==============================================================================
|
||||
INTERFACE *neomru-interface*
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
VARIABLES *neomru-variables*
|
||||
|
||||
*g:neomru#time_format*
|
||||
g:neomru#time_format
|
||||
Specify the output format of the modified file
|
||||
in MRU sources. Uses |strftime()| formatting.
|
||||
Note: It is not access time format.
|
||||
*g:neomru#filename_format*
|
||||
g:neomru#filename_format
|
||||
Specify the output format of the filename of in MRU sources.
|
||||
The format is same to |fnamemodify()|. If this variable is
|
||||
empty, drawing speed is faster.
|
||||
g:neomru#do_validate *g:neomru#do_validate*
|
||||
Specify whether automatically remove invalid file paths from
|
||||
mru history.
|
||||
*g:neomru#update_interval*
|
||||
g:neomru#update_interval
|
||||
Specify the update interval to save updated mru
|
||||
files/directories to disk.
|
||||
g:neomru#file_mru_path *g:neomru#file_mru_path*
|
||||
Specifies the file to write the information of most recent
|
||||
used files.
|
||||
|
||||
Default value is "$XDG_CACHE_HOME/neomru/file" or
|
||||
expand("~/.cache/neomru/file"); the absolute path of it.
|
||||
|
||||
g:neomru#file_mru_limit *g:neomru#file_mru_limit*
|
||||
The number of recent file candidates to show in default
|
||||
file_mru window.
|
||||
*g:neomru#file_mru_ignore_pattern*
|
||||
g:neomru#file_mru_ignore_pattern
|
||||
The ignore regex pattern of neomru/file source.
|
||||
Refer autoload/neomru.vim about the default
|
||||
value.
|
||||
Note: This variable is deprecated. Please use
|
||||
|unite#custom#source()| instead.
|
||||
Note: This variable must be set before using |unite|.
|
||||
*g:neomru#directory_mru_path*
|
||||
g:neomru#directory_mru_path
|
||||
|
||||
Default value is "$XDG_CACHE_HOME/neomru/directory" or
|
||||
expand("~/.cache/neomru/directory"); the absolute path of it.
|
||||
|
||||
*g:neomru#directory_mru_limit*
|
||||
g:neomru#directory_mru_limit
|
||||
*g:neomru#directory_mru_ignore_pattern*
|
||||
g:neomru#directory_mru_ignore_pattern
|
||||
The ignore regexp pattern of neomru/directory source.
|
||||
Refer autoload/neomru.vim about the default
|
||||
value.
|
||||
|
||||
*g:neomru#follow_links*
|
||||
g:neomru#follow_links
|
||||
A boolean which determines whether symbolic or hard-linked
|
||||
files should be followed (resolved): if false, symlinked
|
||||
files and directories are listed in the unite buffer using the
|
||||
symlink's path; if true, they are listed using the real path.
|
||||
|
||||
The default value is 0 (false).
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
SOURCES *neomru-sources*
|
||||
|
||||
*unite-source-neomru/file*
|
||||
neomru/file
|
||||
*unite-source-file_mru*
|
||||
file_mru
|
||||
Nominates files you used recently as candidates, ordering
|
||||
by time series.
|
||||
|
||||
The mru code is overhauled to tracking long mru history.
|
||||
Set a large number like 5000 for the long limit will not
|
||||
impact vim performance.
|
||||
|
||||
Source custom variables:
|
||||
fnamemodify
|
||||
a flag to modify given paths.
|
||||
Use |filename-modifiers|.
|
||||
(default is ':~')
|
||||
|
||||
*unite-source-neomru/directory*
|
||||
neomru/directory
|
||||
*unite-source-directory_mru*
|
||||
directory_mru
|
||||
Nominates directories you used recently as candidates,
|
||||
ordering by time series.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
COMMANDS *neomru-commands*
|
||||
|
||||
:NeoMRUReload *:NeoMRUReload*
|
||||
Reload MRU files.
|
||||
It validates the MRU files.
|
||||
|
||||
:NeoMRUSave *:NeoMRUSave*
|
||||
Save MRU files manually.
|
||||
|
||||
:NeoMRUImportFile [{path}] *:NeoMRUImportFile*
|
||||
Import the files from previous version of MRU {path} file and
|
||||
|v:oldfiles|.
|
||||
If {path} is omitted, "~/.unite/file_mru" is used.
|
||||
|
||||
:NeoMRUImportDirectory [{path}] *:NeoMRUImportDirectory*
|
||||
Import the directories from previous version of MRU {path}
|
||||
file.
|
||||
If {path} is omitted, "~/.unite/directory_mru" is used.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTIONS *neomru-functions*
|
||||
|
||||
*neomru#append()*
|
||||
neomru#append({filename})
|
||||
Include the specified file in the MRU list, mimicking a file
|
||||
open by unite/denite. This will mainly be used in
|
||||
|unite#custom#action()|/|denite#custom#action()|.
|
||||
|
||||
==============================================================================
|
||||
FAQ *neomru-faq*
|
||||
|
||||
Q: mru sources are slow in large mru files.
|
||||
https://github.com/Shougo/unite.vim/issues/422
|
||||
|
||||
A: You can set |g:neomru#do_validate| to 0. It is faster. But unite
|
||||
does not validate mru files.
|
||||
|
||||
Q: I want to restrict the files I see to the current project or the current
|
||||
directory in mru sources.
|
||||
https://github.com/Shougo/unite.vim/issues/456
|
||||
|
||||
A: You should use |unite-filter-matcher_project_files|. >
|
||||
call unite#custom#source(
|
||||
\ 'neomru/file', 'matchers',
|
||||
\ ['matcher_project_files', 'matcher_fuzzy'])
|
||||
<
|
||||
==============================================================================
|
||||
vim:tw=78:ts=8:ft=help:norl:noet:fen:
|
39
bundle/neomru.vim/plugin/neomru.vim
Normal file
39
bundle/neomru.vim/plugin/neomru.vim
Normal file
@ -0,0 +1,39 @@
|
||||
"=============================================================================
|
||||
" FILE: neomru.vim
|
||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||
" License: MIT license
|
||||
"=============================================================================
|
||||
|
||||
if exists('g:loaded_neomru')
|
||||
\ || ($SUDO_USER != '' && $USER !=# $SUDO_USER
|
||||
\ && $HOME !=# expand('~'.$USER)
|
||||
\ && $HOME ==# expand('~'.$SUDO_USER))
|
||||
finish
|
||||
endif
|
||||
|
||||
command! NeoMRUReload call neomru#_reload()
|
||||
command! NeoMRUSave call neomru#_save()
|
||||
|
||||
command! -nargs=? -complete=file NeoMRUImportFile
|
||||
\ call neomru#_import_file(<q-args>)
|
||||
command! -nargs=? -complete=file NeoMRUImportDirectory
|
||||
\ call neomru#_import_directory(<q-args>)
|
||||
|
||||
augroup neomru
|
||||
autocmd!
|
||||
autocmd BufEnter,VimEnter,BufWinEnter,BufWritePost *
|
||||
\ call s:append(expand('<amatch>'))
|
||||
autocmd VimLeavePre *
|
||||
\ call neomru#_save({'event' : 'VimLeavePre'})
|
||||
augroup END
|
||||
|
||||
let g:loaded_neomru = 1
|
||||
|
||||
function! s:append(path) abort
|
||||
if bufnr('%') != expand('<abuf>')
|
||||
\ || a:path == ''
|
||||
return
|
||||
endif
|
||||
|
||||
call neomru#_append()
|
||||
endfunction
|
@ -0,0 +1,21 @@
|
||||
# ============================================================================
|
||||
# FILE: directory_mru.py
|
||||
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
|
||||
# License: MIT license
|
||||
# ============================================================================
|
||||
|
||||
from .base import Base
|
||||
|
||||
|
||||
class Source(Base):
|
||||
|
||||
def __init__(self, vim):
|
||||
Base.__init__(self, vim)
|
||||
|
||||
self.name = 'directory_mru'
|
||||
self.kind = 'directory'
|
||||
self.default_action = 'cd'
|
||||
|
||||
def gather_candidates(self, context):
|
||||
return [{'word': x, 'action__path': x} for x
|
||||
in self.vim.call('neomru#_gather_directory_candidates')]
|
43
bundle/neomru.vim/rplugin/python3/denite/source/file_mru.py
Normal file
43
bundle/neomru.vim/rplugin/python3/denite/source/file_mru.py
Normal file
@ -0,0 +1,43 @@
|
||||
# ============================================================================
|
||||
# FILE: file_mru.py
|
||||
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
|
||||
# License: MIT license
|
||||
# ============================================================================
|
||||
|
||||
from .base import Base
|
||||
|
||||
|
||||
class Source(Base):
|
||||
|
||||
def __init__(self, vim):
|
||||
Base.__init__(self, vim)
|
||||
|
||||
self.name = 'file_mru'
|
||||
self.kind = 'file'
|
||||
self.sorters = []
|
||||
self.vars = {
|
||||
'fnamemodify': ':~',
|
||||
}
|
||||
|
||||
def gather_candidates(self, context):
|
||||
candidates = self.vim.call('neomru#_gather_file_candidates')
|
||||
|
||||
def time_format(x):
|
||||
return self.vim.call('getftime', x)
|
||||
|
||||
def path_format(x):
|
||||
return self.vim.call('fnamemodify', x, self.vars['fnamemodify'])
|
||||
|
||||
if self.vim.vars['neomru#time_format'] == '':
|
||||
return [{
|
||||
'word': path_format(x),
|
||||
'abbr': path_format(x),
|
||||
'action__path': x
|
||||
} for x in candidates]
|
||||
else:
|
||||
return [{
|
||||
'word': path_format(x),
|
||||
'abbr': self.vim.call('neomru#_abbr',
|
||||
path_format(x), time_format(x)),
|
||||
'action__path': x
|
||||
} for x in candidates]
|
@ -1822,6 +1822,7 @@ LAYER OPTIONS
|
||||
1. `format_on_save`: disabled by default.
|
||||
2. `format_method`: set the format plugin, default plugin is `neoformat`.
|
||||
You can also use `vim-codefmt`.
|
||||
3. `silent_format`: Runs the formatter without any messages.
|
||||
|
||||
KEY BINDINGS
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user