Hello,
is there any script to insert hard breaks where TM makes a soft wrap?
Bye?
On Sun, 15 Apr 2007, Robert W. Kuhn wrote:
Allan Odgaard:
On 13. Apr 2007, at 08:34, Robert W. Kuhn wrote:
is there any script to insert hard breaks where TM makes a soft wrap?
Text → Reformat Paragraph.
Or you can pipe the paragraph through: fold -sw$TM_COLUMNS
A related question: Is there a way to get TextMate to do this automatically? That is, whenever a soft wrap would occur when I'm typing, insert a newline instead of just wrapping the display? Yeah, I can do it manually, but for any document more than about five paragraphs I'll forget at least once. I can't just pipe the whole doc to an external fold command because often I have tables or other markup that I don't want reformatted.
On 16. Apr 2007, at 15:33, Steve King wrote:
[...] A related question: Is there a way to get TextMate to do this automatically? [...]
Hard wrap is not a built-in feature. You can fake it by overloading space with a macro that reflows the current paragraph, maybe conditionally only when TM_COLUMN_NUMBER is above 80 (i.e. use a command instead -- there is a scope for paragraphs in text, making it possible to have the command take meta.paragraph as input).
Allan Odgaard:
On 16. Apr 2007, at 15:33, Steve King wrote:
[...] A related question: Is there a way to get TextMate to do this automatically? [...]
Hard wrap is not a built-in feature. You can fake it by overloading space with a macro that reflows the current paragraph, maybe conditionally only when TM_COLUMN_NUMBER is above 80 (i.e. use a command instead -- there is a scope for paragraphs in text, making it possible to have the command take meta.paragraph as input).
..and do not forget to post the script ;-)
On Mon, 16 Apr 2007, Robert W. Kuhn wrote:
Allan Odgaard:
Hard wrap is not a built-in feature.
Will it be in 2.0? Pretty please?
You can fake it by overloading space with a macro that reflows the current paragraph, maybe conditionally only when TM_COLUMN_NUMBER is above 80 (i.e. use a command instead -- there is a scope for paragraphs in text, making it possible to have the command take meta.paragraph as input).
..and do not forget to post the script ;-)
You can't really do it with a macro. I tried making a macro that inserts a space then reformats the paragraph. This doesn't work if the cursor's at the end of a line (as it will be probably 95% of the time when this macro is triggered) because the reformat function deletes trailing whitespace. So the paragraph gets reformatted, but you lose the space you just inserted!
So I tried reversing the operations. I made a macro that reformats the paragraph, then inserts the space. That's better, but not perfect. Say you're wrapping at column 80. You end a word exactly at column 80 and type a space. The reformat occurs, but of course the line doesn't change (since it hasn't gone beyond the wrap margin). Then a space is entered, and you start typing the next word. This word is now hanging off the right-hand side of the screen in columns 81+. But all will be right again after you finish the word and hit space, right? Well, yeah, unless the word is the last one in the paragraph and you end it with a newline.
This method also fails in that you can't add multiple spaces at the end of a line. Reformat, add a space. Reformat again. The space you just added is eaten. Add a space. Net result: No change.
Entering multiple spaces within a line is even worse. The reformatter merges multiple spaces into a single space anywhere within the paragraph. This leads to the reformatter shifting the paragraph around, but the cursor doesn't move. It stays in the same column, regardless of how the words move around it. So you've got a double-space somewhere, and the cursor is just to the left of a word. Hit space. The reformatter removes the double-space, shifting the line one character to the left. Now your cursor is just *after* the first character of the word, not just before it. Insert a space. You've just turned 'word' into 'w ord'.
(And if you're old enough to have learned to type on a manual typewriter, the habit of adding two spaces at the end of a sentence is just too deeply ingrained to change. As you can see in the above paragraphs!)
You'd need to write a command to do this, and that's adding more overhead to the space character than I'm willing to do.
Allan, a question about that: When a command runs, does it spawn a new OS process or does it run in a thread within the TextMate process? It seems that if you're running any command that starts with a shebang (#!) line you'd have to fork a new process to load the specified command interpreter. If that's so, then it's *way* too much CPU and disk overhead to do every time you hit space!
On 4/16/07, Steve King steve@narbat.com wrote:
Allan, a question about that: When a command runs, does it spawn a new OS process or does it run in a thread within the TextMate process? It seems that if you're running any command that starts with a shebang (#!) line you'd have to fork a new process to load the specified command interpreter. If that's so, then it's *way* too much CPU and disk overhead to do every time you hit space!
I think you may be over-estimating the cost of forking. I just did a little test, and my G4 Powerbook can spawn and reap 90,000 processes per second. Your computer is probably faster than mine, and I wonder how many times you press space every second. :-)
Robin
On Mon, 16 Apr 2007, Robin Houston wrote:
I think you may be over-estimating the cost of forking. I just did a little test, and my G4 Powerbook can spawn and reap 90,000 processes per second. Your computer is probably faster than mine, and I wonder how many times you press space every second. :-)
I'm mostly concerned about the disk I/O needed to load up the command interpreter, plus the CPU time for the interpreter to initialize itself. My MacBook Pro is pretty disk-bound; I already get major slow-downs when I'm doing something disk-intensive. Sure, most of the time the interpreter is going to be in the disk cache, so no hit. But if I'm trying to edit a file while running a big compile job, well...
It seems to me that spawning a new process for (on average) one out of six keystrokes is excessive. Just sayin'. :-)
On 4/16/07, Steve King steve@narbat.com wrote:
I'm mostly concerned about the disk I/O needed to load up the command interpreter, plus the CPU time for the interpreter to initialize itself.
Yeah, that makes a massive difference. After I sent the message you quote, I tried timing vfork()+execve(), and it's more than 100x slower than vfork() alone. Not really surprising. I still think the staggering efficiency of Unix vfork() is one of the wonders of the computing world, but maybe that's not altogether relevant. :-)
All the same, you don't know it's going to be too slow until you've tried it and it is.
It seems to me that spawning a new process for (on average) one out of six
keystrokes is excessive. Just sayin'. :-)
Excessive ... in a good way? :-)
Robin
On 16. Apr 2007, at 21:07, Steve King wrote:
Hard wrap is not a built-in feature.
Will it be in 2.0? Pretty please?
I am aware of the request.
[...] Allan, a question about that: When a command runs, does it spawn a new OS process [...]
It does spawn a process, yes.
Allan Odgaard:
Or you can pipe the paragraph through: fold -sw$TM_COLUMNS
Is there any program (or script) that respects the quotation marks? It should a paragraph from
jlöjlkj löj k äöjkäö jäököälk öäkl öäkl äöklöäkl öäkl öäklöäklöäkläöklöäkl öäkl äöjk öäköäklöäkl jlöjlkj löj k äöjkäö jäököälk öäkl öäkl äöklöäkl öäkl öäklöäklöäkläöklöäkl öäkl äöjk öäköäklöäkl jlöjlkj löj k äöjkäö jäököälk öäkl öäkl äöklöäkl öäkl öäklöäklöäkläöklöäkl öäkl äöjk öäköäklöäkl
to
jlöjlkj löj k äöjkäö jäököälk öäkl öäkl äöklöäkl öäkl öäklöäklöäkläöklöäkl öäkl äöjk öäköäklöäkl jlöjlkj löj k äöjkäö jäököälk öäkl öäkl äöklöäkl öäkl öäklöäklöäkläöklöäkl öäkl äöjk öäköäklöäkl jlöjlkj löj k äöjkäö jäököälk öäkl öäkl äöklöäkl öäkl öäklöäklöäkläöklöäkl öäkl äöjk öäköäklöäkl
Allan Odgaard throw-away-1@macromates.com wrote:
On 18. Apr 2007, at 17:03, Robert W. Kuhn wrote:
Allan Odgaard:
Or you can pipe the paragraph through: fold -sw$TM_COLUMNS
Is there any program (or script) that respects the quotation marks? It should a paragraph from
Quotation marks? What do you mean?
Sorry, bad english. I mean citation marks ('>')?!
And http://www.nicemice.net/par/ does the job.
On 18. Apr 2007, at 18:33, rowkajjh wrote:
Allan Odgaard throw-away-1@macromates.com wrote:
On 18. Apr 2007, at 17:03, Robert W. Kuhn wrote:
Allan Odgaard:
Or you can pipe the paragraph through: fold -sw$TM_COLUMNS
Is there any program (or script) that respects the quotation marks? It should a paragraph from
Quotation marks? What do you mean?
Sorry, bad english. I mean citation marks ('>')?!
And http://www.nicemice.net/par/ does the job.
Ah, we have ⌃Q call par when the scope is markup.quote — so granted you have selected a language grammar that marks up quoted text (like Markdown or the Mail grammar) then ⌃Q should do the right thing :)
The command is btw in the Mail bundle.
On 4/18/07, Robert W. Kuhn 2006@ku.hn wrote:
Is there any program (or script) that respects the quotation marks?
Vim does. I don't know an easy way to pipe through vim, but here's a difficult way:
vim -c 'set tw='$TM_COLUMNS - >/dev/null 2<<<'gqG:%!cat >'>(cat >&2)
Pipe the text through that, and it does what you want, I think.
Robin
On 4/13/07, Robert W. Kuhn 2006@ku.hn wrote:
Hello,
is there any script to insert hard breaks where TM makes a soft wrap?
A more interesting question is, is there any way to make TextMate wrap on a column that is _not_ the one where soft-wrapping occurs? What if I want to type away madly in a nice, spacious window, but then wrap to 80 characters for someone on a legacy terminal?
How about something like emacs' auto-fill-mode? With configurable width?
On 16. Apr 2007, at 15:48, Chris Rose wrote:
[...] A more interesting question is, is there any way to make TextMate wrap on a column that is _not_ the one where soft-wrapping occurs? What if I want to type away madly in a nice, spacious window, but then wrap to 80 characters for someone on a legacy terminal?
Move caret to column 80, now use ⇧⌘← to select to the beginning of the line. Press ⌥ once to switch to column selection and then do the ⌃Q to reflow — with a column selection, it will reflow the paragraph to be within the left/right edges of that selection, so this is also handy for indented paragraphs (e.g. after ⇧⌘← use ⇧→ a few times to give the paragraph some indent, or alternatively move the reflowed paragraphs around afterwards with ⌃⌘ + arrow keys).