Show Selective Display Line Statistics
Sunday, September 7, 2008This discussion involves the commands "all", "allnot", "more", and "less". For the sake of conciseness, I'll call these four commands "the selective display commands", even though I know they aren't the only selective display commands. Additionally, this article assumes you're issuing these commands from the Slickedit command line and that you're using Slickedit 2008 or a comparable Slickedit version.
To show selective display statistics on the message line each time you run one of the four selective display commands, you need to insert 8 lines into your seldisp.e file (make a backup copy first). After you've done this, each time you run one of the four commands cited, the Slickedit message line will tell you:
- the number of lines matched (lines displayed)
- the number of lines not matched (lines hidden)
- the total number of lines in the file
Open seldisp.e from your macros folder and locate the start of the "all" command.
_command void all(...)
Scroll down to the following text near the end of the "all" command:
set_find_next_msg("Find", old_search_string, new_search_options);
restore_pos(p);
//return(status)
Insert the 8 new lines below, between the end of the 3 lines I just cited above and the last brace in the "all" command. The result will look something like:
/* these are the existing lines at the end of the "all" code */
set_find_next_msg("Find", old_search_string, new_search_options);
restore_pos(p);
//return(status)
<-------- insert new code here
}
/* after inserting the 8 new lines */
set_find_next_msg("Find", old_search_string, new_search_options);
restore_pos(p);
//return(status)
/* start of 8 new lines to insert */
// start selective display line statistics, added by [you] on [date/time]
If(p_Nofhidden==0)
{ // "String not found" message will be displayed
} else {
int NoflinesShown=0;
NoflinesShown=(p_Noflines) - p_Nofhidden);
message('Displaying ' NoflinesShown' of 'p_Noflines' lines | 'p_Nofhidden' hidden lines');
}
/* end of 8 new lines to insert */
} // final brace in the existing "all" code
Now if you run the command "all /banks/" on the following sample text, two lines will be displayed and five will be hidden, as is usual.
Sample text:
atlantic regional auto dealer financing aviation b-piece buyers
bad credit balance transfer bank mergers banks in sba programs banks
intl trade issuing credit cards offering lines of credit boats
book distributorships banks book publishing borrowing money for real
estate
The resulting selective display is:
+ bad credit balance transfer bank mergers banks in sba programs banks
+ book distributorships banks book publishing borrowing money for real
Now the message line will read:
Displaying 2 of 5 lines | 3 hidden lines
After you modify the original seldisp.e code and you see these stats a few times, you might find them helpful, especially in large files. You can customize the wording and appearance any way you want. For example, you could add a little more code to get the following result:
Selective Display Statistics: Now displaying 3 instances of "banks" in 2 of 5 lines; 3 lines are hidden
Clearly this is a long message and would be more appropriate if displayed in a message box.
By the way, I have two keys mapped to "show_all" and "toggle selective display" (i.e., expand and collapse visible and hidden lines), respectively. I use them constantly. I added the same 8 lines of code to "show_all" and "toggle selective display". After executing "show_all", the message line reads "All lines displayed". This helps me monitor my file size, search terms and contents continuously.
I hope this helps someone.
NOTE: You'll probably lose the changes to seldisp.e each time you install an update to the editor. You'll then need to re-insert the 8 lines of new code each time seldisp.e is updated. To avoid this, you can keep a modified copy of seldisp.e handy and replace the updated one with the modified version containing the 8 added lines. I keep copies of my modified versions of Slickedit modules in a directory called "dh-modified".
Before swapping the files, be sure to diff them so that you don't lose any important changes in the update to seldisp.e. Another way to avoid losing your modifications is to incorporate the code for "all" etc. into your vusrmacs.e file.
As always, I'm not a professional developer and my code might be a hack. Your mileage might vary. Please feel free to share ideas, bugs, suggestions, corrections, etc.
dh
0 comments:
Post a Comment