SlickEdit Community
SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: stevecoh1 on July 11, 2006, 05:55:46 PM
-
Several years ago, one of the support guys provided me with a SlickEdit macro that copied the filtered contents of a window that was displayed with selective display. I don't remember if it was copied to clipboard or to a new buffer or whatever. This was a very useful feature. Support now indicates it's on the request list. I believe the macro was called something like "copy_shown()".
Does anyone have this or a similar macro?
-
I was intrigued by this (and the idea of writing my first (relatively) non-trivial macro), so I just whipped this up:
////////////////////////////////////////////////////////////////////////////////////////////
#include "slick.sh"
/*
Copy the lines currently shown in the current buffer to a new buffer. This
should ignore lines that are hidden because of selective display settings.
*/
_command void copy_shown()
{
lines_copied = 0;
// Create a new buffer to hold the displayed lines.
new_file();
// Switch back to the previous buffer to find the lines to copy.
_prev_buffer('R');
push_bookmark();
// Place cursor on line 0 before first line of the buffer.
top(); up();
// Iterate across the lines in the buffer, copying those that are not hidden.
for (j=1; j<=p_Noflines; j++) {
// Go down and get the next line.
if (down()) break;
get_line(line);
// If this line is not hidden, copy it to the new buffer.
if (!(_lineflags() & HIDDEN_LF)) {
lines_copied++;
// Switch to the new buffer.
_next_buffer('R');
// If we are about to insert the first line into the new buffer,
// delete any lines we got in that buffer for free.
if (lines_copied == 1) {
delete_all();
}
// Copy the line.
insert_line(line);
// Switch back to the original buffer.
_prev_buffer('R');
}
}
pop_bookmark();
next_buffer('R');
if (lines_copied == 0) {
close_buffer();
message('No displayed lines found!');
}
else {
s = lines_copied==1 ? '' : 's';
message(lines_copied ' line's ' copied to this buffer.');
}
}
////////////////////////////////////////////////////////////////////////////////////////////
Please be gentle with your comments about this macro. 8-)
Cheers,
Seth
-
Pretty cool, but somehow a second copy of the original buffer you are copying from is getting opened...
Thanks for posting it.
-
| Wanderer, my macro always copies non-hidden lines into a new buffer; perhaps you invoked it without any lines hidden?
The macro adds a new buffer to the ring and copies every non-hidden line from the current buffer to the new one; if no lines are hidden, every line from the current buffer will be copied. Try hiding some lines via a selective display action (like "all" or "notall" or View->Function Headings or some such) and run the macro again to see what gets copied.
I guess I should say that I only have v11, so I haven't tested (and can't test) it with earlier versions of VS.
-
| Wanderer, my macro always copies non-hidden lines into a new buffer; perhaps you invoked it without any lines hidden?
I guess I should say that I only have v11, so I haven't tested (and can't test) it with earlier versions of VS.
SlickEdit 11.0.1 on WinXP. I have one buffer/one MDI window -- gizmo.cpp. View->Selective Display->Function Definitions. On the SlickEdit command line: 'copy-shown'.
Now I have three windows -- two with gizmo.cpp, and one with 'Untitled<26>'.
This is just a minor annoyance (I don't think there is anything harmful in this behavior). Great macro.
Thanks.
-
Weird/interesting. I did the same thing -- only one buffer/MDI window open with a Java file, the same selective display, and the copy-shown invocation -- and ended up with only two windows, the Java file and the untitled one with the non-hidden lines. This is also with SlickEdit 11.0.1 on WinXP.
Have you by any chance modified any of the "standard" procedures, like new_file(), that I call from the macro... or, perhaps, something that one of them calls?
In any case, I'm glad you like the macro, even with the quirk.
Seth
-
Have you by any chance modified any of the "standard" procedures, like new_file(), that I call from the macro... or, perhaps, something that one of them calls?
I'm pretty sure I have not modified any of the stock macro files. So far, I've been able to do what I want with new macros, or ferreting out the events/hooks to use.
There probably is some configuration setting causing our difference in behavior.
-
Woah, this works great! I was just trying to do this the other day without a macro and it was a pain. Just as a point of reference, I'm using 10.0.3 and did not have the extra buffer issue. Thanks for a great macro.
-
For those getting the "extra buffer", I have attached a slightly modified version of seth's posting that uses _create_temp_view instead.
-
My slightly different variation... it just extracts any lines matching the regular expression directly into a new buffer. No need to perform the selective display first.
I end up parsing huge (15+ meg) log files by hand, and wanted to pull out information. Selective display was alright, but I would need to end up turning on selective display, copying the lines, opening a new buffer, pasting the result in, turning selective display off, then repeating for each set of data. Thus, this macro was born.
_command UTLExtractLines()
{
int SourceWindow;
int DestWindow;
Done = false;
/* Get the string to search for. */
if ((get_string(SearchStr, "RegEx to extract:") == 0) &&
(SearchStr != ''))
{
/* Grab a pointer to the source window. */
SourceWindow = p_active_form;
/* Make a new file, and grab its pointer too. It became active by
default. */
new_file();
DestWindow = p_active_form;
/* Save our current position in the source window. */
SourceWindow.save_pos(OrigPos);
SourceWindow.top();
do
{
if (SourceWindow.search(SearchStr, "R<") == 0)
{
SourceWindow.get_line(CurrentLine);
DestWindow._insert_text(CurrentLine"\n");
}
else
{
Done = true;
}
}
while ((SourceWindow.down() == 0) && (Done == false))
/* Finally, restore our original position in the source window. */
SourceWindow.restore_pos(OrigPos);
}
}