Formatting javascript in BBEdit or Textwrangler

  • Follow


What is best thing to do or get to format javascript code in 
BBEdit (8.2.6), Tidy formats the HTML (meaning basically 
indenting and making block elements easier to read). What would 
do the same for a bunch of javascript code? Or, for that matter 
CSS - my Tidy, leaves the CSS alone?

-- 
dorayme
0
Reply dorayme 8/11/2010 2:02:57 AM

In article <dorayme-9BFA13.12025611082010@news.albasani.net>,
 dorayme <dorayme@optusnet.com.au> wrote:

> What is best thing to do or get to format javascript code in 
> BBEdit (8.2.6), Tidy formats the HTML (meaning basically 
> indenting and making block elements easier to read). What would 
> do the same for a bunch of javascript code? Or, for that matter 
> CSS - my Tidy, leaves the CSS alone?

I format JS by hand in TW. I've set the tab key to auto-expand to 5 
spaces, but that's about all.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689
0
Reply Tim 8/11/2010 9:47:07 AM


In article 
<timstreater-7483A9.10470711082010@news.individual.net>,
 Tim Streater <timstreater@waitrose.com> wrote:

> In article <dorayme-9BFA13.12025611082010@news.albasani.net>,
>  dorayme <dorayme@optusnet.com.au> wrote:
> 
> > What is best thing to do or get to format javascript code in 
> > BBEdit (8.2.6), Tidy formats the HTML (meaning basically 
> > indenting and making block elements easier to read). What would 
> > do the same for a bunch of javascript code? Or, for that matter 
> > CSS - my Tidy, leaves the CSS alone?
> 
> I format JS by hand in TW. I've set the tab key to auto-expand to 5 
> spaces, but that's about all.

Yes, fair enough but I am thinking, there must be a better way. 
You know, we are higher beings than most other animals. I saw a 
lion the other day writing some js and said to him, hey, lemme 
look and he said just a mo and he pressed a couple of things and 
showed me, it was beautifully formatted. I was about to ask him 
how he did that but thought it is really silly trying to talk to 
a lion.

I bet *latest* BBEdit has things but I am loathe to spend money, 
it is not something I do easily. (Shop keepers are always saying 
"Let go!" when I am paying with a big note. Maybe I need to take 
valium to relax the muscles for shopping?)

-- 
dorayme
0
Reply dorayme 8/11/2010 10:07:58 AM

In article <dorayme-3BD4A3.20075811082010@news.albasani.net>,
 dorayme <dorayme@optusnet.com.au> wrote:

> In article 
> <timstreater-7483A9.10470711082010@news.individual.net>,
>  Tim Streater <timstreater@waitrose.com> wrote:
> 
> > In article <dorayme-9BFA13.12025611082010@news.albasani.net>,
> >  dorayme <dorayme@optusnet.com.au> wrote:
> > 
> > > What is best thing to do or get to format javascript code in 
> > > BBEdit (8.2.6), Tidy formats the HTML (meaning basically 
> > > indenting and making block elements easier to read). What would 
> > > do the same for a bunch of javascript code? Or, for that matter 
> > > CSS - my Tidy, leaves the CSS alone?
> > 
> > I format JS by hand in TW. I've set the tab key to auto-expand to 5 
> > spaces, but that's about all.
> 
> Yes, fair enough but I am thinking, there must be a better way. 
> You know, we are higher beings than most other animals. I saw a 
> lion the other day writing some js and said to him, hey, lemme 
> look and he said just a mo and he pressed a couple of things and 
> showed me, it was beautifully formatted. I was about to ask him 
> how he did that but thought it is really silly trying to talk to 
> a lion.

*My* JS is inherently beautifully formatted snoot snoot.

> I bet *latest* BBEdit has things but I am loathe to spend money, 
> it is not something I do easily. (Shop keepers are always saying 
> "Let go!" when I am paying with a big note. Maybe I need to take 
> valium to relax the muscles for shopping?)

Much better you give me the big notes. Just open your purse and repeat 
after me "Help yourself".

Meanwhile, back at the farm, what is wrong with your JS that you need to 
have it formatted. Or are you referring to other people's JS that looks 
like it might be useful and you want to make it readable?

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689
0
Reply Tim 8/11/2010 12:31:24 PM

In article 
<timstreater-976C18.13312411082010@news.individual.net>,
 Tim Streater <timstreater@waitrose.com> wrote:

