VHDL File Beautification

General questions about using TextPad

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

Post Reply
Mike_F
Posts: 2
Joined: Thu May 19, 2011 2:59 pm

VHDL File Beautification

Post by Mike_F »

Would like to beautify sections of code by aligning certain characters into columns.
For example I would like to beautify EX1 UGLY to look like EX2 NICE:

Code: Select all

--EX1 UGLY
signal pattern_match_thres_array_of_arrays_tb: tSTIMARRAY;
signal lfsr_tb                 : unsigned(30 downto 0);
constant cTRAINING_ARRAY                  : unsigned(17 downto 0):=o"


--EX 2 NICE
signal pattern_match_thres_array_of_arrays_tb : tSTIMARRAY;
signal lfsr_tb                                : unsigned(30 downto 0)
constant cTRAINING_ARRAY                      : unsigned(17 downto 0)
I spend too much time moving the : around by hand (adding spaces) after editing.
Stated otherwise I would like to add spaces prior to the : so that the :
is always in the same column.

Looking for an efficient REGX or macro trick.

If there were something that performed the behavior:
"Add spaces until character y is in column x on lines that contain z"
I would be happy!

Thanks

Mike
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I also have a need to do precisely this.

Unfortunately, there's no way to do it in TextPad without outside help; you need a script. But TextPad doesn't support scripts, and you can only do it with the aid of some unpleasant jiggery-pokery.

What I use is a TextPad command and a Perl script, stuck together inelegantly with the clipboard and some keyboard stuffing. If you're interested in this have a look at an old version that I posted here 6 years ago: http://forums.textpad.com/viewtopic.php?t=4890&start=25.
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post by Mike Olds »

I do this with tabs. At least a few keystrokes less.
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
User avatar
woho
Posts: 100
Joined: Tue Sep 02, 2003 9:12 am
Location: Steyr/Austria
Contact:

Post by woho »

I hardly dare to suggest a RegExp Search/Replace after ben_josephs - Rex of RegExp - has answered with a script solution
but anyway:

1) tiny extra condition:
the ':' must be far enough right in all your lines so that you can select a column with banks in all the rows left of ':' between
big help for that:
- block select (<Alt> Leftclick) white area left of ':' in row 2 + 3 in your example
- copy (Ctrl-C) it and
- paste (Ctrl-V) it repeatedely to shift the text to the right
- which results in

Code: Select all

signal pattern_match_thres_array_of_arrays_tb: tSTIMARRAY;
signal lfsr_tb                                      : unsigned(30 downto 0);
constant cTRAINING_ARRAY                                       : unsigned(17 downto 0):=o"
2) block select all lines you want to correct
from left: leftmost ':' of all lines (or further left as long as it is still in whitespace)
to right: rightmost ':' of all lines must be included (or further right)

3) search and replace with following setting
[X] Regular Expression
[X] replace only selected Text
[X] use POSIX Syntax in Textpad/Preferences

search
( *):
replace with
<someblanks>:

<someblanks>: here you write as many blanks as you want
voila:

Code: Select all

signal pattern_match_thres_array_of_arrays_tb       : tSTIMARRAY;
signal lfsr_tb                                      : unsigned(30 downto 0);
constant cTRAINING_ARRAY                            : unsigned(17 downto 0):=o"
Image

of course it would be comfortable to record a macro for 3) which you can assign to a keyboard shortcut then

Wolfgang
User avatar
woho
Posts: 100
Joined: Tue Sep 02, 2003 9:12 am
Location: Steyr/Austria
Contact:

Post by woho »

1) there is a 'between' too many in line 4 of my post above
2) are you aware of Preferences/Editor: [ ] constrain cursor to text
- helps a lot in avoiding the blank key when unchecked
- does not work with word wrap == ON
- not sure what is the default
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I do something similar for small corrections, but it gets tedious.

Here's an alternative for steps 2 and 3:

2) block select a single column covering the leftmost ':' (or further left as long as it is still in whitespace) and extending over all lines you want to correct

3) search and replace:
Search | Replace... (<F8>):
Find what: [a single space]
Replace with: [nothing]

Replace All -- do this repeatedly until it beeps
Post Reply