Very nice, thanks!
baptiste
1. Re: highlight (JiHO) Message: 1 Date: Sun, 10 May 2009 19:52:30 -0400 From: JiHO jo.lists@gmail.com Subject: [TxMt] Re: highlight To: TextMate users textmate@lists.macromates.com Message-ID: 91EB0E2E-0293-4B78-9776-04D854EC3710@gmail.com Content-Type: text/plain; charset="us-ascii"
On 2009-May-09 , at 15:35 , baptiste auguie wrote:
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).
OK, then I tried to link to some pasties and it does not work on this wiki.
But indeed highlight seems to be nice and is very flexible in its input. In particular it accepts input from stdin (where TM pipe your text). So I installed it from macports but I don't have all the options you have (--inlince-css, --enclose-pre etc.) because the version there is too old.
Still a simple, one language (R here) bundle command could be:
highlight -X -l --include-style --syntax=R --style=print
input set to selection or document output set to new document (or discard and add "| pbcopy" at the end of the command).
This feeds the curent selection or document to highlight directly, not need for the $TM_SELECTED_TEXT (and this solves your problems caused by shell expansion I guess).
But creating a temporary file might still be desirable: if you create it with the same extension as the current file, highlight will be able to recognize the language and your bundle command will work for any language.
Attached is my bundle item (currently set to display the HTML, pipe to pbcopy if you want to copy). Here is the code:
# Extract file extension extension=$(echo "$TM_FILEPATH" | awk -F "." {'print $NF'})
# Create a unique temporary file tmpname=$(mktemp /tmp/TMtemp.XXXX) tmpfile="$tmpname.$extension"
# Capture TM selection/Document cat > $tmpfile
# Feed that to highlight highlight --input="$tmpfile" -X -l --include-style --doc-title=$ (basename "$TM_FILEPATH") --style="vim-dark"