Mercurial > lasercutter
comparison src/clojure/contrib/javadoc/browse.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:35cf337adfcf | 10:ef7dbbd6452c |
---|---|
1 ;;; browse.clj -- start a web browser from Clojure | |
2 | |
3 ; Copyright (c) Christophe Grand, December 2008. All rights reserved. | |
4 ; The use and distribution terms for this software are covered by the | |
5 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
6 ; which can be found in the file epl-v10.html at the root of this | |
7 ; distribution. | |
8 ; By using this software in any fashion, you are agreeing to be bound by | |
9 ; the terms of this license. | |
10 ; You must not remove this notice, or any other, from this software. | |
11 | |
12 (ns | |
13 ^{:author "Christophe Grand", | |
14 :deprecated "1.2" | |
15 :doc "Start a web browser from Clojure"} | |
16 clojure.contrib.javadoc.browse | |
17 (:require [clojure.contrib.shell :as sh]) | |
18 (:import (java.net URI))) | |
19 | |
20 (defn- macosx? [] | |
21 (-> "os.name" System/getProperty .toLowerCase | |
22 (.startsWith "mac os x"))) | |
23 | |
24 (def *open-url-script* (when (macosx?) "/usr/bin/open")) | |
25 | |
26 (defn open-url-in-browser | |
27 "Opens url (a string) in the default system web browser. May not | |
28 work on all platforms. Returns url on success, nil if not | |
29 supported." | |
30 [url] | |
31 (try | |
32 (when (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" | |
33 "isDesktopSupported" (to-array nil)) | |
34 (-> (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" | |
35 "getDesktop" (to-array nil)) | |
36 (.browse (URI. url))) | |
37 url) | |
38 (catch ClassNotFoundException e | |
39 nil))) | |
40 | |
41 (defn open-url-in-swing | |
42 "Opens url (a string) in a Swing window." | |
43 [url] | |
44 ; the implementation of this function resides in another namespace to be loaded "on demand" | |
45 ; this fixes a bug on mac os x where requiring repl-utils turns the process into a GUI app | |
46 ; see http://code.google.com/p/clojure-contrib/issues/detail?id=32 | |
47 (require 'clojure.contrib.javadoc.browse-ui) | |
48 ((find-var 'clojure.contrib.javadoc.browse-ui/open-url-in-swing) url)) | |
49 | |
50 (defn browse-url [url] | |
51 (or (open-url-in-browser url) (when *open-url-script* (sh/sh *open-url-script* (str url)) true) (open-url-in-swing url))) |