diff --git a/plugin/cobol.py b/plugin/cobol.py index 838446a527faa860534e2e1a03f86fd90a45e9ae..d1b189e0ff99780c1fc0055606304d3fba4ec567 100755 --- a/plugin/cobol.py +++ b/plugin/cobol.py @@ -5,6 +5,7 @@ # Copyright © 2017 Kevin Lyda <kevin@phrye.com> # # Distributed under terms of the GPL license. +from __future__ import print_function """ COBOL utilities. @@ -13,12 +14,17 @@ COBOL utilities. import vim import math +try: + xrange +except NameError: + xrange = range + def cobol_Renumber(): if vim.current.buffer.options['filetype'] == b'cobol': gap = {} last_line_no = 0 lines = vim.current.buffer - for i in range(len(lines)): + for i in xrange(len(lines)): if len(lines[i]) == 0 or lines[i][:6] == ' ': if not gap: gap['i'] = i @@ -34,14 +40,14 @@ def cobol_Renumber(): (i - gap['i'] + 1)) if delta > 1: new_line_no = gap['last_line_no'] + delta - for j in range(gap['i'], i): + for j in xrange(gap['i'], i): lines[j] = ('%06d' % new_line_no) + lines[j][6:] new_line_no += delta gap = {} if gap: delta = 100 new_line_no = gap['last_line_no'] + delta - for j in range(gap['i'], len(lines)): + for j in xrange(gap['i'], len(lines)): lines[j] = ('%06d' % new_line_no) + lines[j][6:] new_line_no += delta else: @@ -51,7 +57,7 @@ def cobol_Renumber(): def cobol_Unnumber(): if vim.current.buffer.options['filetype'] == b'cobol': lines = vim.current.buffer - for i in range(len(lines)): + for i in xrange(len(lines)): if lines[i][:6].isdigit(): lines[i] = ' ' + lines[i][6:] else: diff --git a/plugin/cobol.vim b/plugin/cobol.vim index 82f1f37192ecff34fce088e43b68f5899e44e09e..8771c487725b94d1627b9ff4c4acc2f38933980d 100644 --- a/plugin/cobol.vim +++ b/plugin/cobol.vim @@ -9,8 +9,13 @@ if exists('g:loaded_cobol') || &cp endif let g:loaded_cobol = 1 -if !has('python3') - echo "Missing python." +if has('python3') + let s:pyfile_cmd = 'py3file' + let s:py_cmd = 'py3' +elseif has('python') + let s:pyfile_cmd = 'pyfile' + let s:py_cmd = 'py' +else finish endif @@ -18,17 +23,17 @@ let s:path = fnamemodify(resolve(expand('<sfile>:p')), ':h') function! LoadCobolPython() if !exists('g:cobol_py_loaded') - exec 'py3file ' . s:path . '/cobol.py' + exec s:pyfile_cmd s:path . '/cobol.py' let g:cobol_py_loaded = 1 endif endfunction function! Renumber() - py3 cobol_Renumber() + exec s:py_cmd 'cobol_Renumber()' endfunction function! Unnumber() - py3 cobol_Unnumber() + exec s:py_cmd 'cobol_Unnumber()' endfunction call LoadCobolPython()