This repository was archived by the owner on Mar 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclojure-slime-ext.el
More file actions
56 lines (47 loc) · 1.94 KB
/
clojure-slime-ext.el
File metadata and controls
56 lines (47 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
;;; extends the swank command set
(defvar *cljx-slime-commands*
`(do
(ns swank.commands.cljx)
(swank.commands/defslimefn cljx-resolve-symbol [ns-str sym-str]
(if-let [the-ns (find-ns (symbol ns-str))]
(try
(if-let [resolved (ns-resolve the-ns (symbol sym-str))]
(cond
(var? resolved) (let [^clojure.lang.Var the-var resolved]
(list :ok
(str (.ns the-var) "/" (.sym the-var))
:var))
(class? resolved) (let [^java.lang.Class the-class resolved]
(list :ok (.getName the-class) :class)))
(list :error (format "Can't resolve symbol %s." sym-str)))
(catch Exception ex
(list :error (format "Can't resolve symbol %s." sym-str))))
(list :error
(format "Can't find namespace %s. Consider compiling buffer."
ns-str)))))
)
(defun cljx/form->string (expr)
(replace-regexp-in-string "\\\\\\(.\\)" "\\1" (prin1-to-string expr)))
(defun cljx/inject-slime-commands ()
(when (clojure-slime-connectionp)
(slime-eval-async `(interactive-eval
,(cljx/form->string *cljx-slime-commands*))
(lambda (&rest args)
(message "cljx-slime-commands injected ok.")))))
(add-hook 'slime-connected-hook 'cljx/inject-slime-commands)
(defun symbol-at-point-as-string ()
(let ((sym (symbol-at-point)))
(when sym (symbol-name sym))))
(defun cljx/symbol-at-point ()
(let ((sap (symbol-at-point)))
(when sap
(replace-regexp-in-string "\\.*$"
""
(substring-no-properties
(symbol-name sap))))))
(defun cljx/slime-resolve-symbol (sap)
(when (and (slime-connected-p) sap)
(slime-eval `(cljx-resolve-symbol ,(slime-current-package) ,sap))))
(defun cljx/slime-resolve-symbol-at-point ()
(cljx/slime-resolve-symbol (cljx/symbol-at-point)))
(provide 'clojure-slime-ext)