Minor question/request,
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
##################################################################### # Program: ${1:filename.sh} <---THIS IS WHAT IM TRYING TO AUTO- CAPTURE TO THE SAVE DIALOG ##################################################################### # Version: ${2:0.1} # Date: ${3:`date`} # Author: ${4:John Doe (jdoe@email.com) # # Notes: # $5 # # #####################################################################
... <insert lots of code here> ...
---- Brian H binarynomad@gmail.com http://www.binarynomad.com
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:
- 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
[...]
I believe it will be possible with the new coming DIALOG 2.
But you can try that one using CocoaDialog (it's only a fast thought idea :):
Create a command: Input: Entire Document Command:
parsed_filename="abc.txt" filename="$(CocoaDialog filesave --with-directory `dirname "$TM_FILEPATH"` --with-file "$parsed_filename" )" if [ -n "$filename" ]; then cat >"$filename" mate "$filename" fi
Key: what you like
The variable "parsed_filename" is set via a regexp parsing the second line of your template in beforehand.
The only tiny hook is that you have to close the untitled document manually.
--Hans
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:
- 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
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
Or if you want to bind that command to APPLE+SHIFT+S you can try this as command:
FILENAME="$TM_SELECTED_TEXT" if [ -z "$TM_SELECTED_TEXT" ]; then "$TMTOOLS" show saveAsPanel exit_show_tool_tip fi
FMF=$("$TMTOOLS" get frontMostDocument) if [ "${FMF:0:8}" == "untitled" ]; then 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 else "$TMTOOLS" show saveAsPanel exit_show_tool_tip fi
--Hans
On Oct 26, 2007, at 9:07 AM, Hans-Joerg Bibiko wrote:
added: do saveWithFilenameAndReopen '{name=XXX;overwriteMode;}'
Keen. Can you add something that simply saves the document if it's unsaved?
I could use the existing textmate command thing to save before running the command, but I want to do stuff with the unsaved file before saving it. Thanks!
—Thomas Aylott – subtleGradient—
On 26.10.2007, at 15:34, Thomas Aylott wrote:
On Oct 26, 2007, at 9:07 AM, Hans-Joerg Bibiko wrote:
added: do saveWithFilenameAndReopen '{name=XXX;overwriteMode;}'
Keen. Can you add something that simply saves the document if it's unsaved?
I could use the existing textmate command thing to save before running the command, but I want to do stuff with the unsaved file before saving it. Thanks!
Do you mean something like
do saveWithFilename '{name=XXX;overwriteMode;}'
without reopen it AND if the current document is unsaved AND the current document is not a "untitled" document meaning it was already saved before?
Then it could be used like: "$TMTOOLS" do saveWithFilename '{name=$TM_FILEPATH;overwriteMode;}' <further code>
--Hans
On Oct 26, 2007, at 10:15 AM, Hans-Jörg Bibiko wrote:
On 26.10.2007, at 15:34, Thomas Aylott wrote:
On Oct 26, 2007, at 9:07 AM, Hans-Joerg Bibiko wrote:
added: do saveWithFilenameAndReopen '{name=XXX;overwriteMode;}'
Keen. Can you add something that simply saves the document if it's unsaved?
I could use the existing textmate command thing to save before running the command, but I want to do stuff with the unsaved file before saving it. Thanks!
Do you mean something like
do saveWithFilename '{name=XXX;overwriteMode;}'
without reopen it AND if the current document is unsaved AND the current document is not a "untitled" document meaning it was already saved before?
Then it could be used like: "$TMTOOLS" do saveWithFilename '{name=$TM_FILEPATH;overwriteMode;}'
<further code>
--Hans
Yeah, that sounds great. I guess I'd need to throw some logic in there for allowing them to saveas if it is untitled. What's the best way to do that? Or could you work that in there too? ;)
—Thomas Aylott – subtleGradient—
On 26.10.2007, at 16:33, Thomas Aylott wrote:
On Oct 26, 2007, at 10:15 AM, Hans-Jörg Bibiko wrote:
do saveWithFilename '{name=XXX;overwriteMode;}'
without reopen it AND if the current document is unsaved AND the current document is not a "untitled" document meaning it was already saved before?
Then it could be used like: "$TMTOOLS" do saveWithFilename '{name=$TM_FILEPATH;overwriteMode;}'
<further code>
Yeah, that sounds great. I guess I'd need to throw some logic in there for allowing them to saveas if it is untitled. What's the best way to do that? Or could you work that in there too? ;)
Well, saving is a very sensible task. Ok, I can do the following:
"$TMTOOLS" do saveCurrentDocument This command is the same command like APPLE+S. Fine, but if the document is 'untitled' then this command would invoke the NSSavePanel and TM will freeze.
To avoid this one could do to the following: RETURN=$("$TMTOOLS" do saveCurrentDocument '{avoidPanel;}') This would mean that if the current document is an 'untitled' document it will return '0' without showing the save panel AND without saving, otherwise it'll return '1'; and it is up to you what do you want to do.
An other approach would be: $TMTOOLS" do saveWithFilename '{name=XXX;overwriteMode;}'
This command would also save even an untitled document as XXX. Fine, but TM will not be informed about the saving (that's why I used saveWithFilenameAndReopen). It's possible to mark the current document as saved, and set the window title to XXX, but this would lead to some unstable side-effects, I guess.
Thus I would prefer the first approach. But as I mentioned above, saving is a very sensible issue!
--Hans
On 26.10.2007, at 17:04, Hans-Jörg Bibiko wrote:
On 26.10.2007, at 16:33, Thomas Aylott wrote:
On Oct 26, 2007, at 10:15 AM, Hans-Jörg Bibiko wrote:
do saveWithFilename '{name=XXX;overwriteMode;}'
without reopen it AND if the current document is unsaved AND the current document is not a "untitled" document meaning it was already saved before?
Then it could be used like: "$TMTOOLS" do saveWithFilename '{name=$TM_FILEPATH;overwriteMode;}'
<further code>
Yeah, that sounds great. I guess I'd need to throw some logic in there for allowing them to saveas if it is untitled. What's the best way to do that? Or could you work that in there too? ;)
"$TMTOOLS" do saveCurrentDocument This command is the same command like APPLE+S. Fine, but if the document is 'untitled' then this command would invoke the NSSavePanel and TM will freeze.
To avoid this one could do to the following: RETURN=$("$TMTOOLS" do saveCurrentDocument '{avoidPanel;}') This would mean that if the current document is an 'untitled' document it will return '0' without showing the save panel AND without saving, otherwise it'll return '1'; and it is up to you what do you want to do.
I just uploaded the new version supporting this. Please read the help for that!! ;) TMTOOLS version 0.905 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
--Hans