Robert Rollins wrote:
When a PHP programmer types an open curly bracket (or a Python
programmer types a colon) then presses Return, the expectation is that
the cursor will appear indented one tab further to the right than the
above line.  However, BBEdit's auto-indent brings the cursor to the
same level as the previous line, regardless of the contents of the
above line.  This requires an additional TAB press to bring the code
into the proper indentation level when starting a deeper block.

My impression is that this is something of a religious issue in these parts. :) I'm with you--while I think programmers should have the option of being able to turn this off, it's remarkable how much time this little trick, and its corresponding trick of automatic de-indenting when you start a line with a close bracket, ends up saving in practice.

The best I've done in BBEdit is create a combination AppleScript and "Universal Item" clipping to let me do an indent with Ctrl-Return, which not only isn't really syntax aware, it turned out to be less trivial than I was originally expecting. The clipping file I called "Return & Indent" and simply contains this, where "<r>" indicates a return character:

<r>
#INDENT##script maketab.scpt##INSERTION#<r>

(i.e., you need to have a blank line above the code.) The AppleScript is named "maketab" and contains this:

tell application "BBEdit"
        tell text window 1
                if expand tabs is true then
                        set insertText to ""
                        repeat tab width times
                                set insertText to insertText & " "
                        end repeat
                else
                        set insertText to tab
                end if
                insertText
        end tell
end tell

Both of those need to be saved in the "~/Library/Application Support/BBEdit/Clippings/Universal Items" folder. This is still not 100% ideal, as BBEdit's autocompletion will try to execute this via any time I type the word "return" in plain text; I'm not sure if there's a way to turn that off short of just renaming it something sufficiently weird that it's not likely to come up (or just turning off autocomplete).

At least for me, the hardest thing to adapt to in BBEdit is that AppleScript is pretty much essential if you want to learn how to do extensions. I know some people are very comfortable with AppleScript, but I am not one of them.

--
Watts Martin <[email protected]>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to