> Meanwhile, back at the farm, what is wrong with your JS that you need to 
> have it formatted. Or are you referring to other people's JS that looks 
> like it might be useful and you want to make it readable?

Have a look at what Tidy can do by way of reflowing an HTML doc 
(nothing to do with validating or closing unclosed elements or 
supplying missing and sloppily forgotten tags etc) and now apply 
the analogy to javascript and you should be seeing what I want. 

Perhaps all this is quite unfathomable to you because you are a 
careful and thoughtful typist and a in-real-time-thinker of all 
the relevant things wanted for any task. Me, I am wildly 
imperfect and type away and revise stuff. If I see an extra rule 
I need for CSS, I might not bother to make a space for it on a 
new line but plonk it straight after a semi-colon on the same 
line as an existing rule. I might type table elements without 
bothering to hit return (its quicker!). Later, I will tidy it up.

One of the things I have help in revising is reflowing HTML 
markup (with the handy Tidy) to make it more easily read by 
others and by me (especially months or years later). I am 
wondering if there is a facility to do the same for JS and CSS. 
(especially interested in if there would be any plugin or way to 
do it in my BBEdit)

-- 
dorayme
0
Reply dorayme 8/11/2010 10:15:05 PM

In article <dorayme-AB79CD.08150512082010@news.albasani.net>,
 dorayme <dorayme@optusnet.com.au> wrote:

> In article 
> <timstreater-976C18.13312411082010@news.individual.net>,
>  Tim Streater <timstreater@waitrose.com> wrote:
> 
> > Meanwhile, back at the farm, what is wrong with your JS that you need to 
> > have it formatted. Or are you referring to other people's JS that looks 
> > like it might be useful and you want to make it readable?
> 
> Have a look at what Tidy can do by way of reflowing an HTML doc 
> (nothing to do with validating or closing unclosed elements or 
> supplying missing and sloppily forgotten tags etc) and now apply 
> the analogy to javascript and you should be seeing what I want. 
> 
> Perhaps all this is quite unfathomable to you because you are a 
> careful and thoughtful typist and a in-real-time-thinker of all 
> the relevant things wanted for any task. Me, I am wildly 
> imperfect and type away and revise stuff. If I see an extra rule 
> I need for CSS, I might not bother to make a space for it on a 
> new line but plonk it straight after a semi-colon on the same 
> line as an existing rule. I might type table elements without 
> bothering to hit return (its quicker!). Later, I will tidy it up.

Ah, you must be a wild young thing fortunate enough to have come to 
consciousness at a time when text editing is easy. I, on the other hand, 
will officially become a doddering old fossil in less than a year.

in 1970, I was given the task of writing a histogram package. It needed 
to be in assembler (for speed, as I recall) and of course it was all 
punched cards at that stage. Once it became large, I transferred it to 
mag tape and used a program a colleague had developed to make changes to 
it (deleting card ranges or inserting them). But, because I'd gone at 
the project in a somewhat gung-ho manner, it was a complete mess of 
jumps back and forth, into and out of loops - no structure at all. And 
it didn't work.

In somewhat of a panic I sat down and *carefully* redesigned/rewrote it 
from scratch, and after a few mammoth editing sessions with tapes 
spinning back and forth, had something that not only worked, but 
coincidentally followed the norms of any modern structured programming 
language (at the time, on the machine in question, it was FORTRAN or 
assembler. We got BCPL a few years later).

So if I write "neat and tidy" code straight off, it's mere self-defence.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689
0
Reply Tim 8/12/2010 10:09:42 AM

In article <dorayme-9BFA13.12025611082010@news.albasani.net>,
 dorayme <dorayme@optusnet.com.au> wrote:

> What is best thing to do or get to format javascript code in 
> BBEdit (8.2.6), Tidy formats the HTML (meaning basically 
> indenting and making block elements easier to read). What would 
> do the same for a bunch of javascript code? Or, for that matter 
> CSS - my Tidy, leaves the CSS alone?

I found this, from a few years ago:

<http://attaboy.tumblr.com/post/20570385/beautify-your-javascript-in-bbed
it>

The page has a big chunk of PHP code which can be run as a shell script 
from BBEdit #! > Unix Scripts >

Here's their description:

"BBEdit has nice tools built-in for formatting HTML and CSS into nice, 
hierarchically-indented blocks. It doesn�t do JavaScript though, which I 
often lament when I�m copying and pasting other people�s source code (or 
just my own lazily-written code)."

