From f89d0f643fb8b77ea603edfe1f44dc5ad3535a29 Mon Sep 17 00:00:00 2001 From: Maksim Ryzhikov Date: Fri, 21 Feb 2014 01:48:44 +0400 Subject: [PATCH] Fix error with detection position of cursor (fix #47) --- plugin/beautifier.vim | 12 ++++++++---- .../issue_47/Error with detection position of cursor | 5 +++++ test/vim/issue_47/file | 2 ++ test/vim/issue_47/vimrc | 12 ++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100755 test/vim/issue_47/Error with detection position of cursor create mode 100644 test/vim/issue_47/file create mode 100644 test/vim/issue_47/vimrc diff --git a/plugin/beautifier.vim b/plugin/beautifier.vim index 7e05e1c..a6678f7 100644 --- a/plugin/beautifier.vim +++ b/plugin/beautifier.vim @@ -254,7 +254,6 @@ endfunction "Converts number of non blank characters to cursor position (line and column) function! s:getCursorPosition(numberOfNonBlankCharactersFromTheStartOfFile) - "echo a:numberOfNonBlankCharactersFromTheStartOfFile let lineNumber = 1 let nonBlankCount = 0 while lineNumber <= line('$') @@ -267,13 +266,15 @@ function! s:getCursorPosition(numberOfNonBlankCharactersFromTheStartOfFile) endif let charIndex = charIndex + 1 if nonBlankCount == a:numberOfNonBlankCharactersFromTheStartOfFile - "echo 'found position!' + "Found position! return {'line': lineNumber,'column': charIndex} end endwhile let lineNumber = lineNumber + 1 endwhile - "echo "Oops, nothing found!" + + "Oops, nothing found! + return {} endfunction @@ -281,7 +282,10 @@ endfunction "Restoring current position by number of non blank characters function! s:setNumberOfNonSpaceCharactersBeforeCursor(mark,numberOfNonBlankCharactersFromTheStartOfFile) let location = s:getCursorPosition(a:numberOfNonBlankCharactersFromTheStartOfFile) - call setpos(a:mark, [0, location.line, location.column, 0]) + + if !empty(location) + call setpos(a:mark, [0, location.line, location.column, 0]) + endif endfunction diff --git a/test/vim/issue_47/Error with detection position of cursor b/test/vim/issue_47/Error with detection position of cursor new file mode 100755 index 0000000..38168ad --- /dev/null +++ b/test/vim/issue_47/Error with detection position of cursor @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +vim -u vimrc -c "execute 'try | call setpos(\".\", [0, 0, 0]) | silent call JsBeautify() | catch | cq! | endtry' | q!" file diff --git a/test/vim/issue_47/file b/test/vim/issue_47/file new file mode 100644 index 0000000..479207d --- /dev/null +++ b/test/vim/issue_47/file @@ -0,0 +1,2 @@ + +{} diff --git a/test/vim/issue_47/vimrc b/test/vim/issue_47/vimrc new file mode 100644 index 0000000..9cda742 --- /dev/null +++ b/test/vim/issue_47/vimrc @@ -0,0 +1,12 @@ +" vim -u vimrc +set nocompatible + +set nowrap + +let root = '~/.vim/bundle' + +filetype off +syntax on + +runtime macros/matchit.vim +exec 'set rtp+=../../../'