nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 2d639b70e73ecf3f62884a578fe5e5937e6d8a92
parent 6318406f6606481b5e3a42a5754096063d996587
Author: Phil Runninger <PhilRunninger@users.noreply.github.com>
Date:   Tue,  1 Oct 2019 09:17:32 -0400

Catch errors when trying to read CHANGELOG.md. (#1045)

* Catch errors when trying to read CHANGELOG.md.

The ArchLinux package
(https://www.archlinux.org/packages/community/any/vim-nerdtree/) puts
this file in the wrong location.

* Update version number in change log.

Diffstat:
MCHANGELOG.md | 1+
Mautoload/nerdtree.vim | 23+++++++++++++----------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -1,6 +1,7 @@
 # Change Log
 
 #### 6.1...
+- **.1**: Catch errors when trying to read CHANGELOG.md. (PhilRunninger) [#1045](https://github.com/scrooloose/nerdtree/pull/1045)
 - **.0**: If file path doesn't exist, :NERDTreeFind its parent directory instead. (PhilRunninger) [#1043](https://github.com/scrooloose/nerdtree/pull/1043)
 #### 6.0...
 - **.1**: Reintroduce necessary variable mistakenly removed. (PhilRunninger) [#1040](https://github.com/scrooloose/nerdtree/pull/1040)
diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim
@@ -10,17 +10,20 @@ let s:rootNERDTreePath = resolve(expand("<sfile>:p:h:h"))
 "  change log is shown for the current version; otherwise, only the version
 "  number is shown.
 function! nerdtree#version(...)
-    let l:changelog = readfile(join([s:rootNERDTreePath, "CHANGELOG.md"], nerdtree#slash()))
     let l:text = 'Unknown'
-    let l:line = 0
-    while l:line <= len(l:changelog)
-        if l:changelog[l:line] =~ '\d\+\.\d\+'
-            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
+    try
+        let l:changelog = readfile(join([s:rootNERDTreePath, "CHANGELOG.md"], nerdtree#slash()))
+        let l:line = 0
+        while l:line <= len(l:changelog)
+            if l:changelog[l:line] =~ '\d\+\.\d\+'
+                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
     return l:text
 endfunction