Wrapping text in symbols or tags

306 views
Skip to first unread message

Adrian Manea

unread,
Aug 6, 2016, 11:01:35 AM8/6/16
to BBEdit Talk
One of the main things I miss from Sublime Text is the ability to wrap selected text in symbols/markers or tags. I used this largely for Markdown and LaTeX, the main "languages" I write in. So it goes like this: you have some text which you want to italicize, say, select it and press * once and Sublime wraps the text in asterisks. It seems to recognize most symbols that are common for the language, since it works with all sorts of brackets or specific symbols and even some LaTeX environment tags.

As I understand it, the only way to do this in BBEdit is to create a clipping based around #SELECTIONORINSERTION#. So basically if I want to wrap a text in, say, \textbf{...}, I have to create a specific clipping to say \textbf{#SELECTIONORINSERTION#}.

This is largely inconvenient, because I have to create a clipping for each and every usage I'll ever have. For Markdown, I'd be OK with single or double asterisks for bold/italic, but for LaTeX, there are a lot of environments or commands which I'd need... Admittedly, I can setup one clipping for wrapping in curly braces, then write the appropriate command, but still, it's not very comfortable. And setting up keyboard shortcuts for each and every one of them is equally cumbersome.

Are there alternatives? Or do I really have to create a clipping for each symbol or marker which I'll ever use for wrapping text in it? I understand and value clippings for more generous snippets, but for wrapping text in symbols, I'd say it's overly complicated.

Thank you.

P.S. I don't want to sound like I'm bashing BBEdit or its workflow! Quite the contrary, in fact, I love it. But as I'm trying to get a better command of it, I'd say it's natural for questions and frustrations to arise. :)

Adrian Manea

unread,
Aug 6, 2016, 1:39:13 PM8/6/16
to BBEdit Talk
LE: I've seen this post: http://www.macdrifter.com/2012/01/moving-text-editors-taking-bbedit-seriously.html, wherefrom I've drawn some inspiration. But really, using Keyboard Maestro or similar software is not that comfortable. Are there any "native" alternatives?

Christopher Stone

unread,
Aug 6, 2016, 6:26:32 PM8/6/16
to BBEdit-Talk
On Aug 06, 2016, at 10:01, Adrian Manea <adrian....@gmail.com> wrote:
One of the main things I miss from Sublime Text is the ability to wrap selected text in symbols/markers or tags.


Hey Adrian,

BBEdit is scriptable, which means you can add features to suit yourself.

This very basic AppleScript will wrap the selected text in whatever text you provide in the dialog.

It can be tremendously customized.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2016/08/06 17:00
# dMod: 2016/08/06 17:10 
# Appl: BBEdit
# Task: Wrap Selected Text in the User-Provided Text.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Wrap, @Selection
-------------------------------------------------------------------------------------------

try

   

   tell application "BBEdit"
      tell text of front text document
         set selectedText to contents of selection
      end tell
   end tell

   

   set wrapperText to text returned of (display dialog "Enter Wrapper Text" with title "Edit Selection" default answer "")

   

   tell application "BBEdit"
      tell text of front text document
         set text of selection to wrapperText & selectedText & wrapperText
      end tell
   end tell

   

on error e number n
   set e to e & return & return & "Num: " & n
   if n ≠ -128 then
      try
         tell application (path to frontmost application as text) to set ddButton to button returned of ¬
            (display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to e
      end try
   end if
end try

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


Adrian Manea

unread,
Aug 7, 2016, 12:32:01 AM8/7/16
to BBEdit Talk, listm...@suddenlink.net
Hi Chris,

Thank you for the reply and the script. It is very useful, indeed. Now I setup a unique keyboard shortcut for the script and choose the wrappers, I got it.

Thanks again,
Adrian
Reply all
Reply to author
Forward
0 new messages