Formatting Text to the Left...

General questions about using TextPad

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

Post Reply
User avatar
mmiller
Posts: 17
Joined: Tue Nov 25, 2003 11:49 pm
Location: Canada
Contact:

Formatting Text to the Left...

Post by mmiller »

Hi;

TextPad is great! I'm a new user though and have a question.
I'm working on HTML files that were created long ago and when opening them in TextPad I would like all the text to automatically move to the left.
So there would be no identation of any lines.

The idea being that I want to get rid of any dead space. I hope there's a way to make it do that :)
Best Regards;
Marvin Miller
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

You may not really want to do that, HTML code does not use conventional line breaks. It may be coded for visual reading by programmer but have no effect on execution by browser. You may have a "return" code on the line for visual purposes, but it might break the syntax if you do automated replacements. Some leading spaces may be required to keep correct HTML syntax.

But, if you insist, try this:
================================
For some control about the spacing this is one method.

From the Main Menu
Edit, Select All.
Edit Reduce Indent. Repeat this as necessary until all text is shifted to left
===============================

Or use this method which will give no control on indentation.
Search and Replace using Regular Expressions (POSIX format):

Before doing Search and Replace, press CTRL-Home to go to beginning of document. You may also want to turn Word Wrap OFF for better visual of results.

NOTE: I have inserted underscore "_" to represent a visual space character. Actual code should be a real "space" character. (Using POSIX format)

Search for: \n(_+|\t+)(.*)
Replace with: \n\2

Explanation of RegEx Search expression:
\n ........ = Return code
( ......... = start of first tagged expression
_ ......... = space character
+ ........ = one or more of preceeding character (space)
| ......... = OR
\t ......... = Tab code
+ ......... = one or more of preceeding character (tab)
) ......... = end of first tagged expression
( .......... = start of second tagged expression
. .......... = any character
* ......... = any number of preceeding character (any character)
) .......... = end of second tagged expression

Explanation of RegEx Replace expression:
\n ........ = Return code
\2 ........ = second tagged expression
Last edited by Bob Hansen on Wed Nov 26, 2003 3:44 am, edited 1 time in total.
Hope this was helpful.............good luck,
Bob
User avatar
mmiller
Posts: 17
Joined: Tue Nov 25, 2003 11:49 pm
Location: Canada
Contact:

Post by mmiller »

Thanks Bob - I appreciate the fast reply. I'll try it out tonight and see if it's safe to do to my HTML :shock:
Best Regards;
Marvin Miller
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Hmmm, I just tried a few more test pages, and saw some lines that still had a few leading spaces.:oops:

No time to look at it now, but the RegEx above will probably get rid of most of the leading spaces for you.......perhaps someone else will correct this before I get back to it again?
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Search for: ^[ \t]+
Replace with:
Select "Regular Expression".
Select "Replace All".

(I.e., search for all sequences of spaces and tabs at the beginning of a line, and replace each of them with nothing.)

Bob's version won't find spaces after tabs.

But, as Bob asks, why would you want to do that?
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Hey Marvin, looks like you are all set!

ben_josephs got back before me with a better solution. The errors I mentioned that I saw were as noted, some spaces following tabs.

My new solution is just about the same as his.

Again I have included underscore "_" as a visual "space" character. (Using POSIX format):

Search for:^[\t_]*
Replace with nothing.

Explanation of RegEx Search expression:
^ ...... = start at beginning of line
[ ....... = start of specific character class
\t ...... = tab character
_ ....... = space character (use a real "space")
] ....... = end of specific character class
* ...... = any number of preceeding expression
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

It's a good habit to avoid regular expressions that match empty strings, so that you can use them conveniently for repeated searches. If you match an empty string, the current position doesn't advance, so the next attempt matches the same empty string, and so does the next one, and the next one...

When you search and replace using a regex that matches empty strings, the engine secretly advances one character after each empty match to ensure that it doesn't loop endlessly.
User avatar
mmiller
Posts: 17
Joined: Tue Nov 25, 2003 11:49 pm
Location: Canada
Contact:

Post by mmiller »

Thanks guys!

The reason why I want to get rid of leading spaces is to make the file sizes as small as possible. You'd be surprised how much space in a file is taken up by dead space.

What I'm doing is re-vamping my website. It was originally coded with Front Page so I'm in there trimming & editing to make it fully W3C compliant.

While I'm at it I want to add new content, re-write sections to get rid of clunky and inefficient code and also remove any whitespace from the files.

I'm finding significatnt reductions in file sizes and I'm not done yet :shock: Once completed the site should load way faster and my monthly traffic will be much less due to smaller sizes.

As well, the Internet itself should be less congested due to my cleaner code :D
Best Regards;
Marvin Miller
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

As well, the Internet itself should be less congested due to my cleaner code
I thought it seemed faster today.....thanks a lot! :D
Hope this was helpful.............good luck,
Bob
Lennart
Posts: 1
Joined: Mon Dec 15, 2003 3:31 pm

Post by Lennart »

The most easy solution must be to select all text and the use SHIFT + TAB a copule of times. :lol:
Post Reply