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!