Can BBEdit format code like it formats HTML?

331 views
Skip to first unread message

James Reynolds

unread,
Sep 18, 2020, 1:49:06 PM9/18/20
to bbe...@googlegroups.com
I know BBEdit has an HTML formatter. Can it also format code? Like what https://beautifier.io/ does for JavaScript?

James Reynolds
Sr Systems Administrator
School of Biological Sciences
The University of Utah
801-585-3086

Steve deRosier

unread,
Sep 18, 2020, 2:15:57 PM9/18/20
to bbedit
Well, it does automatically handle indentation depending on your settings, and you can setup clippings if that's your jam. It also does a lot of coloring, especially nice when setup via ctags.

For more hardcore reformatting, you can always setup to trigger external commands, like `astyle` for C/C++/Java, or one of the many python PEP8 formatters.  The flexibility in this regard is one of the things I like about BBEdit. Though personally I usually restrict such options to doing manually on the commandline; for python projects I use pylint triggered from a Makefile to enforce style guidelines that I choose to enable.

I also like the fact it doesn't autoformat for me... in other words it doesn't get in my way or overrule me. Since for any given project I'm working with 3-8 different languages, it staying out of my way and only helping in the ways I want is critical. I also wouldn't ever want an editor take in a project file and just reformat it for me because that breaks revision control history for zero useful purpose; I've had IDEs do this to me and dropped them immediately because of it.

Hope that helps!
- Steve


--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://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 bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/0F089104-5A7A-4BE0-A750-5B7965AE443B%40gmail.com.

Rick Yentzer

unread,
Sep 19, 2020, 1:14:44 PM9/19/20
to BBEdit Talk

Hey James,

BBEdit formats only html and css to the best of my knowledge. Like Steve, I have used command line utilities if I needed additional formatting for other languages. I mostly work with web languages and python/php and have my build tools set to format if needed. Hope that helps.

Charlie Garrison

unread,
Sep 20, 2020, 7:44:03 PM9/20/20
to bbe...@googlegroups.com

On 19 Sep 2020, at 3:48, James Reynolds wrote:

I know BBEdit has an HTML formatter. Can it also format code? Like what https://beautifier.io/ does for JavaScript?

BBEdit has fantastic support for Text Filters. So if your formatter of choice works via CLI, writing a formatter (prettifier) is fairly trivial.

I have attached the filter script I use, which auto-detects language and applies appropriate command. It should be easy to swap out prettier for beautifier.

I set a keyboard shortcut for the filter, so it's as simple to use as the built-in formatting - select the text to format, type shortcut. (No selection will format the whole document.)

-cng

--

Charlie Garrison                   <cha...@garrison.com.au>
Garrison Computer Services      <http://www.garrison.com.au>
PO Box 380
Tumbarumba NSW 2653  Australia
16)prettier.sh

TJ Luoma

unread,
Sep 20, 2020, 7:58:00 PM9/20/20
to BBEdit MailingList
On Sun, Sep 20, 2020 at 7:44 PM Charlie Garrison <charlie...@garrison.com.au> wrote:

> BBEdit has fantastic support for Text Filters. So if your formatter of choice works via CLI, writing
> a formatter (prettifier) is fairly trivial.


I'm not very familiar with these. Are there any out there which format bash / zsh shell scripts?

 

Charlie Garrison

unread,
Sep 20, 2020, 8:29:12 PM9/20/20
to BBEdit MailingList

On 21 Sep 2020, at 9:57, TJ Luoma wrote:

I'm not very familiar with these. Are there any out there which format bash / zsh shell scripts?

I haven't looked. If there are I'm sure an online search will reveal them. Common terms are "tidy", "prettify" & "beautify".

Rick Yentzer

unread,
Sep 20, 2020, 8:39:46 PM9/20/20
to BBEdit Talk
Thanks for the file Charlie. That is really helpful and I will be adding it to my own workflow.

James Reynolds

unread,
Sep 21, 2020, 6:30:18 PM9/21/20
to bbe...@googlegroups.com
Charlie,
This is exactly what I was hoping for. Thank you!

James
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://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 bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/852FB848-89F7-4E5C-9872-1C361ECAEEAA%40garrison.com.au.
> <16)prettier.sh>

isao

unread,
Dec 1, 2020, 6:31:49 PM12/1/20
to BBEdit Talk
That's nice Charlie-- I didn't realize prettier fixed other things like JSON too.


It will fix and/or report lint issues. Added JSON just now after seeing your script.

Charlie Garrison

unread,
Dec 1, 2020, 6:42:52 PM12/1/20
to BBEdit Talk

On 2 Dec 2020, at 10:30, isao wrote:

Here's my BBEdit shell script https://github.com/isao/shell/blob/master/bbedit/Scripts/lint.sh

Nice.

I just came across tidyall this morning:

https://metacpan.org/pod/distribution/Code-TidyAll/bin/tidyall

I may rewrite my BBEdit text filter to use that, since it may be easier to enable "plugins" than to adapt the filter script for each new formatter I need.

Reply all
Reply to author
Forward
0 new messages