"Enter the JavaScript beautifier written by Einars �elfz� Lielmanis. It 
works very well. But I�m lazy, and I don�t want to visit a web site 
every time I want to format some code. I want to press a shortcut key 
and have some highlighted code be instantly formatted. elfz has 
thoughtfully made the source code available, so the question is: how do 
you get BBEdit to talk to PHP?"

"Luckily, OS X can run PHP as a shell script language. With a couple of 
extra lines of code tacked on the end, I was able to turn elfz�s script 
into a BBEdit-friendly �filter� which I can pass JavaScript through."

The full PHP source is there and the script framework to pass the 
javascript through it. I have no personal experience with this, but I 
hope it helps.
0
Reply Attila 8/13/2010 2:48:45 AM

In article <attilaj-E7D8D1.22484512082010@5ad64b5e.bb.sky.com>,
 Attila Jozsef <attilaj@poetry.szeged.edu.hu.invalid> wrote:

> In article <dorayme-9BFA13.12025611082010@news.albasani.net>,
>  dorayme <dorayme@optusnet.com.au> wrote:
> 
> > What is best thing to do or get to format javascript code in 
> > BBEdit (8.2.6), Tidy formats the HTML (meaning basically 
> > indenting and making block elements easier to read). What would 
> > do the same for a bunch of javascript code? Or, for that matter 
> > CSS - my Tidy, leaves the CSS alone?
> 
> I found this, from a few years ago:
> 
> <http://attaboy.tumblr.com/post/20570385/beautify-your-javascript-in-bbed
> it>
> 
> The page has a big chunk of PHP code which can be run as a shell script 
> from BBEdit #! > Unix Scripts >
> 
> Here's their description:
> 
> "BBEdit has nice tools built-in for formatting HTML and CSS into nice, 
> hierarchically-indented blocks. It doesn’t do JavaScript though, which I 
> often lament when I’m copying and pasting other people’s source code (or 
> just my own lazily-written code)."
> 
> "Enter the JavaScript beautifier written by Einars “elfz” Lielmanis. It 
> works very well. But I’m lazy, and I don’t want to visit a web site 
> every time I want to format some code. I want to press a shortcut key 
> and have some highlighted code be instantly formatted. elfz has 
> thoughtfully made the source code available, so the question is: how do 
> you get BBEdit to talk to PHP?"
> 
> "Luckily, OS X can run PHP as a shell script language. With a couple of 
> extra lines of code tacked on the end, I was able to turn elfz’s script 
> into a BBEdit-friendly “filter” which I can pass JavaScript through."
> 
> The full PHP source is there and the script framework to pass the 
> javascript through it. I have no personal experience with this, but I 
> hope it helps.

Thanks a lot for this. I don't mind the online or an offline copy 
way of doing this but it would be so cool to have it as a filter 
in BBEDit. I have got as far as copying the php and making a file 
and putting it in library in the Unix Scripts as said. No sure 
what to call it! .php? Or how to quite access and use it but I 
will think some more...

Thanks again, this might save me from making a sort of facility 
of my own with the GREP Find and Replace function.

-- 
dorayme
0
Reply dorayme 8/13/2010 10:06:59 AM

In article <attilaj-E7D8D1.22484512082010@5ad64b5e.bb.sky.com>,
 Attila Jozsef <attilaj@poetry.szeged.edu.hu.invalid> wrote:

> In article <dorayme-9BFA13.12025611082010@news.albasani.net>,
>  dorayme <dorayme@optusnet.com.au> wrote:
> 
> > What is best thing to do or get to format javascript code in 
> > BBEdit (8.2.6), Tidy formats the HTML (meaning basically 
> > indenting and making block elements easier to read). What would 
> > do the same for a bunch of javascript code? Or, for that matter 
> > CSS - my Tidy, leaves the CSS alone?
> 
> I found this, from a few years ago:
> 
> <http://attaboy.tumblr.com/post/20570385/beautify-your-javascript-in-bbed
> it>

Thanks again, it was easy once I paid attention. (Sunday today, 
more time!) I now have it as a filter with a key command.

-- 
dorayme
0
Reply dorayme 8/15/2010 4:21:47 AM

8 Replies
1812 Views

(page loaded in 0.13 seconds)

Similiar Articles:









7/21/2012 5:56:14 AM


Reply: