Created
April 9, 2010 07:55
-
-
Save nonsequitur/360973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Usage: Evaluate file, then run (toggle-swank-clojure-reroute). | |
(defvar swank-clojure-cmd-reroute-code (replace-regexp-in-string "\n+" ";" | |
"swank_clojure_cmd = ARGV.dup | |
ARGV.clear | |
swank_init_forms = [] | |
loop { swank_init_forms << (form = gets); break if form.include? 'start-server' } | |
eval_string = swank_init_forms.map(&:chomp).compact.join | |
puts 'Arguments:' | |
p swank_clojure_cmd | |
puts | |
puts 'Standard Input:' | |
p swank_init_forms | |
puts | |
insert_index = swank_clojure_cmd.find_index('clojure.main') + 1 | |
insert_index += 2 if swank_clojure_cmd[insert_index] =~ /-i|--init/ | |
swank_clojure_cmd.insert(insert_index, '-e', eval_string) | |
puts 'Starting Clojure via:' | |
p swank_clojure_cmd | |
exec('cmd', '/c', 'start', *swank_clojure_cmd) | |
")) | |
(defvar swank-clojure-cmd-reroute-active nil) | |
(defun toggle-swank-clojure-reroute () | |
(interactive) | |
(funcall (if swank-clojure-cmd-reroute-active | |
'ad-disable-advice | |
'ad-enable-advice) | |
'swank-clojure-cmd 'after 'reroute) | |
(ad-activate 'swank-clojure-cmd) | |
(setq swank-clojure-cmd-reroute-active (not swank-clojure-cmd-reroute-active)) | |
(message (concat (if swank-clojure-cmd-reroute-active | |
"Activated" "Deactivated") " Swank Clojure Command Re-Route"))) | |
(defadvice swank-clojure-cmd | |
(after reroute) | |
"Force swank-clojure-cmd to pass its Clojure shell command to a | |
intermediary script that reads the swank-clojure-init forms from | |
Standard Input and then injects these forms as an '--eval' | |
argument for clojure.main into the shell command. | |
Subsequently, the shell command is used to start a Clojure/Swank | |
process in a Windows terminal." | |
(let ((ruby "~/vendor/ruby_19_windows/bin/ruby.exe") | |
(code swank-clojure-cmd-reroute-code)) | |
(add-hook 'slime-connected-hook 'swank-clojure-cmd-connected) | |
(setq ad-return-value `(,ruby "-e" ,code ,@ad-return-value)))) | |
(defun swank-clojure-cmd-connected () | |
"Raise the Emacs frame on top of the Clojure terminal window | |
after a Slime connection has been established." | |
(remove-hook 'slime-connected-hook 'swank-clojure-cmd-connected) | |
(raise-frame)) | |
(provide 'swank-clojure-reroute) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment