Dear TextMate experts,
I would like to execute the shell script myscript.sh from within TextMate. The script myscript.sh takes a file name as argument and does something with the file (it indents the file correctly; for this, it calls emacs in batch mode). So if I use sh myscript.sh myfile.R the script works perfectly fine, i.e., it indents the source code contained in myfile.R. I would like to have textmate do this for me on the file I am working on when I use a certain key combination.
Using the Bundle Editor, I created a new command "tidy" with key equivalent "shift+command+T". As the actual command, I put in: sh /path_to_my_script/myscript.sh "$TM_FILENAME"
Unfortunately, this does not work. I set "Input" to "Entire Document" and "Output" to "Replace Document" (currently I obtain an empty document after "shift+command+T").
How can I trigger the shell script, such that the current content of myfile.R is replaced by the (quietly generated) output of myscript.sh?
Below is the script
Many thanks in advance,
Marius
#!/bin/sh function usage () { printf "Indent R file with Emacs ESS package.\n" printf "Usage: $0 FILE\n" exit 1 } f=$1 shift if test "x$f" = x -o "x$f" = "x-h"; then usage fi emacs -batch \ -eval '(load "/usr/local/share/emacs/site-lisp/ess-5.8/lisp/ess-site")' \ -f R-mode \ -eval '(untabify (point-min) (point-max))' \ -eval '(insert-file "'${f}'")' \ -eval '(set-visited-file-name "'"${f}"'")' \ -eval '(indent-region (point-min) (point-max) nil)' \ -f save-buffer \ 2>/dev/null
This is from "Reformat with JS Beautifier" command:
Command(s):
cat > /tmp/reformat_this_file.js cd "$TM_BUNDLE_SUPPORT/bin/js-beautify/" java -jar ../js.jar beautify-cl.js -n -i 1 /tmp/reformat_this_file.js 2>&1
Input: Selected Text or Scope Output: Replace Selected Text
HTH
-- Alexey
On Wed, May 5, 2010 at 15:27, Marius Hofert m_hofert@web.de wrote:
Dear TextMate experts,
I would like to execute the shell script myscript.sh from within TextMate. The script myscript.sh takes a file name as argument and does something with the file (it indents the file correctly; for this, it calls emacs in batch mode). So if I use sh myscript.sh myfile.R the script works perfectly fine, i.e., it indents the source code contained in myfile.R. I would like to have textmate do this for me on the file I am working on when I use a certain key combination.
Using the Bundle Editor, I created a new command "tidy" with key equivalent "shift+command+T". As the actual command, I put in: sh /path_to_my_script/myscript.sh "$TM_FILENAME"
Unfortunately, this does not work. I set "Input" to "Entire Document" and "Output" to "Replace Document" (currently I obtain an empty document after "shift+command+T").
How can I trigger the shell script, such that the current content of myfile.R is replaced by the (quietly generated) output of myscript.sh?
Below is the script
Many thanks in advance,
Marius
#!/bin/sh function usage () { printf "Indent R file with Emacs ESS package.\n" printf "Usage: $0 FILE\n" exit 1 } f=$1 shift if test "x$f" = x -o "x$f" = "x-h"; then usage fi emacs -batch \ -eval '(load "/usr/local/share/emacs/site-lisp/ess-5.8/lisp/ess-site")' \ -f R-mode \ -eval '(untabify (point-min) (point-max))' \ -eval '(insert-file "'${f}'")' \ -eval '(set-visited-file-name "'"${f}"'")' \ -eval '(indent-region (point-min) (point-max) nil)' \ -f save-buffer \ 2>/dev/null
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On May 5, 2010, at 1:27 PM, Marius Hofert wrote:
How can I trigger the shell script, such that the current content of myfile.R is replaced by the (quietly generated) output of myscript.sh?
It depends on.
First you have to use $TM_FILEPATH not $TM_FILENAME since it only holds the name not the entire path. In your command you should set: - Save: Current File - Input: None
Next, does your script output the new generated stuff on standard output or does it save it? If you run it in the Terminal.app and you see the new stuff then you can set in your command: - Output: Replace Document
If it saves the new stuff to a file, then you can add a shell command "cat /path/to/the/new/file.
On the other hand, does your script support reading from stdin? Then you can simply write as command:
cat | /path_to_my_script/myscript.sh
and set as Input: Entire Document and Save: Nothing.
You see, it's rather difficult to guess how your script works thus provide a bit more details.
Cheers, --Hans
Oh,
sorry, I didn't saw your script. I think if you simply use $TM_FILEPATH it should work.
What's about to use the R bundle "Tidy" function. It makes usage of R's internal formatter.
Can you post me the formatted style to me privately (if the code is not confidential, of course) to see the difference, since I'm still looking for a nice prettifier for R code.
Cheers, --Hans
Hans,
just out of interest: why does the Tidy function remove comments? The formatting is very nice, but loosing the comments is quite a price to pay...
cheers, Daniel
On 5 May 2010, at 13:51, Hans-Jörg Bibiko wrote:
Oh,
sorry, I didn't saw your script. I think if you simply use $TM_FILEPATH it should work.
What's about to use the R bundle "Tidy" function. It makes usage of R's internal formatter.
Can you post me the formatted style to me privately (if the code is not confidential, of course) to see the difference, since I'm still looking for a nice prettifier for R code.
Cheers, --Hans
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On May 6, 2010, at 3:31 PM, Daniel Stegmueller wrote:
Hans,
just out of interest: why does the Tidy function remove comments? The formatting is very nice, but loosing the comments is quite a price to pay...
up to now the Tidy function makes usage of R's internal function formatting.
I declare a new dummy function à la:
dummy <- function() { "TM's R document code" }
and then I dump this dummy function by using options(keep.source = FALSE) for a R --slave command via:
dump(ls(all = TRUE), file = "a_temp_file", control = c("keepInteger", "keepNA", "quoteExpressions")
By doing this all comments will be unfortunately removed. That's why I'm still looking for a better way.
Cheers, --Hans
Ah, I hoped this was just your preference, but I see that there's no easy way around this.
I usually document my functions in one comment at the top - so it is not a problem. However, when writing code for students, it seems easier for them if each line is commented...
Thanks, Daniel
On 6 May 2010, at 19:10, Hans-Jörg Bibiko wrote:
On May 6, 2010, at 3:31 PM, Daniel Stegmueller wrote:
Hans,
just out of interest: why does the Tidy function remove comments? The formatting is very nice, but loosing the comments is quite a price to pay...
up to now the Tidy function makes usage of R's internal function formatting.
I declare a new dummy function à la:
dummy <- function() { "TM's R document code" }
and then I dump this dummy function by using options(keep.source = FALSE) for a R --slave command via:
dump(ls(all = TRUE), file = "a_temp_file", control = c("keepInteger", "keepNA", "quoteExpressions")
By doing this all comments will be unfortunately removed. That's why I'm still looking for a better way.
Cheers, --Hans
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate