[TxMt] Recreating bbinclude in TextMate?

Brad Choate bchoate at gmail.com
Thu Aug 3 06:35:06 UTC 2006


Hi Ken,

I've checked in the first pass at supporting this feature.  It's in  
HTML bundle in the macromates.com subversion repository.

Usage:  In an HTML document, either use cmd+ctrl+i (include) to  
insert the include markup, or just type it out... like this:

	<!-- #tminclude "/path/to/file" -->
	<!-- end tminclude -->

(bbinclude works too, but I thought this was more appropriate.)

To update, use cmd+ctrl+u (same as in BBEdit).  This will pull in the  
included file, but leaves the include markup. Re-running the update  
command will refresh the includes, as you'd expect.

It's recursive, like BBEdit... so included files can include files or  
contain placeholders.  It also supports running Perl/Python/Ruby  
scripts (include the script... it must be executable though and must  
end in a .pl/.py/.rb extension to be recognized; I'll probably make  
this more generic by sniffing the first line for a shebang). Sorry...  
no support for AppleScript yet. The parameters passed to the script  
match the interface BBEdit uses (so command line arguments are:  
<source_file_name> <arg> <value> <arg2> <value2> ......". All TM_*  
variables are also passed through, since this is a TM command  
subprocess.

Most of the BBEdit placeholders are supported; a few are not...  
notably the ones defined through the "web project" dialog.  But it  
does automatically support all the "TM_*" variables (but you omit the  
"TM_" prefix). So you can say: #organization_name# to output the  
value of the TM_ORGANIZATION_NAME environment variable. Placeholder  
names are case-insensitive.

It also supports parameters for includes, as BBEdit does.  So you may  
say:

	<!-- #tminclude "/path/to/header.inc" #title#="Title For Include" -->
	<!-- end tminclude -->

So, your header.inc file could have...

	<title>#title#</title>

And it would expand as you'd expect.

The path for include files can be relative.  If it is relative, the  
update command will look for it, relative to 1) the current file, 2)  
the project directory (if invoked within a project). You can also use  
"~/path/to/file" and it will expand that to the path relative to your  
home directory. Oh, that reminds me... the file path is specified  
using posix paths (/path/to/file) instead of the legacy Mac form  
("Drive:Folder:Folder:File"). I'd like to support the legacy form for  
backward-compatibility, but I recommend using posix paths in general.

I'll take a look at supporting the "update all files in project"  
feature (or even selected files in the project drawer). Both should  
certainly be possible.

-Brad


PS: Oh and currently, there's nothing to prevent you from shooting  
yourself in the foot with including a file that includes itself...  
I'll take care of that shortly.


On Aug 1, 2006, at 2:53 PM, Ken Anderson wrote:

> Hi,
>
> After a quick search of the TextMate Wiki and archives of this  
> list, I am writing to ask about TextMate's ability to support a  
> useful feature related to BBEdit's support for creating websites.
>
> In particular, BBEdit has a feature called "bbinclude" that allows  
> one to insert statements like
>
> <!-- #bbinclude "footer.html" -->
> <!-- end bbinclude -->
>
> into an HTML file. You can then "update" the host file and BBEdit  
> pulls in the text from the referenced file and includes it in the  
> host file.
>
> For instance, my footer.html file looks like this:
>
>         <div id="footer">
>             <p>© Kenneth M. Anderson, 1998-#YEARNUM#.</p>
>             <p>Last Updated: #SHORTDATE#; #TIME#</p>
>         </div>
>
> and when I run the update command, it generates text like this:
>
> <!-- #bbinclude "footer.html" -->
>         <div id="footer">
>             <p>© Kenneth M. Anderson, 1998-2006.</p>
>             <p>Last Updated: 08/01/06; 3:43 PM</p>
>         </div>
> <!-- end bbinclude -->
>
> I love TextMate and use it for a variety of tasks, including the  
> creation of HTML pages, BUT, I miss BBEdit's bbinclude functionality.
>
> Is there anyway to recreate this functionality in TextMate? I'm  
> currently using simple snippets with tab triggers to mimic a  
> portion of this functionality but sometimes I'd like to update  
> multiple sections of an HTML file at once and tab-triggered  
> snippets are not sufficient to address that need. In addition, I'd  
> love to have the ability to update all the HTML files contained  
> within a TextMate project  with one command. Possible?
>
> Suggestions / feedback would be greatly appreciated!
>
> Thanks,
>
> Ken




More information about the textmate mailing list