Format the commentary in "tree_file_node.vim"

This commit is contained in:
Jason Franklin 2018-01-06 08:54:28 -05:00
parent e6a116a9cd
commit d745e11b42

View File

@ -1,22 +1,25 @@
"CLASS: TreeFileNode " ============================================================================
"This class is the parent of the TreeDirNode class and is the " CLASS: TreeFileNode
"'Component' part of the composite design pattern between the treenode "
"classes. " This class is the parent of the "TreeDirNode" class and is the "Component"
"============================================================ " part of the composite design pattern between the NERDTree node classes.
" ============================================================================
let s:TreeFileNode = {} let s:TreeFileNode = {}
let g:NERDTreeFileNode = s:TreeFileNode let g:NERDTreeFileNode = s:TreeFileNode
"FUNCTION: TreeFileNode.activate(...) {{{1 " FUNCTION: TreeFileNode.activate(...) {{{1
function! s:TreeFileNode.activate(...) function! s:TreeFileNode.activate(...)
call self.open(a:0 ? a:1 : {}) call self.open(a:0 ? a:1 : {})
endfunction endfunction
"FUNCTION: TreeFileNode.bookmark(name) {{{1 " FUNCTION: TreeFileNode.bookmark(name) {{{1
"bookmark this node with a:name " bookmark this node with a:name
function! s:TreeFileNode.bookmark(name) function! s:TreeFileNode.bookmark(name)
"if a bookmark exists with the same name and the node is cached then save " if a bookmark exists with the same name and the node is cached then save
"it so we can update its display string " it so we can update its display string
let oldMarkedNode = {} let oldMarkedNode = {}
try try
let oldMarkedNode = g:NERDTreeBookmark.GetNodeForName(a:name, 1, self.getNerdtree()) let oldMarkedNode = g:NERDTreeBookmark.GetNodeForName(a:name, 1, self.getNerdtree())
@ -33,8 +36,8 @@ function! s:TreeFileNode.bookmark(name)
endif endif
endfunction endfunction
"FUNCTION: TreeFileNode.cacheParent() {{{1 " FUNCTION: TreeFileNode.cacheParent() {{{1
"initializes self.parent if it isnt already " initializes self.parent if it isnt already
function! s:TreeFileNode.cacheParent() function! s:TreeFileNode.cacheParent()
if empty(self.parent) if empty(self.parent)
let parentPath = self.path.getParent() let parentPath = self.path.getParent()
@ -45,7 +48,7 @@ function! s:TreeFileNode.cacheParent()
endif endif
endfunction endfunction
"FUNCTION: TreeFileNode.clearBookmarks() {{{1 " FUNCTION: TreeFileNode.clearBookmarks() {{{1
function! s:TreeFileNode.clearBookmarks() function! s:TreeFileNode.clearBookmarks()
for i in g:NERDTreeBookmark.Bookmarks() for i in g:NERDTreeBookmark.Bookmarks()
if i.path.equals(self.path) if i.path.equals(self.path)
@ -55,7 +58,7 @@ function! s:TreeFileNode.clearBookmarks()
call self.path.cacheDisplayString() call self.path.cacheDisplayString()
endfunction endfunction
"FUNCTION: TreeFileNode.copy(dest) {{{1 " FUNCTION: TreeFileNode.copy(dest) {{{1
function! s:TreeFileNode.copy(dest) function! s:TreeFileNode.copy(dest)
call self.path.copy(a:dest) call self.path.copy(a:dest)
let newPath = g:NERDTreePath.New(a:dest) let newPath = g:NERDTreePath.New(a:dest)
@ -68,44 +71,44 @@ function! s:TreeFileNode.copy(dest)
endif endif
endfunction endfunction
"FUNCTION: TreeFileNode.delete {{{1 " FUNCTION: TreeFileNode.delete {{{1
"Removes this node from the tree and calls the Delete method for its path obj " Removes this node from the tree and calls the Delete method for its path obj
function! s:TreeFileNode.delete() function! s:TreeFileNode.delete()
call self.path.delete() call self.path.delete()
call self.parent.removeChild(self) call self.parent.removeChild(self)
endfunction endfunction
"FUNCTION: TreeFileNode.displayString() {{{1 " FUNCTION: TreeFileNode.displayString() {{{1
" "
"Returns a string that specifies how the node should be represented as a " Returns a string that specifies how the node should be represented as a
"string " string
" "
"Return: " Return:
"a string that can be used in the view to represent this node " a string that can be used in the view to represent this node
function! s:TreeFileNode.displayString() function! s:TreeFileNode.displayString()
return self.path.flagSet.renderToString() . self.path.displayString() return self.path.flagSet.renderToString() . self.path.displayString()
endfunction endfunction
"FUNCTION: TreeFileNode.equals(treenode) {{{1 " FUNCTION: TreeFileNode.equals(treenode) {{{1
" "
"Compares this treenode to the input treenode and returns 1 if they are the " Compares this treenode to the input treenode and returns 1 if they are the
"same node. " same node.
" "
"Use this method instead of == because sometimes when the treenodes contain " Use this method instead of == because sometimes when the treenodes contain
"many children, vim seg faults when doing == " many children, vim seg faults when doing ==
" "
"Args: " Args:
"treenode: the other treenode to compare to " treenode: the other treenode to compare to
function! s:TreeFileNode.equals(treenode) function! s:TreeFileNode.equals(treenode)
return self.path.str() ==# a:treenode.path.str() return self.path.str() ==# a:treenode.path.str()
endfunction endfunction
"FUNCTION: TreeFileNode.findNode(path) {{{1 " FUNCTION: TreeFileNode.findNode(path) {{{1
"Returns self if this node.path.Equals the given path. " Returns self if this node.path.Equals the given path.
"Returns {} if not equal. " Returns {} if not equal.
" "
"Args: " Args:
"path: the path object to compare against " path: the path object to compare against
function! s:TreeFileNode.findNode(path) function! s:TreeFileNode.findNode(path)
if a:path.equals(self.path) if a:path.equals(self.path)
return self return self
@ -113,18 +116,18 @@ function! s:TreeFileNode.findNode(path)
return {} return {}
endfunction endfunction
"FUNCTION: TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction) {{{1 " FUNCTION: TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction) {{{1
" "
"Finds the next sibling for this node in the indicated direction. This sibling " 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. " must be a directory and may/may not have children as specified.
" "
"Args: " Args:
"direction: 0 if you want to find the previous sibling, 1 for the next sibling " direction: 0 if you want to find the previous sibling, 1 for the next sibling
" "
"Return: " Return:
"a treenode object or {} if no appropriate sibling could be found " a treenode object or {} if no appropriate sibling could be found
function! s:TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction) function! s:TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction)
"if we have no parent then we can have no siblings " if we have no parent then we can have no siblings
if self.parent != {} if self.parent != {}
let nextSibling = self.findSibling(a:direction) let nextSibling = self.findSibling(a:direction)
@ -139,37 +142,37 @@ function! s:TreeFileNode.findOpenDirSiblingWithVisibleChildren(direction)
return {} return {}
endfunction endfunction
"FUNCTION: TreeFileNode.findSibling(direction) {{{1 " FUNCTION: TreeFileNode.findSibling(direction) {{{1
" "
"Finds the next sibling for this node in the indicated direction " Finds the next sibling for this node in the indicated direction
" "
"Args: " Args:
"direction: 0 if you want to find the previous sibling, 1 for the next sibling " direction: 0 if you want to find the previous sibling, 1 for the next sibling
" "
"Return: " Return:
"a treenode object or {} if no sibling could be found " a treenode object or {} if no sibling could be found
function! s:TreeFileNode.findSibling(direction) function! s:TreeFileNode.findSibling(direction)
"if we have no parent then we can have no siblings " if we have no parent then we can have no siblings
if self.parent != {} if self.parent != {}
"get the index of this node in its parents children " get the index of this node in its parents children
let siblingIndx = self.parent.getChildIndex(self.path) let siblingIndx = self.parent.getChildIndex(self.path)
if siblingIndx != -1 if siblingIndx != -1
"move a long to the next potential sibling node " move a long to the next potential sibling node
let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1 let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1
"keep moving along to the next sibling till we find one that is valid " keep moving along to the next sibling till we find one that is valid
let numSiblings = self.parent.getChildCount() let numSiblings = self.parent.getChildCount()
while siblingIndx >= 0 && siblingIndx < numSiblings while siblingIndx >= 0 && siblingIndx < numSiblings
"if the next node is not an ignored node (i.e. wont show up in the " if the next node is not an ignored node (i.e. wont show up in the
"view) then return it " view) then return it
if self.parent.children[siblingIndx].path.ignore(self.getNerdtree()) ==# 0 if self.parent.children[siblingIndx].path.ignore(self.getNerdtree()) ==# 0
return self.parent.children[siblingIndx] return self.parent.children[siblingIndx]
endif endif
"go to next node " go to next node
let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1 let siblingIndx = a:direction ==# 1 ? siblingIndx+1 : siblingIndx-1
endwhile endwhile
endif endif
@ -178,13 +181,13 @@ function! s:TreeFileNode.findSibling(direction)
return {} return {}
endfunction endfunction
"FUNCTION: TreeFileNode.getNerdtree(){{{1 " FUNCTION: TreeFileNode.getNerdtree(){{{1
function! s:TreeFileNode.getNerdtree() function! s:TreeFileNode.getNerdtree()
return self._nerdtree return self._nerdtree
endfunction endfunction
"FUNCTION: TreeFileNode.GetRootForTab(){{{1 " FUNCTION: TreeFileNode.GetRootForTab(){{{1
"get the root node for this tab " get the root node for this tab
function! s:TreeFileNode.GetRootForTab() function! s:TreeFileNode.GetRootForTab()
if g:NERDTree.ExistsForTab() if g:NERDTree.ExistsForTab()
return getbufvar(t:NERDTreeBufName, 'NERDTree').root return getbufvar(t:NERDTreeBufName, 'NERDTree').root
@ -192,8 +195,8 @@ function! s:TreeFileNode.GetRootForTab()
return {} return {}
endfunction endfunction
"FUNCTION: TreeFileNode.GetSelected() {{{1 " FUNCTION: TreeFileNode.GetSelected() {{{1
"gets the treenode that the cursor is currently over " gets the treenode that the cursor is currently over
function! s:TreeFileNode.GetSelected() function! s:TreeFileNode.GetSelected()
try try
let path = b:NERDTree.ui.getPath(line(".")) let path = b:NERDTree.ui.getPath(line("."))
@ -206,14 +209,14 @@ function! s:TreeFileNode.GetSelected()
endtry endtry
endfunction endfunction
"FUNCTION: TreeFileNode.isVisible() {{{1 " FUNCTION: TreeFileNode.isVisible() {{{1
"returns 1 if this node should be visible according to the tree filters and " returns 1 if this node should be visible according to the tree filters and
"hidden file filters (and their on/off status) " hidden file filters (and their on/off status)
function! s:TreeFileNode.isVisible() function! s:TreeFileNode.isVisible()
return !self.path.ignore(self.getNerdtree()) return !self.path.ignore(self.getNerdtree())
endfunction endfunction
"FUNCTION: TreeFileNode.isRoot() {{{1 " FUNCTION: TreeFileNode.isRoot() {{{1
function! s:TreeFileNode.isRoot() function! s:TreeFileNode.isRoot()
if !g:NERDTree.ExistsForBuf() if !g:NERDTree.ExistsForBuf()
throw "NERDTree.NoTreeError: No tree exists for the current buffer" throw "NERDTree.NoTreeError: No tree exists for the current buffer"
@ -222,12 +225,12 @@ function! s:TreeFileNode.isRoot()
return self.equals(self.getNerdtree().root) return self.equals(self.getNerdtree().root)
endfunction endfunction
"FUNCTION: TreeFileNode.New(path, nerdtree) {{{1 " FUNCTION: TreeFileNode.New(path, nerdtree) {{{1
"Returns a new TreeNode object with the given path and parent " Returns a new TreeNode object with the given path and parent
" "
"Args: " Args:
"path: file/dir that the node represents " path: file/dir that the node represents
"nerdtree: the tree the node belongs to " nerdtree: the tree the node belongs to
function! s:TreeFileNode.New(path, nerdtree) function! s:TreeFileNode.New(path, nerdtree)
if a:path.isDirectory if a:path.isDirectory
return g:NERDTreeDirNode.New(a:path, a:nerdtree) return g:NERDTreeDirNode.New(a:path, a:nerdtree)
@ -240,40 +243,40 @@ function! s:TreeFileNode.New(path, nerdtree)
endif endif
endfunction endfunction
"FUNCTION: TreeFileNode.open() {{{1 " FUNCTION: TreeFileNode.open() {{{1
function! s:TreeFileNode.open(...) function! s:TreeFileNode.open(...)
let opts = a:0 ? a:1 : {} let opts = a:0 ? a:1 : {}
let opener = g:NERDTreeOpener.New(self.path, opts) let opener = g:NERDTreeOpener.New(self.path, opts)
call opener.open(self) call opener.open(self)
endfunction endfunction
"FUNCTION: TreeFileNode.openSplit() {{{1 " FUNCTION: TreeFileNode.openSplit() {{{1
"Open this node in a new window " Open this node in a new window
function! s:TreeFileNode.openSplit() function! s:TreeFileNode.openSplit()
call nerdtree#deprecated('TreeFileNode.openSplit', 'is deprecated, use .open() instead.') call nerdtree#deprecated('TreeFileNode.openSplit', 'is deprecated, use .open() instead.')
call self.open({'where': 'h'}) call self.open({'where': 'h'})
endfunction endfunction
"FUNCTION: TreeFileNode.openVSplit() {{{1 " FUNCTION: TreeFileNode.openVSplit() {{{1
"Open this node in a new vertical window " Open this node in a new vertical window
function! s:TreeFileNode.openVSplit() function! s:TreeFileNode.openVSplit()
call nerdtree#deprecated('TreeFileNode.openVSplit', 'is deprecated, use .open() instead.') call nerdtree#deprecated('TreeFileNode.openVSplit', 'is deprecated, use .open() instead.')
call self.open({'where': 'v'}) call self.open({'where': 'v'})
endfunction endfunction
"FUNCTION: TreeFileNode.openInNewTab(options) {{{1 " FUNCTION: TreeFileNode.openInNewTab(options) {{{1
function! s:TreeFileNode.openInNewTab(options) function! s:TreeFileNode.openInNewTab(options)
echomsg 'TreeFileNode.openInNewTab is deprecated' echomsg 'TreeFileNode.openInNewTab is deprecated'
call self.open(extend({'where': 't'}, a:options)) call self.open(extend({'where': 't'}, a:options))
endfunction endfunction
"FUNCTION: TreeFileNode.putCursorHere(isJump, recurseUpward){{{1 " FUNCTION: TreeFileNode.putCursorHere(isJump, recurseUpward){{{1
"Places the cursor on the line number this node is rendered on " Places the cursor on the line number this node is rendered on
" "
"Args: " Args:
"isJump: 1 if this cursor movement should be counted as a jump by vim " isJump: 1 if this cursor movement should be counted as a jump by vim
"recurseUpward: try to put the cursor on the parent if the this node isnt " recurseUpward: try to put the cursor on the parent if the this node isnt
"visible " visible
function! s:TreeFileNode.putCursorHere(isJump, recurseUpward) function! s:TreeFileNode.putCursorHere(isJump, recurseUpward)
let ln = self.getNerdtree().ui.getLineNum(self) let ln = self.getNerdtree().ui.getLineNum(self)
if ln != -1 if ln != -1
@ -294,18 +297,18 @@ function! s:TreeFileNode.putCursorHere(isJump, recurseUpward)
endif endif
endfunction endfunction
"FUNCTION: TreeFileNode.refresh() {{{1 " FUNCTION: TreeFileNode.refresh() {{{1
function! s:TreeFileNode.refresh() function! s:TreeFileNode.refresh()
call self.path.refresh(self.getNerdtree()) call self.path.refresh(self.getNerdtree())
endfunction endfunction
"FUNCTION: TreeFileNode.refreshFlags() {{{1 " FUNCTION: TreeFileNode.refreshFlags() {{{1
function! s:TreeFileNode.refreshFlags() function! s:TreeFileNode.refreshFlags()
call self.path.refreshFlags(self.getNerdtree()) call self.path.refreshFlags(self.getNerdtree())
endfunction endfunction
"FUNCTION: TreeFileNode.rename() {{{1 " FUNCTION: TreeFileNode.rename() {{{1
"Calls the rename method for this nodes path obj " Calls the rename method for this nodes path obj
function! s:TreeFileNode.rename(newName) function! s:TreeFileNode.rename(newName)
let newName = substitute(a:newName, '\(\\\|\/\)$', '', '') let newName = substitute(a:newName, '\(\\\|\/\)$', '', '')
call self.path.rename(newName) call self.path.rename(newName)
@ -320,17 +323,17 @@ function! s:TreeFileNode.rename(newName)
endif endif
endfunction endfunction
"FUNCTION: TreeFileNode.renderToString {{{1 " FUNCTION: TreeFileNode.renderToString {{{1
"returns a string representation for this tree to be rendered in the view " returns a string representation for this tree to be rendered in the view
function! s:TreeFileNode.renderToString() function! s:TreeFileNode.renderToString()
return self._renderToString(0, 0) return self._renderToString(0, 0)
endfunction endfunction
"Args: " Args:
"depth: the current depth in the tree for this call " depth: the current depth in the tree for this call
"drawText: 1 if we should actually draw the line for this node (if 0 then the " drawText: 1 if we should actually draw the line for this node (if 0 then the
"child nodes are rendered only) " child nodes are rendered only)
"for each depth in the tree " for each depth in the tree
function! s:TreeFileNode._renderToString(depth, drawText) function! s:TreeFileNode._renderToString(depth, drawText)
let output = "" let output = ""
if a:drawText ==# 1 if a:drawText ==# 1
@ -346,7 +349,7 @@ function! s:TreeFileNode._renderToString(depth, drawText)
let output = output . line . "\n" let output = output . line . "\n"
endif endif
"if the node is an open dir, draw its children " if the node is an open dir, draw its children
if self.path.isDirectory ==# 1 && self.isOpen ==# 1 if self.path.isDirectory ==# 1 && self.isOpen ==# 1
let childNodesToDraw = self.getVisibleChildren() let childNodesToDraw = self.getVisibleChildren()