2019-12-31 13:50:25 +08:00
|
|
|
if exists('g:loaded_nerdtree_autoload')
|
2013-01-05 09:08:06 +08:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_nerdtree_autoload = 1
|
|
|
|
|
2019-12-31 13:50:25 +08:00
|
|
|
let s:rootNERDTreePath = resolve(expand('<sfile>:p:h:h'))
|
2019-09-24 13:19:27 +08:00
|
|
|
|
|
|
|
"FUNCTION: nerdtree#version(...) {{{1
|
|
|
|
" If any value is given as an argument, the entire line of text from the
|
|
|
|
" change log is shown for the current version; otherwise, only the version
|
|
|
|
" number is shown.
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#version(...) abort
|
2019-07-02 10:13:20 +08:00
|
|
|
let l:text = 'Unknown'
|
2019-10-01 21:17:32 +08:00
|
|
|
try
|
2019-12-31 13:50:25 +08:00
|
|
|
let l:changelog = readfile(join([s:rootNERDTreePath, 'CHANGELOG.md'], nerdtree#slash()))
|
2019-10-01 21:17:32 +08:00
|
|
|
let l:line = 0
|
|
|
|
while l:line <= len(l:changelog)
|
2019-12-31 14:29:58 +08:00
|
|
|
if l:changelog[l:line] =~# '\d\+\.\d\+'
|
2019-10-01 21:17:32 +08:00
|
|
|
let l:text = substitute(l:changelog[l:line], '.*\(\d\+.\d\+\).*', '\1', '')
|
|
|
|
let l:text .= substitute(l:changelog[l:line+1], '^.\{-}\(\.\d\+\).\{-}:\(.*\)', a:0>0 ? '\1:\2' : '\1', '')
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
let l:line += 1
|
|
|
|
endwhile
|
|
|
|
catch
|
|
|
|
endtry
|
2019-07-02 10:13:20 +08:00
|
|
|
return l:text
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" SECTION: General Functions {{{1
|
|
|
|
"============================================================
|
|
|
|
|
2021-02-11 11:20:04 +08:00
|
|
|
" FUNCTION: nerdtree#closeTreeOnOpen() {{{2
|
2021-02-10 10:34:24 +08:00
|
|
|
function! nerdtree#closeTreeOnOpen() abort
|
|
|
|
return g:NERDTreeQuitOnOpen == 1 || g:NERDTreeQuitOnOpen == 3
|
|
|
|
endfunction
|
|
|
|
|
2021-02-11 11:20:04 +08:00
|
|
|
" FUNCTION: nerdtree#closeBookmarksOnOpen() {{{2
|
2021-02-10 10:34:24 +08:00
|
|
|
function! nerdtree#closeBookmarksOnOpen() abort
|
|
|
|
return g:NERDTreeQuitOnOpen == 2 || g:NERDTreeQuitOnOpen == 3
|
|
|
|
endfunction
|
|
|
|
|
2020-07-14 20:53:00 +08:00
|
|
|
" FUNCTION: nerdtree#slash() {{{2
|
|
|
|
" Return the path separator used by the underlying file system. Special
|
|
|
|
" consideration is taken for the use of the 'shellslash' option on Windows
|
|
|
|
" systems.
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#slash() abort
|
2019-07-02 11:29:56 +08:00
|
|
|
if nerdtree#runningWindows()
|
|
|
|
if exists('+shellslash') && &shellslash
|
|
|
|
return '/'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return '\'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return '/'
|
|
|
|
endfunction
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
"FUNCTION: nerdtree#checkForBrowse(dir) {{{2
|
2015-11-14 19:50:01 +08:00
|
|
|
"inits a window tree in the current buffer if appropriate
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#checkForBrowse(dir) abort
|
2016-10-14 23:34:08 +08:00
|
|
|
if !isdirectory(a:dir)
|
|
|
|
return
|
2013-01-05 09:08:06 +08:00
|
|
|
endif
|
2016-10-14 23:34:08 +08:00
|
|
|
|
|
|
|
if s:reuseWin(a:dir)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call g:NERDTreeCreator.CreateWindowTree(a:dir)
|
|
|
|
endfunction
|
|
|
|
|
2016-10-17 22:05:50 +08:00
|
|
|
"FUNCTION: s:reuseWin(dir) {{{2
|
|
|
|
"finds a NERDTree buffer with root of dir, and opens it.
|
2016-10-14 23:34:08 +08:00
|
|
|
function! s:reuseWin(dir) abort
|
2019-12-31 13:50:25 +08:00
|
|
|
let path = g:NERDTreePath.New(fnamemodify(a:dir, ':p'))
|
2016-10-14 23:34:08 +08:00
|
|
|
|
2019-12-31 13:50:25 +08:00
|
|
|
for i in range(1, bufnr('$'))
|
2016-10-17 22:05:50 +08:00
|
|
|
unlet! nt
|
2019-12-31 13:50:25 +08:00
|
|
|
let nt = getbufvar(i, 'NERDTree')
|
2016-10-14 23:34:08 +08:00
|
|
|
if empty(nt)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
if nt.isWinTree() && nt.root.path.equals(path)
|
2019-12-31 13:50:25 +08:00
|
|
|
call nt.setPreviousBuf(bufnr('#'))
|
|
|
|
exec 'buffer ' . i
|
2016-10-14 23:34:08 +08:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return 0
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" FUNCTION: nerdtree#completeBookmarks(A,L,P) {{{2
|
|
|
|
" completion function for the bookmark commands
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#completeBookmarks(A,L,P) abort
|
2013-01-05 09:08:06 +08:00
|
|
|
return filter(g:NERDTreeBookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"')
|
|
|
|
endfunction
|
|
|
|
|
2020-08-15 06:06:03 +08:00
|
|
|
"FUNCTION: nerdtree#compareNodes(n1, n2) {{{2
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#compareNodes(n1, n2) abort
|
2020-08-15 06:06:03 +08:00
|
|
|
return nerdtree#compareNodePaths(a:n1.path, a:n2.path)
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
2020-08-15 06:06:03 +08:00
|
|
|
"FUNCTION: nerdtree#compareNodePaths(p1, p2) {{{2
|
|
|
|
function! nerdtree#compareNodePaths(p1, p2) abort
|
|
|
|
let sortKey1 = a:p1.getSortKey()
|
|
|
|
let sortKey2 = a:p2.getSortKey()
|
2016-01-19 16:21:13 +08:00
|
|
|
let i = 0
|
|
|
|
while i < min([len(sortKey1), len(sortKey2)])
|
|
|
|
" Compare chunks upto common length.
|
|
|
|
" If chunks have different type, the one which has
|
|
|
|
" integer type is the lesser.
|
2021-09-21 03:01:21 +08:00
|
|
|
if type(sortKey1[i]) == type(sortKey2[i])
|
2016-01-19 16:21:13 +08:00
|
|
|
if sortKey1[i] <# sortKey2[i]
|
|
|
|
return - 1
|
|
|
|
elseif sortKey1[i] ># sortKey2[i]
|
|
|
|
return 1
|
|
|
|
endif
|
2021-09-21 03:01:21 +08:00
|
|
|
elseif type(sortKey1[i]) == type(0)
|
2016-01-19 16:21:13 +08:00
|
|
|
return -1
|
2021-09-21 03:01:21 +08:00
|
|
|
elseif type(sortKey2[i]) == type(0)
|
2016-01-19 16:21:13 +08:00
|
|
|
return 1
|
|
|
|
endif
|
2021-09-21 03:01:21 +08:00
|
|
|
let i += 1
|
2016-01-19 16:21:13 +08:00
|
|
|
endwhile
|
|
|
|
|
|
|
|
" Keys are identical upto common length.
|
|
|
|
" The key which has smaller chunks is the lesser one.
|
|
|
|
if len(sortKey1) < len(sortKey2)
|
2015-05-09 22:38:16 +08:00
|
|
|
return -1
|
2016-01-19 16:21:13 +08:00
|
|
|
elseif len(sortKey1) > len(sortKey2)
|
2015-05-09 22:38:16 +08:00
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
" FUNCTION: nerdtree#deprecated(func, [msg]) {{{2
|
|
|
|
" Issue a deprecation warning for a:func. If a second arg is given, use this
|
|
|
|
" as the deprecation message
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#deprecated(func, ...) abort
|
2013-01-05 09:08:06 +08:00
|
|
|
let msg = a:0 ? a:func . ' ' . a:1 : a:func . ' is deprecated'
|
|
|
|
|
|
|
|
if !exists('s:deprecationWarnings')
|
|
|
|
let s:deprecationWarnings = {}
|
|
|
|
endif
|
|
|
|
if !has_key(s:deprecationWarnings, a:func)
|
|
|
|
let s:deprecationWarnings[a:func] = 1
|
|
|
|
echomsg msg
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2019-08-09 10:00:35 +08:00
|
|
|
" FUNCTION: nerdtree#exec(cmd, ignoreAll) {{{2
|
|
|
|
" Same as :exec cmd but, if ignoreAll is TRUE, set eventignore=all for the duration
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#exec(cmd, ignoreAll) abort
|
2019-12-31 14:40:39 +08:00
|
|
|
let old_ei = &eventignore
|
2019-08-09 10:00:35 +08:00
|
|
|
if a:ignoreAll
|
2019-12-31 14:40:39 +08:00
|
|
|
set eventignore=all
|
2019-08-09 10:00:35 +08:00
|
|
|
endif
|
2020-01-16 23:51:12 +08:00
|
|
|
try
|
|
|
|
exec a:cmd
|
|
|
|
finally
|
|
|
|
let &eventignore = old_ei
|
|
|
|
endtry
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" FUNCTION: nerdtree#has_opt(options, name) {{{2
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#has_opt(options, name) abort
|
2019-12-31 14:29:58 +08:00
|
|
|
return has_key(a:options, a:name) && a:options[a:name] ==# 1
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
2013-04-14 03:32:25 +08:00
|
|
|
" FUNCTION: nerdtree#loadClassFiles() {{{2
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#loadClassFiles() abort
|
2013-04-14 03:32:25 +08:00
|
|
|
runtime lib/nerdtree/path.vim
|
|
|
|
runtime lib/nerdtree/menu_controller.vim
|
|
|
|
runtime lib/nerdtree/menu_item.vim
|
|
|
|
runtime lib/nerdtree/key_map.vim
|
|
|
|
runtime lib/nerdtree/bookmark.vim
|
|
|
|
runtime lib/nerdtree/tree_file_node.vim
|
|
|
|
runtime lib/nerdtree/tree_dir_node.vim
|
|
|
|
runtime lib/nerdtree/opener.vim
|
|
|
|
runtime lib/nerdtree/creator.vim
|
2014-07-06 03:51:21 +08:00
|
|
|
runtime lib/nerdtree/flag_set.vim
|
2014-07-08 05:59:28 +08:00
|
|
|
runtime lib/nerdtree/nerdtree.vim
|
|
|
|
runtime lib/nerdtree/ui.vim
|
2014-07-18 03:16:57 +08:00
|
|
|
runtime lib/nerdtree/event.vim
|
|
|
|
runtime lib/nerdtree/notifier.vim
|
2013-04-14 03:32:25 +08:00
|
|
|
endfunction
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
" FUNCTION: nerdtree#postSourceActions() {{{2
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#postSourceActions() abort
|
2015-12-03 05:16:34 +08:00
|
|
|
call g:NERDTreeBookmark.CacheBookmarks(1)
|
2014-07-08 02:36:34 +08:00
|
|
|
call nerdtree#ui_glue#createDefaultBindings()
|
2013-01-05 09:08:06 +08:00
|
|
|
|
|
|
|
"load all nerdtree plugins
|
|
|
|
runtime! nerdtree_plugin/**/*.vim
|
|
|
|
endfunction
|
|
|
|
|
2023-10-22 20:17:01 +08:00
|
|
|
"FUNCTION: nerdtree#runningWindows() {{{2
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#runningWindows() abort
|
2019-12-31 13:50:25 +08:00
|
|
|
return has('win16') || has('win32') || has('win64')
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
2023-10-22 20:17:01 +08:00
|
|
|
"FUNCTION: nerdtree#runningCygwin() {{{2
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#runningCygwin() abort
|
2019-12-31 13:50:25 +08:00
|
|
|
return has('win32unix')
|
2017-10-27 15:06:51 +08:00
|
|
|
endfunction
|
|
|
|
|
2023-10-22 20:17:01 +08:00
|
|
|
"FUNCTION: nerdtree#runningMac() {{{2
|
|
|
|
function! nerdtree#runningMac() abort
|
|
|
|
return has('gui_mac') || has('gui_macvim') || has('mac') || has('osx')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" FUNCTION: nerdtree#osDefaultCaseSensitiveFS() {{{2
|
|
|
|
function! nerdtree#osDefaultCaseSensitiveFS() abort
|
|
|
|
return s:osDefaultCaseSensitiveFS
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" FUNCTION: nerdtree#caseSensitiveFS() {{{2
|
|
|
|
function! nerdtree#caseSensitiveFS() abort
|
|
|
|
return g:NERDTreeCaseSensitiveFS == 1 ||
|
|
|
|
\((g:NERDTreeCaseSensitiveFS == 2 || g:NERDTreeCaseSensitiveFS == 3) &&
|
|
|
|
\nerdtree#osDefaultCaseSensitiveFS())
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#pathEquals(lhs, rhs) {{{2
|
|
|
|
function! nerdtree#pathEquals(lhs, rhs) abort
|
|
|
|
if nerdtree#caseSensitiveFS()
|
|
|
|
return a:lhs ==# a:rhs
|
|
|
|
else
|
|
|
|
return a:lhs ==? a:rhs
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2024-02-07 19:37:25 +08:00
|
|
|
"FUNCTION: nerdtree#onBufLeave() {{{2
|
|
|
|
" used for handling the nerdtree BufLeave/WinLeave events.
|
|
|
|
function! nerdtree#onBufLeave() abort
|
|
|
|
" detect whether we are in the middle of sourcing a session.
|
|
|
|
" if it is a buffer from the sourced session we need to restore it.
|
|
|
|
if exists('g:SessionLoad') && !exists('b:NERDTree')
|
|
|
|
let bname = bufname('%')
|
|
|
|
" is the buffer for a tab tree?
|
|
|
|
if bname =~# '^' . g:NERDTreeCreator.BufNamePrefix() . 'tab_\d\+$'
|
|
|
|
" rename loaded buffer and mark it as trash to prevent this event
|
|
|
|
" getting fired again
|
|
|
|
exec 'file TRASH_' . bname
|
|
|
|
" delete the trash buffer
|
|
|
|
exec 'bwipeout!'
|
|
|
|
" rescue the tab tree at the current working directory
|
|
|
|
call g:NERDTreeCreator.CreateTabTree(getcwd())
|
|
|
|
" is the buffer for a window tree?
|
|
|
|
elseif bname =~# '^' . g:NERDTreeCreator.BufNamePrefix(). 'win_\d\+$'
|
|
|
|
" rescue the window tree at the current working directory
|
|
|
|
call g:NERDTreeCreator.CreateWindowTree(getcwd())
|
|
|
|
else " unknown buffer type
|
|
|
|
" rename buffer to mark it as broken.
|
|
|
|
exec 'file BROKEN_' . bname
|
|
|
|
call nerdtree#echoError('Failed to restore "' . bname . '" from session. Is this session created with an older version of NERDTree?')
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
if g:NERDTree.IsOpen()
|
|
|
|
call b:NERDTree.ui.saveScreenState()
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
" SECTION: View Functions {{{1
|
|
|
|
"============================================================
|
2014-07-08 03:12:05 +08:00
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
"FUNCTION: nerdtree#echo {{{2
|
|
|
|
"A wrapper for :echo. Appends 'NERDTree:' on the front of all messages
|
|
|
|
"
|
|
|
|
"Args:
|
|
|
|
"msg: the message to echo
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#echo(msg) abort
|
2019-07-15 03:17:56 +08:00
|
|
|
redraw
|
2019-12-31 13:50:25 +08:00
|
|
|
echomsg empty(a:msg) ? '' : ('NERDTree: ' . a:msg)
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#echoError {{{2
|
|
|
|
"Wrapper for nerdtree#echo, sets the message type to errormsg for this message
|
|
|
|
"Args:
|
|
|
|
"msg: the message to echo
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#echoError(msg) abort
|
2013-01-05 09:08:06 +08:00
|
|
|
echohl errormsg
|
|
|
|
call nerdtree#echo(a:msg)
|
|
|
|
echohl normal
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#echoWarning {{{2
|
|
|
|
"Wrapper for nerdtree#echo, sets the message type to warningmsg for this message
|
|
|
|
"Args:
|
|
|
|
"msg: the message to echo
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#echoWarning(msg) abort
|
2013-01-05 09:08:06 +08:00
|
|
|
echohl warningmsg
|
|
|
|
call nerdtree#echo(a:msg)
|
|
|
|
echohl normal
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#renderView {{{2
|
2019-12-31 14:34:55 +08:00
|
|
|
function! nerdtree#renderView() abort
|
2014-07-08 05:59:28 +08:00
|
|
|
call b:NERDTree.render()
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
2023-10-22 20:17:01 +08:00
|
|
|
if nerdtree#runningWindows()
|
|
|
|
let s:osDefaultCaseSensitiveFS = 0
|
|
|
|
elseif nerdtree#runningMac()
|
|
|
|
let s:osDefaultCaseSensitiveFS = 0
|
|
|
|
else
|
|
|
|
let s:osDefaultCaseSensitiveFS = 1
|
|
|
|
endif
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|