Page 1 of 1

Beautify/Format code

Posted: Fri Apr 02, 2004 3:55 pm
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

Posted: Fri Apr 02, 2004 7:23 pm
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.

Posted: Fri Apr 02, 2004 7:25 pm
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]

Posted: Thu Apr 08, 2004 7:03 am
by trids