Hi,
is there a way to, when saving, to remove all trailing spaces and tabs from lines. I would like this when saving C++/C files.
Cheers, Fons.
On Tue, Mar 21, 2006 at 11:58:50AM +0100, Fons Rademakers wrote:
Hi,
is there a way to, when saving, to remove all trailing spaces and tabs from lines. I would like this when saving C++/C files.
Ditto for my ruby files. It's really annoying because I edit the same stuff using Vim when I'm not at my mac, and trailing spaces really break the "up / down paragraph" navigation.
-Dom
record a macro that replaces all "[ \t]*\n" with "\n" (regular expressions turned on) then saves the file, bind it to cmd+s and give it the scope "source".
'nuff said :)
domenico
Den 21. mar. 2006 kl. 14.12 skrev Domenico Carbotta:
record a macro that replaces all "[ \t]*\n" with "\n" (regular expressions turned on) then saves the file, bind it to cmd+s and give it the scope "source".
Never tried macro recording. Could you give a slightly more detailed explenation of this procedure, please? -- Mvh/Regards Geir-Tore Lindsve lindsve@bluezone.no http://www.lindsve.net
macroing for dummies ;) (no, I'm not saying you're dummy, it's just a joke on the book serie :)
open a random file (don't create a new file, otherwise it'll ask for the file name when saving and we don't want it to happen) automation -> start macro recording edit -> find and replace (as in the previous message) file -> save automation -> stop macro recording automation -> save scratch macro name it whatever you want ;) then focus the "key equivalent" field and press cmd+S go to the "scope" field and insert "source" if you only want it to be applied on source code (vs. "normal" text files)
and I think we should call this macro "hurt goblins".
hth
domenico
Il giorno 21/mar/06, alle ore 13:58, Dominic Mitchell ha scritto:
On Tue, Mar 21, 2006 at 11:58:50AM +0100, Fons Rademakers wrote:
Hi,
is there a way to, when saving, to remove all trailing spaces and tabs from lines. I would like this when saving C++/C files.
Ditto for my ruby files. It's really annoying because I edit the same stuff using Vim when I'm not at my mac, and trailing spaces really break the "up / down paragraph" navigation.
Howdy, I'd LOVE for this to work but it doesn't actually do the SAVING. It replaces everything properly when hitting cmd-S, but the saving never occurs. what am i missing? thanx...
On 3/21/06, Domenico Carbotta domenico.carbotta@fastwebnet.it wrote:
Il giorno 21/mar/06, alle ore 13:58, Dominic Mitchell ha scritto:
On Tue, Mar 21, 2006 at 11:58:50AM +0100, Fons Rademakers wrote:
Hi,
is there a way to, when saving, to remove all trailing spaces and tabs from lines. I would like this when saving C++/C files.
Ditto for my ruby files. It's really annoying because I edit the same stuff using Vim when I'm not at my mac, and trailing spaces really break the "up / down paragraph" navigation.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On Mar 21, 2006, at 9:35 AM, Domenico Carbotta wrote:
I'd LOVE for this to work but it doesn't actually do the SAVING. It replaces everything properly when hitting cmd-S, but the saving never occurs. what am i missing?
you're not missing anything, it's more about ME missing something... :| I'll let allan come to the rescue.
Try assigning it a different shortcut, and see if it works then.
Haris
There's a command - Text / Remove Trailing Spaces in Document. You could bind that, or your macro, to Cmd-E (right next to S on the keyboard), so you could remove spaces and save by holding Cmd and tapping E-S.
If you really want to get it into one command, you can use this:
perl -pe 's/[\t ]+$//g' > "$TM_FILEPATH" && cat "$TM_FILEPATH"
(Input: Entire Document Output: Replace Document)
There are two problems with this, though:
* TextMate will not know that you've overwritten the file, so while the file contents on disk will match the file contents in TextMate, you'll still get the "unsaved" bullet on your tab, and will be prompted to save on close. * You'll be returned to the beginning of the current line when you run it.
On Mar 21, 2006, at 10:48 AM, Dan Ridley wrote:
There's a command - Text / Remove Trailing Spaces in Document. You could bind that, or your macro, to Cmd-E (right next to S on the keyboard), so you could remove spaces and save by holding Cmd and tapping E-S.
ah, what keyboard is that? mine has A and D next to S. Also, cmd-E is extremely useful, it pastes the current selection to the Find field.
Haris
ok, now I remember. you have to create a command that does nothing and select "save: current file". then, when recording the macro, trigger it instead of saving the file. this should work.
So what would I need to do to bind this "Text / Remove Trailing Spaces in Document" + "Save" to, say F3 (that is what I've F3 defined to in Nedit on Linux to do the same)?
Cheers, Fons.
Dan Ridley wrote:
There's a command - Text / Remove Trailing Spaces in Document. You could bind that, or your macro, to Cmd-E (right next to S on the keyboard), so you could remove spaces and save by holding Cmd and tapping E-S.
If you really want to get it into one command, you can use this:
perl -pe 's/[\t ]+$//g' > "$TM_FILEPATH" && cat "$TM_FILEPATH"
(Input: Entire Document Output: Replace Document)
There are two problems with this, though:
- TextMate will not know that you've overwritten the file, so while the
file contents on disk will match the file contents in TextMate, you'll still get the "unsaved" bullet on your tab, and will be prompted to save on close.
- You'll be returned to the beginning of the current line when you run it.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On Mar 21, 2006, at 11:07 AM, Fons Rademakers wrote:
So what would I need to do to bind this "Text / Remove Trailing Spaces in Document" + "Save" to, say F3 (that is what I've F3 defined to in Nedit on Linux to do the same)?
Actually, all you have to do is open "Text/Remove Trailing Spaces" in the bundle editor, set its "save:" option to "current file", and assign it the key equivalent F3 by clicking on the text field next to "key equivalent" and pressing F3. Then "F3" should show up in the text field. Close the bundle editor, and you should be good to go. No need to create a new macro at all.
Cheers, Fons.
Haris
Actually, all you have to do is open "Text/Remove Trailing Spaces" in the bundle editor, set its "save:" option to "current file", and assign it the key equivalent F3 by clicking on the text field next to "key equivalent" and pressing F3.
this way you save the contents of the file BEFORE triggering the command. you need to create the empty command and then enqueue "remove trailing spaces" and said empty command in a macro.
On Mar 21, 2006, at 1:48 PM, Domenico Carbotta wrote:
Actually, all you have to do is open "Text/Remove Trailing Spaces" in the bundle editor, set its "save:" option to "current file", and assign it the key equivalent F3 by clicking on the text field next to "key equivalent" and pressing F3.
this way you save the contents of the file BEFORE triggering the command. you need to create the empty command and then enqueue "remove trailing spaces" and said empty command in a macro.
duh! I stand corrected. I've spent too much time away from messing with TextMate's bundles :). Ok then, the steps would be: Create a new blank command with sole setting that the "save:" option is set to current file. You may delete the command once the macro is created. Then you basically follow the steps as outlined by Domenico earlier:
automation -> start macro recording Text/remove trailing spaces your new blank command that saves things automation -> stop macro recording automation -> save scratch macro Choose name for macro, and set its key equivalent to F3. Move it to your favorite location. As Domenico suggested, you might want to set the scope to "source" or even something more specific, depending on what you want it for.
Haris
On 21 Mar 2006, at 11:03, Charilaos Skiadas wrote:
Actually, all you have to do is open "Text/Remove Trailing Spaces" in the bundle editor, set its "save:" option to "current file", and assign it the key equivalent F3 by clicking on the text field next to "key equivalent" and pressing F3. Then "F3" should show up in the text field. Close the bundle editor, and you should be good to go. No need to create a new macro at all.
The save option in the command editor saves the file *before* running the command, not after.
However, as Domenico pointed out earlier in the thread, you can create an empty command, set to save the file, and queue it up in a macro.
So the best way to accomplish this based on the discussion so far:
* Duplicate the "Text/Remove Trailing Spaces" command, and set input and output to Entire Document, so it won't misbehave when text is selected. * Create a new command, empty, with Save: set to Current File, input None, and output Discard * Record a macro, which runs those two commands in succession * Save the macro and assign it to F3 (or Cmd-S, if you prefer).
On 21/3/2006, at 17:48, Dan Ridley wrote:
If you really want to get it into one command, you can use this:
perl -pe 's/[\t ]+$//g' > "$TM_FILEPATH" && cat "$TM_FILEPATH"
(Input: Entire Document Output: Replace Document)
There are two problems with this, though:
- TextMate will not know that you've overwritten the file, so
while the file contents on disk will match the file contents in TextMate, you'll still get the "unsaved" bullet on your tab, and will be prompted to save on close.
- You'll be returned to the beginning of the current line when you
run it.
If you set the command to save before, it will think the file is up- to-date (even though the command makes a second save), and if you set the output to discard, you should get rid of the latter problem (then also remove the » && cat "$TM_FILEPATH"«).
It does however not handle the case where the file is untitled.
Just FYI (meant for the list) I am currently (amongst other) looking into extending commands to be used in various (callback) events, and directly on files (from the file browser). So long-term the way to strip trailing spaces (and similar) will be a method very similar to this (but with a slightly extended infrastructure to make it more graceful).
On 21 Mar 2006, at 14:06, Allan Odgaard wrote:
If you set the command to save before, it will think the file is up- to-date (even though the command makes a second save), and if you set the output to discard, you should get rid of the latter problem (then also remove the » && cat "$TM_FILEPATH"«).
The downside to that is the fact that the file on disk won't quite match up with the editor view. The trailing spaces will be removed in the file on disk, but TextMate won't know that, and will continue to display them until you reopen the file.
This might not be a problem (the original poster mentioned that the trailing spaces caused him trouble when he took the same files to vi, so as long as the saves always happen without trailing spaces it might be fine).
It does however not handle the case where the file is untitled.
Good catch. The macro solution (using a second empty command with "Save File" set) handles this situation just fine, which is another argument in favor of that method.
Seems like a lot of work for such a basic code editing function :-(
Are there any plans to add this command natively in a future release?
Sean
On Mar 22, 2006, at 7:06 AM, Allan Odgaard wrote:
On 21/3/2006, at 17:48, Dan Ridley wrote:
If you really want to get it into one command, you can use this:
perl -pe 's/[\t ]+$//g' > "$TM_FILEPATH" && cat "$TM_FILEPATH"
(Input: Entire Document Output: Replace Document)
There are two problems with this, though:
- TextMate will not know that you've overwritten the file, so
while the file contents on disk will match the file contents in TextMate, you'll still get the "unsaved" bullet on your tab, and will be prompted to save on close.
- You'll be returned to the beginning of the current line when
you run it.
If you set the command to save before, it will think the file is up- to-date (even though the command makes a second save), and if you set the output to discard, you should get rid of the latter problem (then also remove the » && cat "$TM_FILEPATH"«).
It does however not handle the case where the file is untitled.
Just FYI (meant for the list) I am currently (amongst other) looking into extending commands to be used in various (callback) events, and directly on files (from the file browser). So long-term the way to strip trailing spaces (and similar) will be a method very similar to this (but with a slightly extended infrastructure to make it more graceful).
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
:::: DataFly.Net :::: Complete Web Services http://www.datafly.net
Doh! I just noticed that this is answered at the bottom of the email I just replied too. It's morning here in Japan, I think I need to have some more coffee before firing off any more emails :-)
Sean
On Mar 22, 2006, at 10:08 AM, Sean Schertell wrote:
Seems like a lot of work for such a basic code editing function :-(
Are there any plans to add this command natively in a future release?
Sean
On Mar 22, 2006, at 7:06 AM, Allan Odgaard wrote:
On 21/3/2006, at 17:48, Dan Ridley wrote:
If you really want to get it into one command, you can use this:
perl -pe 's/[\t ]+$//g' > "$TM_FILEPATH" && cat "$TM_FILEPATH"
(Input: Entire Document Output: Replace Document)
There are two problems with this, though:
- TextMate will not know that you've overwritten the file, so
while the file contents on disk will match the file contents in TextMate, you'll still get the "unsaved" bullet on your tab, and will be prompted to save on close.
- You'll be returned to the beginning of the current line when
you run it.
If you set the command to save before, it will think the file is up-to-date (even though the command makes a second save), and if you set the output to discard, you should get rid of the latter problem (then also remove the » && cat "$TM_FILEPATH"«).
It does however not handle the case where the file is untitled.
Just FYI (meant for the list) I am currently (amongst other) looking into extending commands to be used in various (callback) events, and directly on files (from the file browser). So long- term the way to strip trailing spaces (and similar) will be a method very similar to this (but with a slightly extended infrastructure to make it more graceful).
_ For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
:::: DataFly.Net :::: Complete Web Services http://www.datafly.net
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
:::: DataFly.Net :::: Complete Web Services http://www.datafly.net