Can you convert tabs to spaces in selected text?

General questions about using TextPad

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

Mendel Leisk
Posts: 5
Joined: Tue Nov 18, 2003 2:23 pm

Can you convert tabs to spaces in selected text?

Post by Mendel Leisk »

I'd like to leave my tabs in documents as they are, when creating them, or when saving the file. But sometimes, I'd like to convert the tabs to spaces in a specific, selected block of text. Is this possible?
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

1. Select Block Select Mode from the Configure menu, or
hold down the alt-key while selecting with your mouse.
2. Press F8 for Replace, find \t, replace " " (space), the
Selected text radio button should be selected already.

(3. Make sure "Convert New tabs to Spaces" and
"Convert Existing Tabs to Spaces When Saving Files"
are unchecked for the relevant document class, use
Default for all.)
HTH
Then I open up and see
the person fumbling here is me
a different way to be
Mendel Leisk
Posts: 5
Joined: Tue Nov 18, 2003 2:23 pm

Post by Mendel Leisk »

Hi s_reynisson,

Thanks for quick response. I'm aware of the process for replacing regular expressions, things like double spacing paragraphs and the like. I was thinking of doing what you described, but thought, this is not really going to work, since the various tab symbols in my selection need to be replaced with varying quantity of spaces. I tried your suggestion and this turn out to be the case, I think, unless I'm missing something.

If I have "Convert New tabs to Spaces" or "Convert Existing Tabs to Spaces When Saving Files" ticked in preferences, it does exactly what I want: replace tabs with an APPROPRIATE number of spaces to match the spacing which existed previously, with each tab symbol. The number of spaces varies.

But, I don't want to apply this globally. The only way I can see to cobble a solution:

1. Cut and paste the selection to a new document.

2. Tick "Convert Existing Tabs to Spaces When Saving Files"

3. Save the new document

4. Select all and copy.

5. Untick "Convert Existing Tabs to Spaces When Saving Files"

6. Paste my selection back into the original document.

7. Delete the new document I've created.
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

What about creating a document class for just that?
Then you don't have to tick those options on and off all the time.
Then I open up and see
the person fumbling here is me
a different way to be
Mendel Leisk
Posts: 5
Joined: Tue Nov 18, 2003 2:23 pm

Post by Mendel Leisk »

Does the new document class have to have a different extension? Sounds like cobble #2, first impression. I tryed to create one, "tabs to spaces", and told it to use extension ".txt", and it warned me this was taken, so I cancelled out. Would I have to be creating separate files, with separate filename extensions?? Sounds awkward, if that's the case. I'd just like to work in ".txt" extension files, and be able to do this within any file, without rigamorol.

I suspect it just isn't possible at present, at least not in a simple, direct way. Wish list item???
Mendel Leisk
Posts: 5
Joined: Tue Nov 18, 2003 2:23 pm

Post by Mendel Leisk »

Ok, if I tick just the convert new tabs to spaces in the text document class, copy the tabbed text, then paste, it comes in with spaces. If I then untick that same box, and do another paste, it comes in with tabs. Relatively painless. Helps that the configure menu remembers where you just were. Thanks for the suggestions, I'll muddle off now.
User avatar
Tomas Eklund
Posts: 40
Joined: Tue Mar 16, 2004 1:15 am
Location: Sweden

Should be on the wishlist though..

Post by Tomas Eklund »

"Replace tabs with spaces" and "Replace spaces with tabs" really should be easily accessible menu options - not something you have to create document classes and use clumsy workarounds for. Working with a file that uses real tabs is a lot smoother I think, but sometimes you need to temporarily convert the tabs to spaces - like when you send the file to a program, printer, whatever that doesn't handle tabs very well.

I need to do these conversions back and forth every now and then. And when I do, I have to resort to a different editor (EditPad Pro), which has this feature.

So... Put it on the todo-list please! Shouldn't be too hard to implement either.
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

View->Document Properties (Alt-Enter), select the Tabulation tab and you're in business ;)
Then I open up and see
the person fumbling here is me
a different way to be
User avatar
Tomas Eklund
Posts: 40
Joined: Tue Mar 16, 2004 1:15 am
Location: Sweden

Post by Tomas Eklund »

Are you an opponent of useful, lightweight features? ;-)

I know about the "convert existing tabs to spaces on save" feature and it may come in handy at times, but for this purpose it's useless. First of all, I don't want to have to do five clicks and a save in order to do the tabs-to-spaces conversion. One single keystroke please. Secondly, I want to be able to convert back from spaces to tabs, and the workaround can't do that. (And even if it could, it would still be a workaround -- and workarounds are, and always will be, workarounds.)
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

