Hey Folks,

Due to Vlad's recent request (and my own intention to get around to it 
eventually) I finally tackled this little task.

Repositioning the current line at top and bottom was quite simple with Keyboard 
Maestro.  I just used the the key-sequence (PgUp/PgDn)-Ctrl-A.

That did the job and was very fast but unfortunately didn't preserve the 
selection.

I then wrote the reposition-line-at-middle script based on where BBEdit puts 
the line when you reposition with AppleScript and an offset.

After that I played with the offsets and got scripts working for 
reposition-line-at-top and reposition-line-at-bottom.

The problem with this method is that it depends upon the window size being 
fixed, and you have to adjust the offset for your font-size and and 
window-height.

The error-handler is appended at the end and should be added to each saved 
script.

These work much faster when run from BBEdit's own Script Menu.

Hopefully there are others besides Vlad and myself who'll find them useful.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone <[email protected]>
# dCre: 2015/01/02 21:50
# dMod: 2015/01/02 21:59
# Appl: BBEdit
# Task: Reposition Current Line at Top.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Line, @Reposition 
-------------------------------------------------------------------------------------------

try
  
  set lineOffset to 14
  
  tell application "BBEdit"
    tell text of front text window
      set _sel to selection
      set selectLine to (startLine of _sel) + lineOffset
      select insertion point before line 1
      select line selectLine
      select _sel
    end tell
  end tell
  
on error e number n
  stdErr(e, n, true, true) of me
end try

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


-------------------------------------------------------------------------------------------
# Auth: Christopher Stone <[email protected]>
# dCre: 2015/01/02 21:50
# dMod: 2015/01/02 21:59
# Appl: BBEdit
# Task: Reposition Current Line at Middle.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Line, @Reposition 
-------------------------------------------------------------------------------------------

try
  
  set lineOffset to 14
  
  tell application "BBEdit"
    tell text of front text window
      set _sel to selection
      set selectLine to (startLine of _sel) - lineOffset
      select insertion point before line -1
      select line selectLine
      select _sel
    end tell
  end tell
  
on error e number n
  stdErr(e, n, true, true) of me
end try

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


-------------------------------------------------------------------------------------------
# Auth: Christopher Stone <[email protected]>
# dCre: 2015/01/02 21:50
# dMod: 2015/01/02 21:59
# Appl: BBEdit
# Task: Reposition Line at Bottom.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Line, @Reposition.
-------------------------------------------------------------------------------------------

try
  
  set lineOffset to 44
  
  tell application "BBEdit"
    tell text of front text window
      set _sel to selection
      set selectLine to (startLine of _sel) - lineOffset
      select insertion point before line -1
      select line selectLine
      select _sel
    end tell
  end tell
  
on error e number n
  stdErr(e, n, true, true) of me
end try

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


-------------------------------------------------------------------------------------------
--ยป HANDLERS
-------------------------------------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
  set e to e & return & return & "Num: " & n
  if beepFlag = true then
    beep
  end if
  if ddFlag = true then
    tell me
      set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", 
"Copy", "OK"} default button "OK"
    end tell
    if button returned of dDlg = "Copy" then set the clipboard to e
  else
    return e
  end if
end stdErr
-------------------------------------------------------------------------------------------

-- 
This is the BBEdit Talk public discussion group. 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>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to