Select paragraph without whitespace

113 views
Skip to first unread message

oliver

unread,
Aug 7, 2011, 9:34:19 PM8/7/11
to BBEdit Talk
When in Soft Wrap mode is there any difference between Select Line and
Select Paragraph?

I'm interested in selecting an indented paragraph of text (in Soft
Wrap mode) without selecting the leading whitespace and the newline at
the end. Is this possible?

Christopher Stone

unread,
Aug 8, 2011, 1:00:03 AM8/8/11
to bbe...@googlegroups.com
Hey Oliver,

On Aug 07, 2011, at 20:34, oliver wrote:
When in Soft Wrap mode is there any difference between Select Line and Select Paragraph?

Yes.  Select Paragraph will select hard wrapped text between the whitespace.
I'm interested in selecting an indented paragraph of text (in Soft Wrap mode) without selecting the leading whitespace and the newline at the end. Is this possible?

Hmm.  Okay.  If I understand correctly you've got soft-wrapped text with an intent.  I'm assuming a tab for the indent, but that can be altered of course.

This will work if the line is indented and terminated with a linefeed (return *) and if the indented line is the last line in the document with no trailing LF.

The cursor can be anywhere in the line - beginning, anywhere inside, end.

In the event that you fire off the script in a non-indented line the cursor is returned to its original position.

--
Best Regards,
Chris


* Return characters are of course not equal to linefeeds, but this is the eol representation BBEdit uses.

______________________________________________________________________


tell application "BBEdit"
  try
    tell text of front text window
      set originalOffset to characterOffset of selection
      # properties of selection
      select line (startLine of selection)
      tell selection
        if its contents starts with tab then
          set newCharacterOffset to characterOffset + 1
          if its contents ends with return then
            set newLength to (characterOffset + (its length)) - 2
          else
            set newLength to (characterOffset + (its length)) - 1
          end if
          tell text of front text window of application "BBEdit"
            select (characters newCharacterOffset thru newLength)
          end tell
        else
          tell text of front text window of application "BBEdit"
            select insertion point before character originalOffset
          end tell
        end if
      end tell
    end tell
  on error errMsg number errNum
    set sep to "=============================="
    set e to sep & return & "Error: " & errMsg & return & sep & return ¬
      & "Error Number: " & errNum & return & sep
    beep
    display dialog e
  end try
end tell

oliver

unread,
Aug 8, 2011, 3:04:55 AM8/8/11
to BBEdit Talk
Wow. Ninja skills. Thanks.

I'd love to have this work with any level of indentation, even none.
Is that even possible?

Something like: ^[ \t]*(.+)$

Christopher Stone

unread,
Aug 8, 2011, 4:00:37 PM8/8/11
to bbe...@googlegroups.com
On Aug 08, 2011, at 02:04, oliver wrote:
> I'd love to have this work with any level of indentation, even none. Is that even possible?
> Something like: ^[ \t]*(.+)$
______________________________________________________________________

Hey Oliver,

Done. :)

The non-greedy operator is not strictly necessary, but it picks the speed up just a trifle.

-ccs


tell application "BBEdit"
try
tell text of front text window

set lineOfInsertionPoint to line (startLine of selection)
set findReco to find "\\S+.+?$" searching in lineOfInsertionPoint ¬
options {search mode:grep} with selecting match

oliver

unread,
Aug 8, 2011, 4:09:53 PM8/8/11
to BBEdit Talk
On Aug 8, 1:00 pm, Christopher Stone <listmeis...@thestoneforge.com>
wrote:
> Hey Oliver,
>
> Done.  :)

You are my hero.
Reply all
Reply to author
Forward
0 new messages