Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kevin Lyda
vim-cobol
Commits
4a991ec7
Commit
4a991ec7
authored
Sep 19, 2017
by
Kevin Lyda
💬
Browse files
Renumbering works.
parent
7a4981d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
plugin/cobol.vim
View file @
4a991ec7
...
...
@@ -28,3 +28,4 @@ function! Renumber()
endfunction
" call LoadCobolPython()
command
!
-
nargs
=
0
Renumber
call
Renumber
()
plugin/renumber.py
View file @
4a991ec7
...
...
@@ -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'
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment