From: dorayme on
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
From: dorayme on
In article
<timstreater-7483A9.10470711082010(a)news.individual.net>,
Tim Streater <timstreater(a)waitrose.com> wrote:

> In article <dorayme-9BFA13.12025611082010(a)news.albasani.net>,
> dorayme <dorayme(a)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
From: dorayme on
In article
<timstreater-976C18.13312411082010(a)news.individual.net>,
Tim Streater <timstreater(a)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
From: dorayme on
In article <attilaj-E7D8D1.22484512082010(a)5ad64b5e.bb.sky.com>,
Attila Jozsef <attilaj(a)poetry.szeged.edu.hu.invalid> wrote:

> In article <dorayme-9BFA13.12025611082010(a)news.albasani.net>,
> dorayme <dorayme(a)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