Beautify/Format code

General questions about using TextPad

Moderators: AmigoJack, helios, bbadmin, Bob Hansen, MudGuard

Post Reply
CJ
Posts: 17
Joined: Thu Apr 24, 2003 10:37 pm
Location: Vancouver, BC, Canada

Beautify/Format code

Post by CJ »

Hello everyone.

Does anyone know of a way to beautify/format the following code using a search/replace with a regular expression?

I'd like to format the code from this:

Code: Select all

        set north [lindex $string_list 0]
        set east [lindex $string_list 1]
        set elevation [lindex $string_list 2]
        set arsenic [lindex $string_list 3]
        set sulph [lindex $string_list 4]
to this:

Code: Select all

        set north      [lindex $string_list 0]
        set east       [lindex $string_list 1]
        set elevation  [lindex $string_list 2]
        set arsenic    [lindex $string_list 3]
        set sulph      [lindex $string_list 4]
In other words, I'd like the different parts each line of the code block to line up vertically.

Thanks for any insight.
CJ
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

One rather crude way is to use tab, you can set TP to convert them if you need.
This only works for your example code, not a very general solution.
Find ^( *[[:word:]]+ [[:word:]]+)( )(\[.+\].*)$
Replace \1\t\3
Using POSIX style from the Editor page of the Preferences dialog box.
Then I open up and see
the person fumbling here is me
a different way to be
User avatar
talleyrand
Posts: 625
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post by talleyrand »

No reg exp expert but this seems to get me in the ballpark
search for

Code: Select all

(.*)(\[.*\])
replace with

Code: Select all

\1\t\2
POSIX regular expressions[/code]
I choose to fight with a sack of angry cats.
User avatar
trids
Posts: 69
Joined: Wed May 07, 2003 10:16 am
Location: South Africa

Post by trids »

Post Reply