Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

cygwin support #105

Merged
merged 1 commit into from Feb 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions lein-swank/src/leiningen/jack_in.clj
@@ -1,7 +1,8 @@
(ns leiningen.jack-in
(:require [clojure.java.io :as io]
[clojure.string :as string]
[leiningen.swank :as swank])
[leiningen.swank :as swank]
[swank.util.sys :as util])
(:import (java.security MessageDigest)))

(def ^:private payloads-file-name "swank_elisp_payloads.clj")
Expand All @@ -23,10 +24,11 @@
(let [feature (second (re-find #".*/(.*?).el$" resource))
checksum (subs (hex-digest resource) 0 8)
filename (format "%s-%s" feature checksum)
basename (-> (System/getProperty "user.home")
(io/file ".emacs.d" "swank" filename)
(.getAbsolutePath)
(.replaceAll "\\\\" "/"))
basename (util/universal-path
(-> (util/preferred-user-home-path)
(io/file ".emacs.d" "swank" filename)
(.getAbsolutePath)
(.replaceAll "\\\\" "/")))
elisp (str basename ".el")
bytecode (str basename ".elc")
elisp-file (io/file elisp)]
Expand Down
27 changes: 25 additions & 2 deletions src/swank/util/sys.clj
@@ -1,4 +1,5 @@
(ns swank.util.sys)
(ns swank.util.sys
(:import (java.io BufferedReader InputStreamReader)))

(defn get-pid
"Returns the PID of the JVM. This is largely a hack and may or may
Expand All @@ -9,5 +10,27 @@
(System/getProperty "pid")))
{:tag String})

(defn cmd [p]
(.. Runtime getRuntime (exec (str p))))

(defn cmdout [o]
(let [r (BufferedReader.
(InputStreamReader. (.getInputStream o)))]
(line-seq r)))

;; would prefer (= (System/getenv "OSTYPE") "cygwin")
;; but clojure's java not in cygwin env
(defn is-cygwin? []
(not= nil (try (cmdout (cmd "cygpath c:\\")) (catch Exception e))))

(defn universal-path [path]
(if (is-cygwin?)
(first (cmdout (cmd (str "cygpath " path))))
path))

(defn preferred-user-home-path []
(or (System/getenv "HOME")
(System/getProperty "user.home")))

(defn user-home-path []
(System/getProperty "user.home"))
(universal-path (preferred-user-home-path)))