Skip to content
Snippets Groups Projects
Commit d519c981 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Work in python2 environments.

parent 6d2d6a0b
No related merge requests found
......@@ -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:
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment