TextWrangler---Auto indentation

8,433 views
Skip to first unread message

Bingchen Liu

unread,
Feb 8, 2014, 2:35:12 PM2/8/14
to textwr...@googlegroups.com
Hey everyone,

I am new to TextWangler and I have a question which I think is quite important. I use text wrangler to write python code, and the indent is important. But I don't see the auto indentation in text wrangler. 
For example, if I write:

if 2==2:  

and when I hit the enter, it becomes:

if 2==2:
print "hey there"

I thought text wangler can auto materially make it as:
if 2==2:
     print "hey there"

without using tab. 

So, is this just a feature of text wrangler or is it because that I have't activate some features in it to make this possible. 

Thanks!
1.png

Steve

unread,
Feb 9, 2014, 3:07:43 AM2/9/14
to textwr...@googlegroups.com
This is not a function of TextWrangler. While it will indent a line to the same level as the previous line, it is not context-aware and able to indent or outdent blocks of code intelligently.

Tony Chung

unread,
Feb 9, 2014, 3:42:03 AM2/9/14
to textwr...@googlegroups.com
That said, Espresso has really amazing indentation and auto complete.

-Tony


On Sunday, February 9, 2014, Steve <onli...@gmail.com> wrote:
This is not a function of TextWrangler. 
...

On Saturday, February 8, 2014 11:35:12 AM UTC-8, Bingchen Liu wrote:
I use text wrangler to write python code, and the indent is important. But I don't see the auto indentation in text wrangler. 
...

 

Rich Siegel

unread,
Feb 9, 2014, 3:27:57 PM2/9/14
to textwr...@googlegroups.com
On Sunday, February 9, 2014, Tony Chung <to...@tonychung.ca> wrote:

>That said, Espresso has really amazing indentation and auto complete.

This is the *TextWrangler* users' list, and as much respect as
we have for Jan and his work, if your contribution to a given
thread is just to advocate the use of Espresso, then that
doesn't help the folks who are using TextWrangler to make the
most of it.

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.

Nestor E. Aguilera

unread,
Feb 9, 2014, 6:31:09 PM2/9/14
to textwr...@googlegroups.com
As far as I can tell, TW right now has some interesting features for python coding (which you might set in the preferences):

- Syntax coloring.

- Indentation: set indentation to 4 spaces, keep the indentation level after each "enter/return", de-indent with backspace/delete.

Also command-] and command-[ will indent/unindent paragraphs or blocks (see the "Listing by Menu and Command Name" in TW's manual).

Even dedicated python editors such as IDLE will not do the indentation if there is no colon at the end of the line, and they will certainly not unindent since there is no way of telling when you are done with the block (so you must do something "manually" anyway).

On the other hand, I guess it shouldn't be too difficult for the BareBones people to make TW to automatically indent python code when there is a colon at the end of the line and you hit return/enter.

All the best,

Nestor

Walter Ian Kaye

unread,
Feb 10, 2014, 9:27:34 AM2/10/14
to textwr...@googlegroups.com
At 08:31 p -0300 02/09/2014, Nestor E. Aguilera didst inscribe upon
an electronic papyrus:

>On 9 Feb 2014, at 05:07, Steve wrote:
>
> > This is not a function of TextWrangler. While it will indent a
>line to the same level as the previous line, it is not context-aware
>and able to indent or outdent blocks of code intelligently.

And something I had forgotten but remembered the other day upon being
unable to find any sort of "make this document auto-indent now"
doohickey, is that if you press Option+Return, it will do the
opposite of the auto-indent setting. E.g.:

auto-indent off:
Return does not auto-indent
Option+Return auto-indents

auto-indent on:
Return auto-indents
Option+Return does not auto-indent


>On the other hand, I guess it shouldn't be too difficult for the
>BareBones people to make TW to automatically indent python code when
>there is a colon at the end of the line and you hit return/enter.

I was almost going to suggest a script, but that would take longer to
run than just hitting Tab. :D


-boo

Bingchen Liu

unread,
Feb 10, 2014, 9:59:03 PM2/10/14
to textwr...@googlegroups.com
Hi everyone, 

Thank so much for clarifying all these. super helpful!
Thanks again!

Kendall Conrad

unread,
Feb 20, 2014, 6:20:11 PM2/20/14
to textwr...@googlegroups.com
I created a script a while back for helping with this. You have to assign it to a keyboard shortcut, but it handles a lot of indentation cases, such as the Python one you gave an example of. I assign it to cmd+enter so it's not much different than what you would be use to, you just have to remember to use it when you want the effect. Hopefully it can help you out. It works for TextWrangler and BBEdit, just have to update the top of the script to point to TextWrangler.

http://www.angelwatt.com/words/2011/04/11/bbedit-smart-newline-open-line/

-Kendall

Walter Ian Kaye

unread,
Feb 21, 2014, 4:08:18 AM2/21/14
to textwr...@googlegroups.com
At 03:20 p -0800 02/20/2014, Kendall Conrad didst inscribe upon an
electronic papyrus:

>It works for TextWrangler and BBEdit, just have to update the top of
>the script to point to TextWrangler.
>
>http://www.angelwatt.com/words/2011/04/11/bbedit-smart-newline-open-line/


Funny this comes now, as I'm working on a script for both TW and
BBEdit... and thinking about how I might have it check the frontmost
app and figure out itself which one to target.

Rich/Patrick, are the raw event codes mostly the same for both apps?
(I mean apart from the model change from one doc per window.) If I
wanted to get the text contents of the current document and have the
code work across TW and BBEdit and across different versions of them
all, is there some compact <<code>> that would work, or would it
require a whole bunch of 'if' statements?

Christopher Stone

unread,
Feb 21, 2014, 11:19:43 AM2/21/14
to TextWrangler-Talk
On Feb 21, 2014, at 03:08, Walter Ian Kaye <bood...@gmail.com> wrote:
Funny this comes now, as I'm working on a script for both TW and BBEdit... and thinking about how I might have it check the frontmost app and figure out itself which one to target.
______________________________________________________________________

Hey Walter,

I expect there are things in BBEdit that aren't in TextWrangler, but the event structure should be the same otherwise.  You've got to test both apps with your code though.

The appended script will work equally well with BBEdit and TextWrangler.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------

using terms from application "BBEdit"
tell application whichApp()
make new text document with properties {name:"I'm Expendable!", text:"I told you so!"}
end tell
end using terms from

on whichApp()
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set _app to text item -2 of (path to frontmost application as text)
set AppleScript's text item delimiters to oldTIDS
return text 1 thru -5 of _app
end whichApp

-------------------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages