What is TextMate's equivalent to BBEdit's 'Add Line Breaks'
Example: - TextMate Soft Wrap set to 66 characters - How do I Hard Wrap my document at 66 columns? Reformat Paragraph works, if I just want to reformat a few paragraphs, but I'm hoping there is a TextMate command that can be applied to the entire document and that won't reformat lines separated by a single return.
On 20/11/2007, Frank Eves gold_eagle@mac.com wrote:
- TextMate Soft Wrap set to 66 characters
- How do I Hard Wrap my document at 66 columns?
As far as I know, TextMate doesn't have a built-in command to do this. You can use Text > Filter Through Command… to run some external formatter of your choice. Unfortunately the BSD version of fmt included with OS X can't quite be made to do the right thing, though you may find it good enough for your purposes. (The problem is that it insists on removing linebreaks as well as adding new ones. The GNU version is better since it has an option that prevents it from doing that; you could always install it, assuming you know how to work a C compiler and so on.)
This question comes up fairly regularly, and I remember there have been some good suggestions made in the past, though I don't remember precisely what they were. You could try searching the archives of this list.
Robin
On 20 Nov 2007, at 22:33, Robin Houston wrote:
On 20/11/2007, Frank Eves gold_eagle@mac.com wrote:
- TextMate Soft Wrap set to 66 characters
- How do I Hard Wrap my document at 66 columns?
As far as I know, TextMate doesn't have a built-in command to do this. You can use Text > Filter Through Command… to run some external formatter of your choice. Unfortunately the BSD version of fmt included with OS X can't quite be made to do the right thing [...]
fold -sw66 though should do exactly what Frank wants. Or to make it actually use his soft wrap setting: fold -sw$TM_COLUMNS
On Nov 20, 2007, at 2:37 PM, Allan Odgaard wrote:
to make it actually use his soft wrap setting: fold -sw$TM_COLUMNS
After applying 'Soft Wrap' to a simple text document, I asked if there was a TextMate command to add line breaks to the end of every line.
Allan Odgaard suggested the following command fold -sw$TM_COLUMNS
which delivers precisely the results I hoped for. My thanks to Allan, Robin and others for their help.
On 20/11/2007, Allan Odgaard throw-away-2@macromates.com wrote:
fold -sw66 though should do exactly what Frank wants. Or to make it actually use his soft wrap setting: fold -sw$TM_COLUMNS
*blush* I forgot about fold. •_•
Robin
- TextMate Soft Wrap set to 66 characters
- How do I Hard Wrap my document at 66 columns?
Reformat Paragraph works, if I just want to reformat a few paragraphs, but I'm hoping there is a TextMate command that can be applied to the entire document and that won't reformat lines separated by a single return.
Does selecting the entire document before Reformatting Selection work?
On Nov 20, 2007, at 1:51 PM, Alex Ross wrote:
Does selecting the entire document before Reformatting Selection work?
Unfortunately, lists with single line breaks are then converted into a paragraph. Reformatting paragraph by paragraph and skipping lists is time consuming. I can, of course, continue to do this with a single click in BBEdit, I had hoped that TextMate might offer an option that I'd missed.
If you don't need to worry about dealing properly with (hard) tabs, then you can easily write a short command to do the reformatting.
Set input to "Entire Document", output to "Replace Document", and put the code
#!/usr/bin/perl -p print "$1\n" while s/(\S{$ENV{TM_COLUMNS}})//; print "$1\n" while s/(.{0,$ENV{TM_COLUMNS}})\s//;
into the Command(s) box. This will treat a tab as though it took up a single column, so if you have a lot of tab indents then it will leave excessively long lines. Writing something that deals properly with tabs would be a bit harder, but very possible.
(I bet somebody has already done it too!)
Robin