[TxMt] Default "Save As..." filename...

Hans-Joerg Bibiko bibiko at eva.mpg.de
Fri Oct 26 13:07:23 UTC 2007


On 26.10.2007, at 02:03, Brian Huddleston wrote:
> When working with templates or new files to have Textmate  
> automatically adjust the default file name used when hitting SAVE  
> to something other than "untitled"?
> For example, if I create a BASH template, and one of my fields is  
> the file/program name, I wanted to be able to either:
> 	1) hit "apple-s" and have Textmate pull a possible default  
> filename from the area/field I had defined.
> 	or
> 	2) select text; hit "apple-s"; and have the text selection become  
> the default filename
> [...]

And of course you can use the new version 0.904 of the hacking tool  
TMTOOLS which should be used at your own risk because it uses  
undocumented TM functions without an appropriate API ;)

Write a command:

Input: Selected Text or Nothing

Command:
FILENAME="$TM_SELECTED_TEXT"
EXT=$("$TMTOOLS" get suggestedExtensionForDocument)
filename="$(CocoaDialog filesave --with-directory `dirname  
"$TM_FILEPATH"` --with-file "$FILENAME.$EXT" )"
if [ -n "$filename" ]; then
	echo "{name=\""$filename"\";overwriteMode;}" |"$TMTOOLS" do  
saveWithFilenameAndReopen -
fi

Output: Show a Tool Tip
Bound to: what ever

That command gets the name from the selection (easily changeable),  
asks TM for a file extension based on the current set language;
opens CocoaDialog to choose a filename with the default "$FILENAME. 
$EXT";
if there is a $filename, it saves the current document (as floating  
window!) and reopens it in TM (if it was saved successfully!).
If such a $filename already exists it overwrites it, but you will be  
asked by CocoaDialog in beforehand ;) [If you don't use CocoaDialog,  
it would be better to delete the PLIST key overwriteMode ! ]
If the path doesn't exist, or there are access right problems, or  
other things you will be informed about it by the return value of  
"$TMTOOLS" do saveWithFilenameAndReopen and/or by TM.
This command won't work inside of a project.

#############################
TMTOOLS version 0.904
Download:
http://email.eva.mpg.de/~bibiko/downloads/textmate/TMTools.tmplugin.zip
Help:
http://email.eva.mpg.de/~bibiko/downloads/textmate/tmtoolshelp.html
or
"$TMTOOLS" help me

Changes:
added: do saveWithFilenameAndReopen '{name=XXX;overwriteMode;}'
added: get suggestedExtensionForDocument


Cheers,

--Hans



More information about the textmate mailing list