Delall: Delete Visible Lines from a Selective Display

Thursday, September 18, 2008 0 comments

Here are 3 more Slickedit macros I've been using regularly for several years. Actually, the first one is more of a test macro than it is useful. The other two are stalwarts.

The 3 macros are:

  1. count_hidden_lines(): show count of hidden lines
  2. dat(): delete all visible lines in the selective display, without deleting any hidden lines
  3. delall(): delete all lines containing the specified search string
Have fun. Let me know if you find any significant problems or have comments.

dh
// count_hidden_lines

_command count_hidden_lines()
{
NoflinesShown0=((p_Noflines)-p_Nofhidden);
message( NoflinesShown0' visible (selected) lines, p_Noflines= 'p_Noflines'; p_Nofhidden = 'p_Nofhidden);
}


// dat(): delete all visible lines in selective display
// Example: to remove all lines containing "Bookmark this site",
// execute 'all /bookmark this site/' and then execute 'dat.'
// The 'dat' command will delete all of the visible lines and leave the
// rest untouched.

_command dat() name_info(','VSARG2_REQUIRES_EDITORCTL)
{
// get line counts for verification and be sure a selective display is active
NoflinesShown0=((p_Noflines)-p_Nofhidden);
if (NoflinesShown0==p_Noflines) {
_message_box("Error: be sure selective display is active before running ''dat''");
return(0);
}
old_line_cou=p_Noflines;
// make sure nothing is marked--we don't want to delete invisible lines
if (select_active()) {
_message_box('Error: Deselect the marked block');
return(0);
} else {
bottom();
while (p_line>=1) {
hid=_lineflags() & (HIDDEN_LF);
if (hid!=HIDDEN_LF) {
// probably also need to exclude or prompt for

// deletion of pbm "minus" lines. A pbm minus
// line is a hidden line that has been expanded
status=_delete_line();
} else {
cursor_up();
}
}
}
NoflinesShown1=((p_Noflines)-p_Nofhidden);
message(old_line_cou'-'old_line_cou-p_Noflines' lines deleted; 'p_Noflines' remain');
if (p_Noflines!=(old_line_cou-NoflinesShown0)) {
_message_box('Error: Number of lines deleted does not match original number of visible lines');
}
show_all();
}


// delall(): Delete all lines containing the specified search string.
//
Locates lines containing matches and then runs 'dat' to delete
// all matching lines in one step.

// Example: "delall /^Subtotal$/r"
// Delall is a timesaver ... and easily reversible, thanks to Undo.
// You can use any arguments
to 'delall' that you can use with the
// ordinary 'search', 'find', 'all', 'more', or 'less'
commands,
// including those luscious regular expressions we love so much.


_command d,delall(...) name_info(','VSARG2_REQUIRES_EDITORCTLVSARG2_READ_ONLY)
{
_str searchstr=arg(1);
_str delim;
_str sstring;
_str opts;
// strip delimiters
parse searchstr with delim +1 sstring(delim)opts
save_pos(p);
all(sstring,'i':+opts);
dat();
show_all();
restore_pos(p);
}

GlossyBlue Blogger by Black Quanta. Theme & Icons by N.Design Studio
Entries RSS Comments RSS