From 39ceebbb1ec98f9093193b9e395b9b03cb861e6b Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 10 Jul 2012 20:50:03 -0700 Subject: [PATCH] Where possible, using native objects, not vim.eval --- python/ycm.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/python/ycm.py b/python/ycm.py index 2c9ed531..a4c304ad 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -116,7 +116,7 @@ class ClangComplete( object ): files.append( unsaved_file ) - line = int( vim.eval( "line('.')" ) ) + line, _ = vim.current.window.cursor column = int( vim.eval( "s:completion_start_column" ) ) + 1 current_buffer = vim.current.buffer results = self.completer.CandidatesForLocationInFile( current_buffer.name, @@ -136,17 +136,21 @@ def GetUnsavedBuffers(): def CurrentColumn(): """Do NOT access the CurrentColumn in vim.current.line. It doesn't exist yet. - Only the chars befor the current column exist in vim.current.line.""" + Only the chars before the current column exist in vim.current.line.""" - # vim's columns start at 1 while vim.current.line columns start at 0 - return int( vim.eval( "col('.')" ) ) - 1 + # vim's columns are 1-based while vim.current.line columns are 0-based + # ... but vim.current.window.cursor (which returns a (line, column) tuple) + # columns are 0-based, while the line from that same tuple is 1-based. + # Pigs have wings and I'm a loopy purple duck. Everything makes sense now. + return vim.current.window.cursor[ 1 ] def CurrentLineAndColumn(): - result = vim.eval( "getpos('.')") - line_num = int( result[ 1 ] ) - 1 - column_num = int( result[ 2 ] ) - 1 - return line_num, column_num + # See the comment in CurrentColumn about the calculation for the line and + # column number + line, column = vim.current.window.cursor + line -= 1 + return line, column def ShouldUseClang( start_column ):