Re: Indented comments

48 views
Skip to first unread message

Christopher Stone

unread,
Jun 16, 2012, 1:59:37 AM6/16/12
to bbe...@googlegroups.com
On Jun 15, 2012, at 08:55, Gingi wrote:
When I try to comment an indented block of code, BBEdit inserts the comment characters at the beginning of the line instead of at the indentation point. How do I change that behavior? I can't find any setting for controlling this anywhere.
______________________________________________________________________

Hey There,

There are a few expert settings (in the help) that affect comments, but I don't think any of them do what you want.  It's easy to script though:

tell application "BBEdit"
tell front text window's selection
replace "^([ \\t]*)(.+)" using "\\1// \\2" options {search mode:grep, case sensitive:false}
end tell
end tell

--
Best Regards,
Chris

Christopher Stone

unread,
Jun 18, 2012, 4:33:58 PM6/18/12
to bbe...@googlegroups.com
Hey Shiran,

On Jun 18, 2012, at 10:46, Gingi wrote:
That does the trick. I was just hoping there would be a way to set this universally.

File a feature request with support: sup...@barebones.com, and be sure to make your case.  A really well thought out argument is much more likely to be accepted than "I want this feature…".

I use several languages with different comment characters so scripting all of them can become a hassle.

No hassle.  Just allow for the different languages (see appended script).

Then again, I should get comfortable with BBEdit scripting.

Yes.  :)

You can't always make BBEdit do exactly what you want, but the possibility-pool grows exponentially.

Note: the script can be changed such that if there is no selection the current line becomes the target.  This kind of action is very flexible.

--
Best Regards,
Chris

------------------------------------------------------------------------------------------------
tell application "BBEdit"
  tell front text window

    

    set srcLang to source language

    

    if srcLang = "HTML" then
      set quoteStr to "<!--"
    else
      set quoteStr to "//"
    end if

    

    tell selection
      replace "^([ \\t]*)(.+)" using ("\\1" & quoteStr & " \\2") options {search mode:grep, case sensitive:false}
    end tell

    

  end tell
end tell
------------------------------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages