Here's two AppleScript scripts that I wrote for this type of thing. I
think I made it after a discussion here actually. I have it set with
cmd+return / cmd+shift+return. It handles cases for JavaDoc (/**),
open curly, colon, and by default will just move down a line with the
correct indentation. One benefit is it allows you to execute it no
matter where you're at on the current line. It just looks at the end
of the current line to determine what to do.
The second script is similar except it will create a new line above
the current one with correct indentation and can be executed from
anywhere on the current line. I made these to mimic vim's o and O
commands, though I added extras for o to have some extra output.
Hope these help. They're not automatic, but I have found them very
helpful in coding.
-Kendall
(*
Author: Kendall Conrad of Angelwatt.com
Name: Smart Newline
Created: 2010-01-23
Description: Based on the current line it will generate different
text for the context. It knows about indentation, code doc syntax,
function starts
*)
tell application "BBEdit" to tell front window
activate
set lineNum to startLine of selection
set leng to length of line lineNum
-- Move cursor to end of line
if leng > 0 then
select insertion point after (character (leng) of line lineNum)
end if
-- Find leading whitespace
set theResult to find "(^[\\s]*)" options {search mode:grep}
searching in line (lineNum)
-- Set text to the white space found
set white to ""
if found of theResult then
set white to found text of theResult
end if
set wleng to length of white
-- Are we starting a code doc?
if (leng - wleng) ≥ 3 then
if (characters (wleng + 1) through (wleng + 3) of line lineNum
as
string) is equal to "/**" then
set selection to return & white & " * " & return &
white & " */"
select insertion point after line (lineNum + 1)
return
end if
end if
-- Check if inside a code doc
if (leng - wleng) ≥ 1 then
if (characters (wleng + 1) through (wleng + 2) of line lineNum
as
string) is equal to "* " then
set selection to return & white & "* "
select insertion point after line (lineNum + 1)
return
end if
end if
-- Check for code block {}
if (leng - wleng) ≥ 1 then
if (character -1 of line lineNum as string) is equal to "{" then
set selection to return & white & tab & return & white
& "}"
select insertion point after line (lineNum + 1)
return
end if
end if
-- Check for code block : (Python)
if (leng - wleng) ≥ 1 then
if (character -1 of line lineNum as string) is equal to ":" then
set selection to return & white & tab
select insertion point after line (lineNum + 1)
return
end if
end if
-- Default: Insert a return plus the white space
set selection to return & white
select insertion point after selection
end tell
-----------------------------
(*
Author: Kendall Conrad of Angelwatt.com
Name: OpenLineUp
Created: 2010-01-18
Description: Creates a new line above the line currently on at
appropriate indent level
*)
tell application "BBEdit" to tell front window
activate
set lineNum to startLine of selection
set leng to length of line lineNum
-- Move cursor to start of line
if leng > 0 then
select insertion point before (character 1 of line lineNum)
end if
-- Find leading whitespace
set theResult to find "(^[\\s]*)" options {search mode:grep}
searching in line (lineNum)
-- Set text to the white space found
set white to ""
if found of theResult then
set white to found text of theResult
end if
-- Insert a return plus the white space
set selection to white & return
select insertion point before (character -1 of selection)
end tell
On Apr 11, 2:24 pm, Robert Rollins <[email protected]> wrote:
> Hi all! I recently started checking out BBEdit as an alternative
> development platform to Eclipse and TextMate, and so far I like it a
> lot. But there's one thing I'm really missing: syntax aware ("smart")
> auto-indent.
>
> 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.
>
> Is there any way, via an addon to BBEdit, or other such device, to
> make auto-indent more syntax aware?
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>