Suitable text editor with advanced features


I'm using TextWrangler at the moment to edit code. It is an OK editor, but now I find that I need more advanced features that it seems not to have. I would like that if I write an if statement or while statement, the code below the statement is automatically indented and when I close the if statement, the 'end;' statement should be put at the same level as the if statement. This makes editing lengthy procedures less of a chore. I have utilised editors that have these features, but on Windows. Examples are Borland C++ compiler and Visual Studio 6 and .NET
If anybody has used or uses a text/code editor with such or similar features, then please suggest it. I would appreciate it.
I've been using Xcode, but otherwise my editors of choice are subethaedit and smultron. Xcode is by far the most feature rich and I know it does the indenting thing you speak of. I'm not sure about the others. It has been a while.