mirror of
				https://github.com/amix/vimrc
				synced 2025-10-31 06:33:35 +08:00 
			
		
		
		
	Updated plugins
This commit is contained in:
		| @ -142,18 +142,9 @@ function! s:chRoot(node) | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1 | ||||
| " changes the current root to CWD | ||||
| " Change the NERDTree root to match the current working directory. | ||||
| function! nerdtree#ui_glue#chRootCwd() | ||||
|     try | ||||
|         let cwd = g:NERDTreePath.New(getcwd()) | ||||
|     catch /^NERDTree.InvalidArgumentsError/ | ||||
|         call nerdtree#echo("current directory does not exist.") | ||||
|         return | ||||
|     endtry | ||||
|     if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str() | ||||
|        return | ||||
|     endif | ||||
|     call s:chRoot(g:NERDTreeDirNode.New(cwd, b:NERDTree)) | ||||
|     NERDTreeCWD | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1 | ||||
| @ -357,35 +348,6 @@ function! s:handleMiddleMouse() | ||||
|     endif | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:jumpToChild(direction) {{{2 | ||||
| " Args: | ||||
| " direction: 0 if going to first child, 1 if going to last | ||||
| function! s:jumpToChild(currentNode, direction) | ||||
|     if a:currentNode.isRoot() | ||||
|         return nerdtree#echo("cannot jump to " . (a:direction ? "last" : "first") .  " child") | ||||
|     end | ||||
|     let dirNode = a:currentNode.parent | ||||
|     let childNodes = dirNode.getVisibleChildren() | ||||
|  | ||||
|     let targetNode = childNodes[0] | ||||
|     if a:direction | ||||
|         let targetNode = childNodes[len(childNodes) - 1] | ||||
|     endif | ||||
|  | ||||
|     if targetNode.equals(a:currentNode) | ||||
|         let siblingDir = a:currentNode.parent.findOpenDirSiblingWithVisibleChildren(a:direction) | ||||
|         if siblingDir != {} | ||||
|             let indx = a:direction ? siblingDir.getVisibleChildCount()-1 : 0 | ||||
|             let targetNode = siblingDir.getChildByIndex(indx, 1) | ||||
|         endif | ||||
|     endif | ||||
|  | ||||
|     call targetNode.putCursorHere(1, 0) | ||||
|  | ||||
|     call b:NERDTree.ui.centerView() | ||||
| endfunction | ||||
|  | ||||
|  | ||||
| " FUNCTION: nerdtree#ui_glue#invokeKeyMap(key) {{{1 | ||||
| "this is needed since I cant figure out how to invoke dict functions from a | ||||
| "key map | ||||
| @ -393,41 +355,55 @@ function! nerdtree#ui_glue#invokeKeyMap(key) | ||||
|     call g:NERDTreeKeyMap.Invoke(a:key) | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:jumpToFirstChild() {{{1 | ||||
| " wrapper for the jump to child method | ||||
| " FUNCTION: s:jumpToFirstChild(node) {{{1 | ||||
| function! s:jumpToFirstChild(node) | ||||
|     call s:jumpToChild(a:node, 0) | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:jumpToLastChild() {{{1 | ||||
| " wrapper for the jump to child method | ||||
| " FUNCTION: s:jumpToLastChild(node) {{{1 | ||||
| function! s:jumpToLastChild(node) | ||||
|     call s:jumpToChild(a:node, 1) | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:jumpToChild(node, last) {{{2 | ||||
| " Jump to the first or last child node at the same file system level. | ||||
| " | ||||
| " Args: | ||||
| " node: the node on which the cursor currently sits | ||||
| " last: 1 (true) if jumping to last child, 0 (false) if jumping to first | ||||
| function! s:jumpToChild(node, last) | ||||
|     let l:node = a:node.path.isDirectory ? a:node.getCascadeRoot() : a:node | ||||
|  | ||||
|     if l:node.isRoot() | ||||
|         return | ||||
|     endif | ||||
|  | ||||
|     let l:parent = l:node.parent | ||||
|     let l:children = l:parent.getVisibleChildren() | ||||
|  | ||||
|     let l:target = a:last ? l:children[len(l:children) - 1] : l:children[0] | ||||
|  | ||||
|     call l:target.putCursorHere(1, 0) | ||||
|     call b:NERDTree.ui.centerView() | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:jumpToParent(node) {{{1 | ||||
| " Move the cursor to the parent of the specified node. For a cascade, move to | ||||
| " the parent of the cascade's highest node. At the root, do nothing. | ||||
| " Move the cursor to the parent of the specified node.  For a cascade, move to | ||||
| " the parent of the cascade's first node.  At the root node, do nothing. | ||||
| function! s:jumpToParent(node) | ||||
|     let l:parent = a:node.parent | ||||
|     let l:node = a:node.path.isDirectory ? a:node.getCascadeRoot() : a:node | ||||
|  | ||||
|     " If "a:node" represents a directory, back out of its cascade. | ||||
|     if a:node.path.isDirectory | ||||
|         while !empty(l:parent) && !l:parent.isRoot() | ||||
|             if index(l:parent.getCascade(), a:node) >= 0 | ||||
|                 let l:parent = l:parent.parent | ||||
|             else | ||||
|                 break | ||||
|             endif | ||||
|         endwhile | ||||
|     if l:node.isRoot() | ||||
|         return | ||||
|     endif | ||||
|  | ||||
|     if !empty(l:parent) | ||||
|         call l:parent.putCursorHere(1, 0) | ||||
|         call b:NERDTree.ui.centerView() | ||||
|     else | ||||
|     if empty(l:node.parent) | ||||
|         call nerdtree#echo('could not jump to parent node') | ||||
|         return | ||||
|     endif | ||||
|  | ||||
|     call l:node.parent.putCursorHere(1, 0) | ||||
|     call b:NERDTree.ui.centerView() | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:jumpToRoot() {{{1 | ||||
| @ -447,19 +423,22 @@ function! s:jumpToPrevSibling(node) | ||||
|     call s:jumpToSibling(a:node, 0) | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:jumpToSibling(currentNode, forward) {{{2 | ||||
| " moves the cursor to the sibling of the current node in the given direction | ||||
| " FUNCTION: s:jumpToSibling(node, forward) {{{2 | ||||
| " Move the cursor to the next or previous node at the same file system level. | ||||
| " | ||||
| " Args: | ||||
| " forward: 1 if the cursor should move to the next sibling, 0 if it should | ||||
| " move back to the previous sibling | ||||
| function! s:jumpToSibling(currentNode, forward) | ||||
|     let sibling = a:currentNode.findSibling(a:forward) | ||||
| " node: the node on which the cursor currently sits | ||||
| " forward: 0 to jump to previous sibling, 1 to jump to next sibling | ||||
| function! s:jumpToSibling(node, forward) | ||||
|     let l:node = a:node.path.isDirectory ? a:node.getCascadeRoot() : a:node | ||||
|     let l:sibling = l:node.findSibling(a:forward) | ||||
|  | ||||
|     if !empty(sibling) | ||||
|         call sibling.putCursorHere(1, 0) | ||||
|         call b:NERDTree.ui.centerView() | ||||
|     if empty(l:sibling) | ||||
|         return | ||||
|     endif | ||||
|  | ||||
|     call l:sibling.putCursorHere(1, 0) | ||||
|     call b:NERDTree.ui.centerView() | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: nerdtree#ui_glue#openBookmark(name) {{{1 | ||||
|  | ||||
| @ -142,8 +142,8 @@ The following features and functionality are provided by the NERD tree: | ||||
|     current tab does not exist, a new one will be initialized. | ||||
|  | ||||
| :NERDTreeCWD                                                    *:NERDTreeCWD* | ||||
|     Change tree root to current directory. If no NERD tree exists for this | ||||
|     tab, a new tree will be opened. | ||||
|     Change the NERDTree root to the current working directory.  If no | ||||
|     NERDTree exists for this tab, a new one is opened. | ||||
|  | ||||
| ------------------------------------------------------------------------------ | ||||
| 2.2. Bookmarks                                             *NERDTreeBookmarks* | ||||
| @ -522,7 +522,7 @@ Default key: cd | ||||
| Map option: NERDTreeMapChdir | ||||
| Applies to: files and directories. | ||||
|  | ||||
| Change vims current working directory to that of the selected node. | ||||
| Change Vim's current working directory to that of the selected node. | ||||
|  | ||||
| ------------------------------------------------------------------------------ | ||||
|                                                                  *NERDTree-CD* | ||||
| @ -530,7 +530,7 @@ Default key: CD | ||||
| Map option: NERDTreeMapCWD | ||||
| Applies to: no restrictions. | ||||
|  | ||||
| Change tree root to vims current working directory. | ||||
| Change the NERDTree root to Vim's current working directory. | ||||
|  | ||||
| ------------------------------------------------------------------------------ | ||||
|                                                                   *NERDTree-I* | ||||
|  | ||||
| @ -343,7 +343,12 @@ function! s:Bookmark.Write() | ||||
|     for j in s:Bookmark.InvalidBookmarks() | ||||
|         call add(bookmarkStrings, j) | ||||
|     endfor | ||||
|     call writefile(bookmarkStrings, g:NERDTreeBookmarksFile) | ||||
|  | ||||
|     try | ||||
|         call writefile(bookmarkStrings, g:NERDTreeBookmarksFile) | ||||
|     catch | ||||
|         call nerdtree#echoError("Failed to write bookmarks file. Make sure g:NERDTreeBookmarksFile points to a valid location.") | ||||
|     endtry | ||||
| endfunction | ||||
|  | ||||
| " vim: set sw=4 sts=4 et fdm=marker: | ||||
|  | ||||
| @ -284,16 +284,21 @@ endfunction | ||||
|  | ||||
| " FUNCTION: s:Creator._setCommonBufOptions() {{{1 | ||||
| function! s:Creator._setCommonBufOptions() | ||||
|     "throwaway buffer options | ||||
|     setlocal noswapfile | ||||
|     setlocal buftype=nofile | ||||
|  | ||||
|     " Options for a non-file/control buffer. | ||||
|     setlocal bufhidden=hide | ||||
|     setlocal nowrap | ||||
|     setlocal buftype=nofile | ||||
|     setlocal noswapfile | ||||
|  | ||||
|     " Options for controlling buffer/window appearance. | ||||
|     setlocal foldcolumn=0 | ||||
|     setlocal foldmethod=manual | ||||
|     setlocal nofoldenable | ||||
|     setlocal nobuflisted | ||||
|     setlocal nofoldenable | ||||
|     setlocal nolist | ||||
|     setlocal nospell | ||||
|     setlocal nowrap | ||||
|  | ||||
|     if g:NERDTreeShowLineNumbers | ||||
|         setlocal nu | ||||
|     else | ||||
| @ -311,6 +316,7 @@ function! s:Creator._setCommonBufOptions() | ||||
|  | ||||
|     call self._setupStatusline() | ||||
|     call self._bindMappings() | ||||
|  | ||||
|     setlocal filetype=nerdtree | ||||
| endfunction | ||||
|  | ||||
|  | ||||
| @ -243,6 +243,9 @@ endfunction | ||||
|  | ||||
| " FUNCTION: Opener._openFile() {{{1 | ||||
| function! s:Opener._openFile() | ||||
|     if !self._stay && !g:NERDTreeQuitOnOpen && exists("b:NERDTreeZoomed") && b:NERDTreeZoomed | ||||
|         call b:NERDTree.ui.toggleZoom() | ||||
|     endif | ||||
|  | ||||
|     if self._reuseWindow() | ||||
|         return | ||||
|  | ||||
| @ -153,6 +153,32 @@ function! s:TreeDirNode.getCascade() | ||||
|     return [self] + visChild.getCascade() | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: TreeDirNode.getCascadeRoot() {{{1 | ||||
| " Return the first directory node in the cascade in which this directory node | ||||
| " is rendered. | ||||
| function! s:TreeDirNode.getCascadeRoot() | ||||
|  | ||||
|     " Don't search above the current NERDTree root node. | ||||
|     if self.isRoot() | ||||
|         return self | ||||
|     endif | ||||
|  | ||||
|     let l:cascadeRoot = self | ||||
|     let l:parent = self.parent | ||||
|  | ||||
|     while !empty(l:parent) && !l:parent.isRoot() | ||||
|  | ||||
|         if index(l:parent.getCascade(), self) == -1 | ||||
|             break | ||||
|         endif | ||||
|  | ||||
|         let l:cascadeRoot = l:parent | ||||
|         let l:parent = l:parent.parent | ||||
|     endwhile | ||||
|  | ||||
|     return l:cascadeRoot | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: TreeDirNode.getChildCount() {{{1 | ||||
| " Returns the number of children this node has | ||||
| function! s:TreeDirNode.getChildCount() | ||||
|  | ||||
| @ -116,68 +116,40 @@ function! s:TreeFileNode.findNode(path) | ||||
|     return {} | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction) {{{1 | ||||
| " | ||||
| " Finds the next sibling for this node in the indicated direction. This sibling | ||||
| " must be a directory and may/may not have children as specified. | ||||
| " | ||||
| " Args: | ||||
| " direction: 0 if you want to find the previous sibling, 1 for the next sibling | ||||
| " | ||||
| " Return: | ||||
| " a treenode object or {} if no appropriate sibling could be found | ||||
| function! s:TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction) | ||||
|     " if we have no parent then we can have no siblings | ||||
|     if self.parent != {} | ||||
|         let nextSibling = self.findSibling(a:direction) | ||||
|  | ||||
|         while nextSibling != {} | ||||
|             if nextSibling.path.isDirectory && nextSibling.hasVisibleChildren() && nextSibling.isOpen | ||||
|                 return nextSibling | ||||
|             endif | ||||
|             let nextSibling = nextSibling.findSibling(a:direction) | ||||
|         endwhile | ||||
|     endif | ||||
|  | ||||
|     return {} | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: TreeFileNode.findSibling(direction) {{{1 | ||||
| " | ||||
| " Finds the next sibling for this node in the indicated direction | ||||
| " Find the next or previous sibling of this node. | ||||
| " | ||||
| " Args: | ||||
| " direction: 0 if you want to find the previous sibling, 1 for the next sibling | ||||
| " direction: 0 for previous, 1 for next | ||||
| " | ||||
| " Return: | ||||
| " a treenode object or {} if no sibling could be found | ||||
| " The next/previous TreeFileNode object or an empty dictionary if not found. | ||||
| function! s:TreeFileNode.findSibling(direction) | ||||
|     " if we have no parent then we can have no siblings | ||||
|     if self.parent != {} | ||||
|  | ||||
|         " get the index of this node in its parents children | ||||
|         let siblingIndx = self.parent.getChildIndex(self.path) | ||||
|  | ||||
|         if siblingIndx != -1 | ||||
|             " move a long to the next potential sibling node | ||||
|             let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1 | ||||
|  | ||||
|             " keep moving along to the next sibling till we find one that is valid | ||||
|             let numSiblings = self.parent.getChildCount() | ||||
|             while siblingIndx >= 0 && siblingIndx < numSiblings | ||||
|  | ||||
|                 " if the next node is not an ignored node (i.e. wont show up in the | ||||
|                 " view) then return it | ||||
|                 if self.parent.children[siblingIndx].path.ignore(self.getNerdtree()) ==# 0 | ||||
|                     return self.parent.children[siblingIndx] | ||||
|                 endif | ||||
|  | ||||
|                 " go to next node | ||||
|                 let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1 | ||||
|             endwhile | ||||
|         endif | ||||
|     " There can be no siblings if there is no parent. | ||||
|     if empty(self.parent) | ||||
|         return {} | ||||
|     endif | ||||
|  | ||||
|     let l:nodeIndex = self.parent.getChildIndex(self.path) | ||||
|  | ||||
|     if l:nodeIndex == -1 | ||||
|         return {} | ||||
|     endif | ||||
|  | ||||
|     " Get the next index to begin the search. | ||||
|     let l:nodeIndex += a:direction ? 1 : -1 | ||||
|  | ||||
|     while 0 <= l:nodeIndex && l:nodeIndex < self.parent.getChildCount() | ||||
|  | ||||
|         " Return the next node if it is not ignored. | ||||
|         if !self.parent.children[l:nodeIndex].path.ignore(self.getNerdtree()) | ||||
|             return self.parent.children[l:nodeIndex] | ||||
|         endif | ||||
|  | ||||
|         let l:nodeIndex += a:direction ? 1 : -1 | ||||
|     endwhile | ||||
|  | ||||
|     return {} | ||||
| endfunction | ||||
|  | ||||
|  | ||||
| @ -194,51 +194,52 @@ function! s:UI.getPath(ln) | ||||
|     return toReturn | ||||
| endfunction | ||||
|  | ||||
| " FUNCTION: s:UI.getLineNum(file_node){{{1 | ||||
| " returns the line number this node is rendered on, or -1 if it isnt rendered | ||||
| function! s:UI.getLineNum(file_node) | ||||
|     " if the node is the root then return the root line no. | ||||
|     if a:file_node.isRoot() | ||||
| " FUNCTION: s:UI.getLineNum(node) {{{1 | ||||
| " Return the line number where the given node is rendered.  Return -1 if the | ||||
| " given node is not visible. | ||||
| function! s:UI.getLineNum(node) | ||||
|  | ||||
|     if a:node.isRoot() | ||||
|         return self.getRootLineNum() | ||||
|     endif | ||||
|  | ||||
|     let totalLines = line("$") | ||||
|     let l:pathComponents = [substitute(self.nerdtree.root.path.str({'format': 'UI'}), '/\s*$', '', '')] | ||||
|     let l:currentPathComponent = 1 | ||||
|  | ||||
|     " the path components we have matched so far | ||||
|     let pathcomponents = [substitute(self.nerdtree.root.path.str({'format': 'UI'}), '/ *$', '', '')] | ||||
|     " the index of the component we are searching for | ||||
|     let curPathComponent = 1 | ||||
|     let l:fullPath = a:node.path.str({'format': 'UI'}) | ||||
|  | ||||
|     let fullpath = a:file_node.path.str({'format': 'UI'}) | ||||
|     for l:lineNumber in range(self.getRootLineNum() + 1, line('$')) | ||||
|         let l:currentLine = getline(l:lineNumber) | ||||
|         let l:indentLevel = self._indentLevelFor(l:currentLine) | ||||
|  | ||||
|     let lnum = self.getRootLineNum() | ||||
|     while lnum > 0 | ||||
|         let lnum = lnum + 1 | ||||
|         " have we reached the bottom of the tree? | ||||
|         if lnum ==# totalLines+1 | ||||
|             return -1 | ||||
|         if l:indentLevel != l:currentPathComponent | ||||
|             continue | ||||
|         endif | ||||
|  | ||||
|         let curLine = getline(lnum) | ||||
|         let l:currentLine = self._stripMarkup(l:currentLine) | ||||
|         let l:currentPath =  join(l:pathComponents, '/') . '/' . l:currentLine | ||||
|  | ||||
|         let indent = self._indentLevelFor(curLine) | ||||
|         if indent ==# curPathComponent | ||||
|             let curLine = self._stripMarkup(curLine) | ||||
|  | ||||
|             let curPath =  join(pathcomponents, '/') . '/' . curLine | ||||
|             if stridx(fullpath, curPath, 0) ==# 0 | ||||
|                 if fullpath ==# curPath || strpart(fullpath, len(curPath)-1,1) ==# '/' | ||||
|                     let curLine = substitute(curLine, '/ *$', '', '') | ||||
|                     call add(pathcomponents, curLine) | ||||
|                     let curPathComponent = curPathComponent + 1 | ||||
|  | ||||
|                     if fullpath ==# curPath | ||||
|                         return lnum | ||||
|                     endif | ||||
|                 endif | ||||
|             endif | ||||
|         " Directories: If the current path "starts with" the full path, then | ||||
|         " either the paths are equal or the line is a cascade containing the | ||||
|         " full path. | ||||
|         if l:fullPath[-1:] == '/' && stridx(l:currentPath, l:fullPath) == 0 | ||||
|             return l:lineNumber | ||||
|         endif | ||||
|     endwhile | ||||
|  | ||||
|         " Files: The paths must exactly match. | ||||
|         if l:fullPath ==# l:currentPath | ||||
|             return l:lineNumber | ||||
|         endif | ||||
|  | ||||
|         " Otherwise: If the full path starts with the current path and the | ||||
|         " current path is a directory, we add a new path component. | ||||
|         if stridx(l:fullPath, l:currentPath) == 0 && l:currentPath[-1:] == '/' | ||||
|             let l:currentLine = substitute(l:currentLine, '/\s*$', '', '') | ||||
|             call add(l:pathComponents, l:currentLine) | ||||
|             let l:currentPathComponent += 1 | ||||
|         endif | ||||
|     endfor | ||||
|  | ||||
|     return -1 | ||||
| endfunction | ||||
|  | ||||
|  | ||||
| @ -202,8 +202,28 @@ function! NERDTreeFocus() | ||||
| endfunction | ||||
|  | ||||
| function! NERDTreeCWD() | ||||
|  | ||||
|     if empty(getcwd()) | ||||
|         call nerdtree#echoWarning('current directory does not exist') | ||||
|         return | ||||
|     endif | ||||
|  | ||||
|     try | ||||
|         let l:cwdPath = g:NERDTreePath.New(getcwd()) | ||||
|     catch /^NERDTree.InvalidArgumentsError/ | ||||
|         call nerdtree#echoWarning('current directory does not exist') | ||||
|         return | ||||
|     endtry | ||||
|  | ||||
|     call NERDTreeFocus() | ||||
|     call nerdtree#ui_glue#chRootCwd() | ||||
|  | ||||
|     if b:NERDTree.root.path.equals(l:cwdPath) | ||||
|         return | ||||
|     endif | ||||
|  | ||||
|     let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree) | ||||
|     call b:NERDTree.changeRoot(l:newRoot) | ||||
|     normal! ^ | ||||
| endfunction | ||||
|  | ||||
| function! NERDTreeAddPathFilter(callback) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Amir Salihefendic
					Amir Salihefendic