Hello!
Your solutiion is best.
I actually resorted to groff, what I didn’t take into account, was the compiler wiping out the whitespace.
It would have looked like this really, but with totally straight edges. My solution is only good for my text editor,
one of the days I’ll write a groff filter for BBEdit!
The text I used for comparison was from the fine article about screen sizing by John Gruber at DaringFireball.net
http://daringfireball.net/2006/12/display_size_applescript_the_lazy_way
Yours
-- The tricky part in writing a script to do this is
-- determining the height of the screen. (Or the width, for
-- that matter, if I wanted to do something to make sure all
-- the windows fit on screen, no matter how many there are.) I
-- wasn't aware of any way to obtain the size of the screen
-- using AppleScript. I could hard code a size into the
-- script, but the main reason I wanted to write the script in
-- the first place is that I switch between my 20-inch Cinema
-- Display and the built-in display of my 15-inch PowerBook,
-- which (the switching) can leave browser windows in weird
-- sizes. I want the same script to work with both displays.
Mine
(*
The tricky part in writing a script to do this is determining the
height of the screen. (Or the width, for that matter, if I wanted
to do something to make sure all the windows fit on screen, no
matter how many there are.) I wasn't aware of any way to obtain
the size of the screen using AppleScript. I could hard code a
size into the script, but the main reason I wanted to write the
script in the first place is that I switch between my 20inch
Cinema Display and the builtin display of my 15inch PowerBook,
which (the switching) can leave browser windows in weird sizes. I
want the same script to work with both displays.
*)
This is what I used, and the other problem, is that it seems like groff only handles 7 bit ascii, I may be wrong in that assumption, but, it really seems so, or there is some other oddity, that I have no time for at the moment. (yes, I have had a go with iconv trying to fix it, maybe it is windows latin that is the cure.
You should however try to paste the output of my script into your regular text editor (the script below this.)
Comment Formatter/Reformatter
set the clipboard to «class ktxt» of ((the clipboard as string) as record)
set the clipboard to "(*\n" & (do shell script ("pbpaste |tr \"'\" \"'\" |tr -d '#' |sed -E 's/[-][-]//g' |iconv -f utf-8 -t latin1 |groff -c -i -s -T utf8 |tr \"'\" \"'\" |grep -E [:print:]\\+")) & "\n*)"
Edit I have been back fixing my solution a little, it is of course of no use for formatting AppleScript, it was just for the hell of it, but now I believe it handles unicode as well, when the dreaded back tick is filtered away. Your solution is still the right one and it is not about winning, not for my part, just saying. So I’ll end up using your script I think, while mine is a great formatter for pure text.
I got some ideas during messing with this, (quite fun!) so now my script for formatting comments can reformat them, after I have edited them!
Here it is, slightly revamped, as a text formatter, that doesn’t accept lines starting with #`s! they are interpreted as comments! That means you really can’t reformat Markdown with this either.
Standard Text Formatter
set the clipboard to «class ktxt» of ((the clipboard as string) as record)
set the clipboard to (do shell script ("pbpaste |tr \"'\" \"'\" |tr -d '#' |iconv -f utf-8 -t latin1 |groff -c -i -s -T utf8 |tr \"'\" \"'\" |grep -E [:print:]\\+"))
Final Words
I can actually reformat comments, where they given in my format for starters, so I have gone back, and added even a sed command, so that I can reformat comments already in applescript as well, taking any kind of comment, whether they start with “#” or “””, assuming you leave “(*” and “*)” above and below the comments, that shouldn’t be too hard.
End of Story
It should work properly now.