INSTRUCTIONS FOR FORMAT APPLICATION             11/10/92

**** IMPORTANT ****
Make sure you read this file first, and be sure you change the directory where the FORMAT.APP will reside in the Alt_X_RUN_PROGRAM, and F8_FORMAT macros in the FORMAT.FKY macro file.
*******************

Have you ever wanted to just pick a bunch of lines in your program in the FoxPro text editor and have them formated?

You know what I mean. You've been working all day on your code, you haven't used upper case, and sometimes you have. Sometimes you've added an if...endif, oops, lower case, and you didn't indent under the IF and there are dozens of lines of code that you want indented to help you see the flow of the code.

Some editors, like Brief with an optional program, allow you to highlight a number of lines and format them so the lines are nicely indented. The FoxPro editor seems to have left this out. You can send your code through Danalyst, through the snippet formatter SNIPFMT which is found under \GOODIES, or you can send it through FoxDoc, but you have to close the file or project you're working with before you call the program, and this is a real hassle when you just want to format a few lines.

What I really wanted to do was to just highlight the lines I wanted to format and have it done with just one keystroke. After thinking about this I took a gander at the source code for the SNIPFMT program which was written by Walt Kennamer. I then figured out what parts I needed, stripped down the SNIPFMT.PRG, and finally wrote a macro to do all the work.

It works something like this: First you highlight the text you want to format with your mouse, then press <F8>.

What? You want more details? OK. Here goes.

The program FORMAT.PRG in the FORMAT project is just a stripped down version of SNIPFMT.PRG. It doesn't look for various types of modules: screens, menus, programs or whatever, just a .PRG type of file. All the parts were removed that had anything to do with picking, choosing or anything else. The only other module left was the ALERT program.

After you highlight a bunch of text you leave the mouse cursor in the editing window then press the <F8> function key. This starts the macro which saves the text in the clipboard, sets SAFETY OFF, saves the name of the window where the cursor is in, opens up a new text file, copies the clipboard to the file, and then closes it. Next it executes the FORMAT.APP program which reads the text file, formats it, writes it and stops. The macro next opens the newly formated file that FORMAT.APP wrote, selects all the text, copies it to the clipboard, closes the file, changes over to the window with the program you are working on, and then replaces the selected text with the newly formatted text in the clipboard.

If you want to set up the formatting in some other way, the variables at the beginning of the program allow you to lower case reserved words, set tabs, etc. I added a variable that can skip over checking the reserved words. This will speed things up because the keyword database isn't created, and we just skip the lookup of the reserved words in the table. You can't at this point change any of the variables except from within the program. But there is no reason not to change the program to accept parameters and have different function keys change the way the selected text is formatted.

I found some problems with SNIPFMT, one which I fixed right off. The program pads any word it finds to four characters so that it can be used to seek the database. If your variable is less than four characters, you might find that it has some spaces after it. I trim the variable before it is put back in the text.

Another problem seems to occur if indenting for CASE is turned on and there is an IF...ENDIF after the case statement. This throws off the indenting sequence. I haven't fixed this yet, but perhaps someone already has.

A third problem is when a comment does not start at the beginning of a line it isn't left alone. I haven't fixed this one either.

Another problem is when formating TEXT...ENDTEXT regions. These parts should be left alone, SNIPFMT indents these sections and moves anything you typed in, thus messing up any formating that you had done here.

All my modifications have *** MODIFIED *** & **************** around them so you know where SNIPFMT.PRG was changed.

The macro file is included in the project, so that you can modify it to work with other keys if you want, and to change the location of the application. You should also make sure that none of your present macro keys conflict with the ones in this file.

You also have to have the PROWORDS.FXD file available in your \FOXPRO2 directory if you want to change the case of the reserved words.

A warning: I use <CTRL><F1> to return to the window we started in. This seems to work fine in everything I tried. However, I can't guarantee this will work every time. Other methods I tried didn't  work all the time, but <CTRL><F1> seemed to be the most reliable. Also if you change your menu and don't have Window available this might not work at all.

Remember, this is just a handy little routine that works for the most part on little sections of code. I would suggest checking the results before you commit the editing to disk. If you try this on large files it may not give you everything you want. So before you close your file please check it and if it doesn't look the way you want exit with a 'No' or do an 'Undo' and your file will be restored the way it was.

I hope that this little application saves you lots of time and becomes a handy little routine.

Thanks to Walt Kennamer for SNIPFMT, and Dave Watkins and Calvin Hsia for helping with a tricky part of the macro that gets us back to the original window.

Tony Scarpelli
4thWay Consulting
82 Wellington Rd.
Portland ME 04103
207-774-9823
