[TxMt] Re: Export selected text to HTML?
Allan Odgaard
allan at macromates.com
Sun Feb 6 00:31:39 UTC 2005
On Feb 6, 2005, at 0:43, Chris Ruzin wrote:
>> Since the OP wanted line numbers, I also did a small awk script to
>> insert these [...]
> I can get the source-highlight to work perfectly. I changed the
> output to xhtml (you know, standards and all) and it looks great!
> However...
> whenever I try to pipe it through awk, I just get a single blank line
> as output. I copied and pasted your example above. Any ideas as to
> why it would do that?
No ideas, here's my command in its own bundle (which reminds me that
bundle items should be drag-able to/from Mail for these types of
situations ;) ):
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test.tmbundle.zip
Type: application/zip
Size: 1384 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20050206/c439f56e/attachment.zip>
-------------- next part --------------
> I know NOTHING about awk.
Awk is great for processing text, it takes a 'program' which is
basically a list of ?regex { action }? where action is executed if
regex matches the line (it applies all rules to all lines of the
source.
In action you have the variables $1-n to access specific columns. Try
?man awk?. You can also leave out the regex to have the action executed
for all lines and there are also commands to skip the next actions etc.
etc. Basically awk is an entire programming language, but with text
processing in mind.
> Also, is there a way to include the compiled source-highlight files
> inside of the TextMate application bundle in the future so this could
> be a built-in feature?
There is, and you can reach the path of the bundle to which the command
belong with $TM_BUNDLE_PATH, so basically just copy it to a bin
directory of your bundle and call it as
$TM_BUNDLE_PATH/bin/source-highlight -- though I don't think I should
include this with TextMate (because it's then a binary distribution of
a GNU source and I don't want to argue over whether or not TextMate is
derived work of source-highlight etc.), but I probably should look into
that system people are requesting about having a Quicksilver-inspired
system where people can 'look for more bundles'.
> Right now, you have to staticly type in what the source is. Can TM
> have a current file extension variable (or something like that)
You can get the extension from the TM_FILEPATH like this:
TM_EXT=`echo $TM_FILEPATH|tr . '\n'|tail -1`
But you'd need to map it to the proper argument, e.g. rb -> ruby etc.
Here's an example of how you could do that (inline):
TM_LANG=`grep ^$TM_EXT <<EOF |cut -d: -f2
cc:cpp
mm:cpp
h:cpp
rb:ruby
EOF`
So you'd just add mappings to the list.
There also is the TM_MODE variable which I introduced with the
mode-dependent-lookup. This would be better to use for this, but the
reason I don't mention it is, that the scope system will soon see the
light of day, and that kind of makes this mode-stuff redundant.
So for future compatibility, I'd suggest not relying on TM_MODE. and in
the future the command could be changed to use the scope stuff. But I
guess for most other languages than C++, there are only one or two
extensions in use, so the list above will be manageable.
> I also just noticed that the piping through awk isn't necessary with
> source-highlight. Just add "-n" to the command and it will
> automatically output it with line numbers. Even better, if you add
> "--line-number-ref",
Doh! Well, it gave me a chance to talk about the often overlooked awk!
;)
More information about the textmate
mailing list