EnumerateColumns
From Niki
Add this to your macro file (autoload.nm) and bind it if you wish:
define inc_column {
x1 = $selection_left
x2 = $selection_right
set_cursor_pos($selection_start)
y1 = $line
set_cursor_pos($selection_end)
y2 = $line
if ((x1 == -1) || (x2 == -1)) {
return
}
goto_line_number(y1,x1)
s1 = $cursor
goto_line_number(y1,x2)
s2 = $cursor
select(s1,s2)
sel = get_selection()
start_val = string2num(sel)
my_status = valid_number(start_val)
if (my_status == 0) {
return
}
line_step = 1
inc_val = 1
cur_val = start_val
for (i = 0; i <= (y2 - y1);) {
curr_line = y1 + i
goto_line_number(curr_line,x1)
s1 = $cursor
goto_line_number(curr_line,x2)
s2 = $cursor
select(s1,s2)
insert_string(cur_val)
cur_val = cur_val + inc_val
i = i + line_step
}
return
}
define enum_column {
x1 = $selection_left
x2 = $selection_right
set_cursor_pos($selection_start)
y1 = $line
set_cursor_pos($selection_end)
y2 = $line
if ((x1 == -1) || (x2 == -1)) {
return
}
msg = "Start with:\n"
start_val = string_dialog(msg,"OK","Cancel")
# User closed the dialog box with X.
if ($string_dialog_button == 0) {
return
}
# User pressed 'Cancel'.
if ($string_dialog_button == 2) {
return
}
# Make sure that start_val is number.
is_num = valid_number(start_val)
if (is_num == 0) {
dialog("Error: selection must be a valid decimal number","OK")
return
}
msg = "Enter line step:\n"
line_step = string_dialog(msg,"OK","Cancel")
# User closed the dialog box with X.
if ($string_dialog_button == 0) {
return
}
# User pressed 'Cancel'.
if ($string_dialog_button == 2) {
return
}
# Make sure that line_step is number.
is_num = valid_number(line_step)
if (is_num == 0) {
dialog("Error: selection must be a valid decimal number","OK")
return
}
msg = "Enter incremet value:\n"
inc_val = string_dialog(msg,"OK","Cancel")
# User closed the dialog box with X.
if ($string_dialog_button == 0) {
return
}
# User pressed 'Cancel'.
if ($string_dialog_button == 2) {
return
}
# Make sure that inc_val is number.
is_num = valid_number(inc_val)
if (is_num == 0) {
dialog("Error: selection must be a valid decimal number","OK")
return
}
cur_val = start_val
for (i = 0; i <= (y2 - y1);) {
curr_line = y1 + i
goto_line_number(curr_line,x1)
s1 = $cursor
goto_line_number(curr_line,x2)
s2 = $cursor
select(s1,s2)
insert_string(cur_val)
cur_val = cur_val + inc_val
i = i + line_step
}
return
}
