About myslickeditmacros

, , , , , Thursday, September 4, 2008

If this is your first time here, please read the following
important background information.


Here you'll find Slick-C macros of all kinds
, from overly simple to fairly complex. I'm a writer/editor/journalist by trade, not a professional developer. Slick-C programmers should find something 0f interest here, including plenty of code that can be tweaked or fixed.

The purpose of this blog is to address the shortage of Slick-C code on the Web, while stimulating discussion and encouraging code sharing.

I've used Slickedit in my daily work since approximately 1998. Currently I have 388 _command macros in my vusrmacs.e file. I'm sure there are other Slickedit users whose macro folders are wishing to burst free and benefit the larger community.

My professional roles are technical writer; editor and researcher of print and electronic publications; desktop publisher
; journalist. My programming experience has generally been limited to high-level scripting languages. I've spent a lot of time using numerous text editors and macro languages. Of the two kinds of Slickedit users named in the subtitle of this blog, I'm a Wordsmith rather than a Code Maven.

This blog is not meant to replace Slickedit Documentation, Slickedit Community Forums, "Hello World:" The Slickedit Developer Blog or other Slickedit-related sites. There's plenty of good stuff in those places. I'll post a listing of a bunch of good resources soon.

Many of "my" macros--perhaps a third--borrow from, or are based on, code examples or fragments that I've run across in the past 10 years. This includes lots of Slick-C code and ideas plucked from the guts of Slickedit's code modules themselves. And of course, I've borrowed liberally from third party sources.

If I've failed to credit the authors of any of the code on this blog, please contact me. The same goes for any code that duplicates functionality already built into Slickedit. Please call deprecated procedures to my attention. I will gladly remove, change or credit code in response to reasonable requests.

Again, most macros on this site are relatively simple. Some are simply shortcuts for frequently used commands, regular expressions or tedious command-line typing. I hope you find some of them useful.

Wordsmiths and Code Mavens, grab a Jolt and let's get started. Let's all take full advantage of what is probably the best, most complete and most full-featured text editor ever created.


Here's a simple macro I use frequently. It quickly counts the number of paragraphs in the current buffer and displays the result on the command line. This is helpful because I often work with documents containing hundreds of thousands of lines and thousands of blocks of text. If you wish to change the parameters for recognizing a paragraph, you can modify the #defines at the top of the macro.

// count_paragraphs: count number of paragraphs in buffer
_command coupar,count_paragraphs() name_info(','VSARG2_REQUIRES_EDITORCTLVSARG2_READ_ONLY)
{
#define PARAGRAPH_SKIP_CHARS ' \t '
#define PARAGRAPH_SEP_RE ('(^['PARAGRAPH_SKIP_CHARS']*$)')
#define SKIP_PARAGRAPH_SEP_RE ('^~(['PARAGRAPH_SKIP_CHARS']*$)')

if (p_Noflines==0) {
message('Empty file');
stop;
} else {
para_count=1;
}

_save_pos2(p);
top();up();

for (;;) {
_begin_line;
/* skip paragraph separator lines */
status=search(SKIP_PARAGRAPH_SEP_RE,'r');
if ((status==BOTTOM_OF_FILE_RC) (status==STRING_NOT_FOUND_RC)) {

get_line(line);
if (line=='') {
para_count = para_count - 1;
}

message(para_count ' paragraphs');
break;
} else {
/* Search for paragraph separator line. */
status=search(PARAGRAPH_SEP_RE,'r');
if ((status==BOTTOM_OF_FILE_RC) (status==STRING_NOT_FOUND_RC)) {
message(para_count ' paragraphs');
break;
}
++para_count;
}
}
_restore_pos2(p);
}


1 comments:

  1. davec95 said...

    I've been using Slick Edit for years but my macro knowledge is a bit lacking. Can a SE'08 macro clean up CR,LF erros? (like replace lines ending with CR,LF,CR with CR,LF. Or better yet, any kind of line ending with CR,LF).

Post a Comment

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