Hi all,
Thanks for the two replies. highlight is a cool program I found here,
http://www.andre-simon.de/doku/highlight/en/highlight_io.html
I made an attempt to create a TM command for this, and it seems to work without the need for a temp directory,
highlight -H --syntax R --inline-css --fragment --enclose-pre --style print `$TM_SELECTED_TEXT` | pbcopy
It seems to work, albeit with some warning (seems to be attempting at interpreting the code of TM_SELECTED_TEXT) but since I simply discard the output and use the clipboard it's fine for my purpose.
It's a small world JiHO! --- I'm hoping to use this shortcut to post R code on the new ggplot Wiki (http://ggplot2.wik.is).
Cheers,
baptiste
----------------------------------------------------------------------
Message: 1 Date: Fri, 8 May 2009 10:08:01 -0400 From: JiHO jo.lists@gmail.com Subject: [TxMt] Re: hightlight macro To: TextMate users textmate@lists.macromates.com Message-ID: 7ADEBAA5-A929-4FB6-9782-8C4CEA7BE126@gmail.com Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
On 2009-May-07 , at 05:21 , baptiste auguie wrote:
I'm using a command line to create a html snippet with embedded css to post on a Wiki. At the moment I run,
highlight test.r -H --inline-css --fragment --enclose-pre -- style print | pbcopy
on the command line. I'd like to create a macro in TM so that I can get the same processing applied to selected text in a document. I've never written any TM macro and I don't know Ruby (or bash for that matter). Would you be kind enough to help me out?
Apparently highlight (is that a command of your creation or something else? It would help to know a little more about it) takes a file as argument. So the only ways to have it work on a selection are: 1- to modify highlight to accept either a file or some raw text from standard input (or only raw text) 2- copy the current selection to a temporary document and feed that to highlight
If 1, then you can use highlight with no argument and set TM to feed it selection or document. If the new version can only be made to accept raw text you can still use it independently this way: cat doc.r | highlight -H -...
If 2, the command would look like
# create a temporary document (cleanly) tmpDoc=$(mktemp) # fill it with TM input (selection or doc) cat > $tmpDoc # feed it to highlight highlight $tmpDoc -H -...
Otherwise, depending on the purpose of these snippets, there are plenty of online paste boards with syntax highlighting support for R, and one is accessible from textmate (Paste selection online). You get something like this: http://pastie.textmate.org/private/epwkcdngtzljzkf1zxg with a link you can embed in other pages (and I guess also in a wiki). I am also pretty sure I saw some that could output the html that is displayed (with the colors etc.).
Hop that helps.
JiHO --- http://jo.irisson.free.fr/