*hick!* No. Agreed!
and while Helios scramble their forces on this you could record two macros(*):
1. Ctrl-Shift-R, F8, find "_{4}", replace "\t", replace all, close, Ctrl-Shift-R
2. Ctrl-Shift-R, F8, find "\t", replace "____", replace all, close, Ctrl-Shift-R
Where _=space and tick regular expression in the replace dialog
Goto Configure->Preferences->Keyboard and assign shortcuts to the macros
I'm using 4 spaces as my indentation and now Ctrl-Shift-A and Q "toggle" nicely for me.
Not perfect and you risk loosing your shortcuts and macros on diffrent systems if you don't transfer your settings etc... on the plus side it only takes you two or three minutes to do this.
(*) denotes a workaround :roll:
Then I open up and see
the person fumbling here is me
a different way to be
User avatar
Tomas Eklund
Posts: 40
Joined: Tue Mar 16, 2004 1:15 am
Location: Sweden

Post by Tomas Eklund »

I do appreciate your attempts to help out. However, I'm afraid I'm still out of luck... (well, I do have EditPad Pro and I use it right now so it's not as bad as it sounds)

I don't think it's possible to create a regexp search-and-replace that accurately replaces spaces with tabs - nor the other way around. You have to consider that a tab sometimes should be replaced with one space character, sometimes with two, three or four. (I also use four space indentation.) Because tabs aren't used for indentation only.

For a while I thought: Perhaps it would work if I created a sequence of search-and-replace operations like this (see below)? But it will not work. Because when a tab is inserted at a certain position it will count as only one character even though it occupies the space of 1-4 characters.

find "^_{4}" replace "\t"
find "^([^ \t]{1})_{3}" replace "\1\t"
find "^([^ \t]{2})_{2}" replace "\1\t"
find "^([^ \t]{3})_{1}" replace "\1\t"
find "^([^ \t]{4})_{4}" replace "\1\t"
find "^([^ \t]{5})_{3}" replace "\1\t"
User avatar
Tomas Eklund
Posts: 40
Joined: Tue Mar 16, 2004 1:15 am
Location: Sweden

I just HAVE to bring this up again

Post by Tomas Eklund »

Gosh, I would've liked that feature right now... :-/

Are Helios Software Solutions really responsive to feature requests made in this forum? I haven't been around long enough to tell.

It's interesting to see how much work some people here put down into making complex workarounds to problems that should be really easy for Helios to fix.

Perhaps I should contact them directly on this matter?
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

Helios staff frequent here in the forums, at least two of them anyway. You can contact them directly at http://textpad.com/support/feedback.php , set the form "type" to "feedback". You can also start a poll to back you up, ie. if its simple to implement and does not affect TP regarding performance and/or size etc. you are likely get a good response on it.
Polls are posted in the Enhancement Suggestions forum and take care to use five options, that way it will be counted/included in Jeffy's list, scroll down to view the latest version.
Then I open up and see
the person fumbling here is me
a different way to be
swingheim
Posts: 4
Joined: Tue May 11, 2004 5:17 pm

Easy... if REAL regex were supported

Post by swingheim »

I am pulling my hair out-- I wish Textpad had the same support for RegEx as Perl does.

To solve your problems, if TextPad support REAL regex, you could do it with this single search and replace:

Search:
^\s{1,4}
Replace:
\t

That would search for a minimum of 1 space, up to 4 spaces, and replace them with the tab character. But of course, TexPad barfs horribly on such a statement.

I myself am trying to search for multiple instances of the space character (2+) and replace them with a single space. In perl, the following would work:

Search:
\s{2,}

Replace:
\s

But not in TextPad... grrrrr.... "\s" searches for the "S" character (?!?!) and not the space character. WTF?

As far as I am concerned, TextPad has a crippled and limited support of RegEx, and I think I am going to stick with Perl to do all my search/replace when RegEx is involved.

Hey Mendel Leisk,

If you are still needing to do the aformentioned, reply to this and let me know. I'll post a simple perl program, and you can download/install the ActivePerl for Win32, and run the program against your file.
User avatar
Tomas Eklund
Posts: 40
Joined: Tue Mar 16, 2004 1:15 am
Location: Sweden

Nope... Still not easy

Post by Tomas Eklund »

It is true that TextPad's support for regular expressions are very limited and I'm hoping for an improvement soon. However, what you are trying to accomplish is rather easy, even using TextPad.

You don't need the \s to search for a space character. Just type the space character in explicitly. Like this:

Search:
^_{1,4}
Replace:
\t

However, that is NOT the same as doing a "convert spaces to tabs" operation. To accomplish that you need more programming than just a simple regexp

Replacing multiple spaces with a single one is easy:

Search:
_{2,}
Replace:
_

Where _ is the space character - just press the space bar in the search and replace boxes. I made it a red underscore here so that it would be visible. You can even get away with:

Search:
_+
Replace:
_

You need to get a little more complicated than that (but just a little) in order to outgrow TextPad's regex-flavor.
Post Reply