Dear list,
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?
Thanks,
baptiste
On May 7, 2009, at 2:21 AM, 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?
I am a little confused of the command line above. Are you passing a file to it? It looks to me like you call a command named highlight and give it test.r as the file, with some options, and then pass that to the pasteboard?
I think I can help you, but this is one of very few bundle items I have made. Open your bundle editor, and click bottom left to make a new command.
I am going to mimic your command with a simple command in the shell of `ls -la path-name` which will just output a listing of a path.
I called my command "z". Set Save to: "nothing" Set the command to: #!/bin/bash /bin/ls -la "$TM_SELECTED_TEXT" * I think using full paths to your binary/commands is safest
Set Input to: "Selected Text" or "Nothing" Output to: "Replace Selected Text"
You can adjust these accordingly, ask if you have questions about the behavior.
For the scope I put it to "text.html", which I believe means it will apply to any html scope I am working in, but could also apply to more, I am not entirely clear on this aspect.
If I now move to a TM document, enter in a path, select that path, and run the bundle from the menu, it will pass the selected text into the command. You can assign a keyboard shortcut to it as well.
A test I did was to enter in /etc in TM, run the "z" command, the bundle replaced "/etc" with: lrwxr-xr-x@ 1 root admin 11 Jan 1 21:34 /etc -> private/etc
For some reason, I can not get ~ style paths to work: ~/Desktop ls: ~/Desktop: No such file or directory
ehco $PATH works just fine, and echo ~ as a bundle command also works, so I am a little confused on why a ~/path does not work.
Hope that helps.
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/