Commit 4a991ec7 authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Renumbering works.

parent 7a4981d8
......@@ -28,3 +28,4 @@ function! Renumber()
endfunction
" call LoadCobolPython()
command! -nargs=0 Renumber call Renumber()
......@@ -11,8 +11,37 @@ COBOL utilities.
"""
import vim
import math
print(vim.current.buffer.name)
b = vim.current.buffer
for i in range(len(b)):
b[i] = 'moo ' + b[i]
if vim.current.buffer.options['filetype'] == b'cobol':
gap = {}
last_line_no = 0
lines = vim.current.buffer
for i in range(len(lines)):
if len(lines[i]) == 0 or lines[i][:6] == ' ':
if not gap:
gap['i'] = i
gap['last_line_no'] = last_line_no
else:
try:
last_line_no = int(lines[i][:6])
except ValueError:
raise ValueError('Malformed line - has non-numbers in columns 1-6')
if gap:
delta = math.floor((last_line_no - gap['last_line_no']) /
(i - gap['i'] + 1))
if delta > 1:
new_line_no = gap['last_line_no'] + delta
for j in range(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)):
lines[j] = ('%06d' % new_line_no) + lines[j][6:]
new_line_no += delta
else:
print('Not a COBOL file. This is a %s file' %
vim.current.buffer.options['filetype'].decode('UTF-8'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment