04 May 2006

Perl programming in joe

I do a lot of Perl programming, and I use joe (Joe's Own Editor). I've defined a few macros that I found pretty useful when scripting. Just add the following macro definitions to your .joerc file (do a text search in .joerc for 'Macros:', and add the lines there-ish):

:def comment filt,"sed -e \'s/^/#/g\'",rtn,tomarkb,markk,prevpos
:def uncomment filt,"sed -e \'s/^#//g\'",rtn,tomarkb,markk,prevpos
:def perltidy bof,markb,eof,markk,filt,"perltidy",rtn,bof,markk

comment ^K 1
uncomment ^K 2
perltidy ^K 3

The first macro comments out a section of text by putting a '#' at the beginning of each line of the section. To use it, just go the the beginning of the section you want to comment out and do 'Ctrl-K b', move to the end of the section and do 'Ctrl-K k', and then do 'Ctrl-1'. It'll comment out those lines, disengage the block (so that the section of text will no longer be highlighted), and return the cursor to the previous position (probably the end of the section of text).

The second macro does just the opposite by uncommenting a section of text.

(You could probably replace the '#' in the macro definitions with a pair of forward slashes for programming in PHP or JavaScript.)

The third macro applies the 'perltidy' program to the entire file (not just a highlighed section). Of course, you'll need perltidy installed for this to work. It's in the Fedora Core extras, and the project home page is http://perltidy.sourceforge.net/.

No comments: