Treat groups of n consecutive spaces like a tab?

General questions about using TextPad

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

Post Reply
mspacek
Posts: 8
Joined: Thu Apr 17, 2003 4:32 am
Location: Vancouver, BC, Canada

Treat groups of n consecutive spaces like a tab?

Post by mspacek »

Hi,

I'd like to convert all of my Python code to use 4 spaces instead of tabs (this is good Python coding style). I'll probably do a find & replace on all my Python files, and then I'll set the "convert new tabs to spaces" checkbox for my Python class in Textpad. No problem.

The thing is, I like the convenience of being able to jump back and forth between different levels of indentation with just a single left or right arrow key press, or a single press of the backspace key. If I switch to spaces instead of tabs, I'll lose that convenience. What previously took a single keypress will now require 4.

Is there any way to get Textpad to treat a group of (n=4 in my case) consecutive spaces as it would a single tab? What I'd like is:

1) If the cursor is followed by n or more spaces, and I hit the right arrow key, the cursor will jump forward n columns.
2) If the cursor is preceded by n or more spaces, and I hit the left arrow key, the cursor will jump backwards n columns.
3) If the cursor is preceded by n or more spaces, and I hit the backspace key, the preceding n spaces will be deleted and the cursor will jump backwards n columns.

The fourth obvious item would be to have a tab keypress generate n spaces, but Textpad already does that.

Any tips or workarounds would be greatly appreciated.

Cheers,

Martin
mmcalli
Posts: 2
Joined: Tue Mar 08, 2005 10:51 pm

Post by mmcalli »

Make sure you have a Python document class. Then go to Tools -> Preferences -> Document Classes, and select the document class associated with your file extension. Within that document class, select the "Tabulation" option. Then:-

- Set default spacing to 4
- Select indent size to 4
- Check the options "convert new tabs to spaces" and "convert existing tabs to spaces when saving files."

Also, try this. Select a block of code. With the code selected, hit the tab key. Watch it be nicely indented 4 spaces (or whatever your indent size is). With the code selected, hit shift-tab .... watch the indentation be reduced. All nicely. You can also do this on a new line with now code in it - tab and shift-tab to jump in and out your default indent size.

Enjoy!

Mike
User avatar
talleyrand
Posts: 624
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post by talleyrand »

For your movement, you can also use either Ctrl+Left/ Ctrl+B or Ctrl+Right / Ctrl+W to skip to the next word.
I choose to fight with a sack of angry cats.
mspacek
Posts: 8
Joined: Thu Apr 17, 2003 4:32 am
Location: Vancouver, BC, Canada

Post by mspacek »

Thanks, but like I said, I'd like to be able to move back and forth between indentations using only the cursor keys. Also, I'd like to be able to delete only n spaces at a time. I can delete all the spaces to the left or right of the cursor using Ctrl+Backspace and Ctrl+Del, but that's not the behaviour I want.

I guess this is really more of a feature request: to have the ability to treat an arbitrary number of spaces the way a single tab character is treated, specifically via the keyboard.

Martin
mspacek
Posts: 8
Joined: Thu Apr 17, 2003 4:32 am
Location: Vancouver, BC, Canada

Post by mspacek »

Well, I just realized I should really be using the Increase and Reduce Indent commands. What I like about them is that you can be anywhere on the line (not necessarily before the text you want to indent/unindent), and the whole line will move forward or backward one indent. Duh. You can select multiple lines and indent/unindent them all at once. Even those that are only partially selected still get indented/unindented. This is great cuz it allows for laziness in cursor positioning and text selection, which makes it really fast.

The default key mappings for this are Ctrl-I and Ctrl-Shift-I. To make it a bit more intuitive, I've added Ctrl-. (that's lowercase >) for IndentMore and Ctrl-, (lowercase <) and Ctrl-U for IndentLess.

I'm off to convert all my Python code to use 4 spaces instead of tabs...

Cheers,

Martin
mspacek
Posts: 8
Joined: Thu Apr 17, 2003 4:32 am
Location: Vancouver, BC, Canada

Post by mspacek »

Another note:

Let's say I'm on a blank line and I hit tab to indent. Sometimes I tab one too many times, and I want to delete the unwanted spaces back to the previous tab stop, without having to hit Backspace however many times. IndentLess doesn't seem to work for a line with only spaces on it. So, I made the following macro and assigned it to Shift-Backspace:

Shift-Tab - this gets you back to the previous tab stop
Ctrl-Shift-Right - this highlights from the previous tab stop to the end of the extraneous spaces
Del - this deletes all of the extraneous spaces

Is there a built-in command that already does this?

I'd like to have the option of getting the same behaviour just by hitting Backspace, but this'll do for now.

Cheers,

Martin
Post Reply