From 2d639b70e73ecf3f62884a578fe5e5937e6d8a92 Mon Sep 17 00:00:00 2001 From: Phil Runninger Date: Tue, 1 Oct 2019 09:17:32 -0400 Subject: [PATCH] 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. --- CHANGELOG.md | 1 + autoload/nerdtree.vim | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb99c6..8795c6b 100644 --- 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 index 61adb9c..76c076e 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -10,17 +10,20 @@ let s:rootNERDTreePath = resolve(expand(":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