7171(require 'subr-x )
7272(require 'seq )
7373
74- (defvar inf-clojure-implementations (make-hash-table :size 6 ))
75- (defvar inf-clojure-recognize-alist '())
76- (defvar inf-clojure-startup-forms '())
77-
78- (defun inf-clojure-register-implementation
79- (repl-type implementation &optional recognize default-startup)
80- " Register a REPL-TYPE for `inf-clojure' .
81- REPL-TYPE is a symbol of the repl type (lumo, planck, etc)
82-
83- IMPLEMENTATION is a function from feature-symbol to format
84- string. For instance, (implementation 'doc) > (cljs.repl/doc
85- \" %s\" ). The full list of feature symbols is: load, doc, source,
86- arglists, apropos, ns-vars, set-ns, macroexpand, macroexpand-1,
87- and completion.
88-
89- RECOGNIZE is a namespace that, if present, will indicate that the
90- currently connected repl is a repl of this type.
91-
92- DEFAULT-STARTUP is a command to start a repl of this type from
93- the repl"
94- (puthash repl-type implementation inf-clojure-implementations)
95- (when recognize
96- (add-to-list 'inf-clojure-recognize-alist (cons repl-type recognize)))
97- (when default-startup
98- (add-to-list 'inf-clojure-startup-forms (cons repl-type default-startup))))
99-
100- (defun inf-clojure-cljs-features-dispatch (feature )
101- (case feature
102- ; ; ((load) "(cljs.core/load-file \"%s\")")
103- ((doc) " (cljs.repl/doc %s)" )
104- ((source ) " (cljs.repl/source %s)" )
105- ((arglists) " (try (->> '%s cljs.core/resolve cljs.core/meta :arglists) (catch :default _ nil))" )
106- ((apropos ) " (cljs.repl/apropos \" %s\" )" )
107- ((ns-vars) " (cljs.repl/dir %s)" )
108- ((set-ns) " (in-ns '%s)" )
109- ((macroexpand ) " (cljs.core/macroexpand '%s)" )
110- ((macroexpand-1 ) " (cljs.core/macroexpand-1 '%s)" )
111- ; ; ((completion) inf-clojure-completion-form-lumo)
112- ))
113-
114- (inf-clojure-register-implementation
115- 'cljs #'inf-clojure-cljs-features-dispatch " cljs.repl" " clojure -m cljs.main -r" )
116-
117- (defun inf-clojure-lumo-features-dispatch (feature )
118- (case feature
119- ((load ) " (clojure.core/load-file \" %s\" )" )
120- ((doc) " (lumo.repl/doc %s)" )
121- ((source ) " (lumo.repl/source %s)" )
122- ((arglists)
123- " (let [old-value lumo.repl/*pprint-results*]
124- (set! lumo.repl/*pprint-results* false)
125- (js/setTimeout #(set! lumo.repl/*pprint-results* old-value) 0)
126- (lumo.repl/get-arglists \" %s\" ))" )
127- ((apropos ) " (lumo.repl/apropos \" %s\" )" )
128- ((ns-vars) " (lumo.repl/dir %s)" )
129- ((set-ns) " (in-ns '%s)" )
130- ((macroexpand ) " (macroexpand-1 '%s)" )
131- ((macroexpand-1 ) " (macroexpand-1 '%s)" )
132- ((completion)
133- " (let [ret (atom nil)]
134- (lumo.repl/get-completions \" %s\" (fn [res] (reset! ret (map str res))))
135- @ret)" )) )
136-
137- (inf-clojure-register-implementation
138- 'lumo #'inf-clojure-lumo-features-dispatch " lumo.repl" " lumo" )
139-
140- (defun inf-clojure-planck-features-dispatch (feature )
141- (case feature
142- ((load ) " (load-file \" %s\" )" )
143- ((doc) " (planck.repl/doc %s)" )
144- ((source ) " (planck.repl/source %s)" )
145- ((arglists) " (planck.repl/get-arglists \" %s\" )" )
146- ((apropos ) " (doseq [var (sort (planck.repl/apropos \" %s\" ))] (println (str var)))" )
147- ((ns-vars) " (planck.repl/dir %s)" )
148- ((set-ns) " (in-ns '%s)" )
149- ((macroexpand ) " (macroexpand '%s)" )
150- ((macroexpand-1 ) " (macroexpand-1 '%s)" )
151- ; ; ((completion) inf-clojure-completion-form-planck )
152- ))
153-
154- (inf-clojure-register-implementation
155- 'planck #'inf-clojure-planck-features-dispatch " planck.repl" " planck" )
156-
157- (defun inf-clojure-joker-features-dispatch (feature )
158- (case feature
159- ((load ) " (load-file \" %s\" )" )
160- ((doc) " (joker.repl/doc %s)" )
161- ; ; ((source) "")
162- ((arglists)
163- " (try
164- (:arglists
165- (joker.core/meta
166- (joker.core/resolve
167- (joker.core/read-string \" %s\" ))))
168- (catch Error _ nil))" )
169- ; ; ((apropos) "")
170- ; ; ((ns-vars) "")
171- ((set-ns) " (in-ns '%s)" )
172- ((macroexpand ) " (macroexpand '%s)" )
173- ((macroexpand-1 ) " (macroexpand-1 '%s)" )
174- ; ; ((completion) "")
175- ))
176-
177- (inf-clojure-register-implementation
178- 'joker #'inf-clojure-joker-features-dispatch " joker.repl" " joker" )
179-
180- (defun inf-clojure-clojure-features-dispatch (feature )
181- (case feature
182- ((load ) " (clojure.core/load-file \" %s\" )" )
183- ((doc) " (clojure.repl/doc %s)" )
184- ((source ) " (clojure.repl/source %s)" )
185- ((arglists)
186- " (try
187- (:arglists
188- (clojure.core/meta
189- (clojure.core/resolve
190- (clojure.core/read-string \" %s\" ))))
191- (catch #?(:clj Throwable :cljr Exception) e nil))" )
192- ((apropos ) " (doseq [var (sort (clojure.repl/apropos \" %s\" ))] (println (str var)))" )
193- ((ns-vars) " (clojure.repl/dir %s)" )
194- ((set-ns) " (clojure.core/in-ns '%s)" )
195- ((macroexpand ) " (clojure.core/macroexpand '%s)" )
196- ((macroexpand-1 ) " (clojure.core/macroexpand-1 '%s)" )
197- ; ; ((completion) nil)
198- ))
199-
200- (inf-clojure-register-implementation
201- 'clojure #'inf-clojure-clojure-features-dispatch " clojure.core.server" " clojure" )
74+ (defvar inf-clojure-recognize-alist '((lumo . " lumo.repl" )
75+ (planck . " planck.repl" )
76+ ; ; cljs goes after the selfhosts
77+ (cljs . " cljs.repl" )
78+ (joker . " joker.repl" )
79+ (clojure . " clojure.core.server" )))
80+ (defvar inf-clojure-startup-forms '((clojure . " clojure" )
81+ (cljs . " clojure -m cljs.main -r" )
82+ (planck . " planck" )
83+ (lumo . " lumo" )
84+ (joker . " joker" )))
85+
86+ (defvar inf-clojure-repl-features
87+ '((cljs . ((doc . " (cljs.repl/doc %s)" )
88+ (source . " (cljs.repl/source %s)" )
89+ (arglists . " (try (->> '%s cljs.core/resolve cljs.core/meta :arglists) (catch :default _ nil))" )
90+ (apropos . " (cljs.repl/apropos \" %s\" )" )
91+ (ns-vars . " (cljs.repl/dir %s)" )
92+ (set-ns . " (in-ns '%s)" )
93+ (macroexpand . " (cljs.core/macroexpand '%s)" )
94+ (macroexpand-1 . " (cljs.core/macroexpand-1 '%s)" )))
95+ (lumo . ((load . " (clojure.core/load-file \" %s\" )" )
96+ (doc . " (lumo.repl/doc %s)" )
97+ (source . " (lumo.repl/source %s)" )
98+ (arglists .
99+ " (let [old-value lumo.repl/*pprint-results*]
100+ (set! lumo.repl/*pprint-results* false)
101+ (js/setTimeout #(set! lumo.repl/*pprint-results* old-value) 0)
102+ (lumo.repl/get-arglists \" %s\" ))" )
103+ (apropos . " (lumo.repl/apropos \" %s\" )" )
104+ (ns-vars . " (lumo.repl/dir %s)" )
105+ (set-ns . " (in-ns '%s)" )
106+ (macroexpand . " (macroexpand-1 '%s)" )
107+ (macroexpand-1 . " (macroexpand-1 '%s)" )
108+ (completion .
109+ " (let [ret (atom nil)]
110+ (lumo.repl/get-completions \" %s\" (fn [res] (reset! ret (map str res))))
111+ @ret)" )))
112+ (planck . ((load . " (load-file \" %s\" )" )
113+ (doc . " (planck.repl/doc %s)" )
114+ (source . " (planck.repl/source %s)" )
115+ (arglists . " (planck.repl/get-arglists \" %s\" )" )
116+ (apropos . " (doseq [var (sort (planck.repl/apropos \" %s\" ))] (println (str var)))" )
117+ (ns-vars . " (planck.repl/dir %s)" )
118+ (set-ns . " (in-ns '%s)" )
119+ (macroexpand . " (macroexpand '%s)" )
120+ (macroexpand-1 . " (macroexpand-1 '%s)" )))
121+ (joker . ((load . " (load-file \" %s\" )" )
122+ (doc . " (joker.repl/doc %s)" )
123+ (arglists .
124+ " (try
125+ (:arglists
126+ (joker.core/meta
127+ (joker.core/resolve
128+ (joker.core/read-string \" %s\" ))))
129+ (catch Error _ nil))" )
130+ (set-ns . " (in-ns '%s)" )
131+ (macroexpand . " (macroexpand '%s)" )
132+ (macroexpand-1 . " (macroexpand-1 '%s)" )))
133+ (clojure . ((load . " (clojure.core/load-file \" %s\" )" )
134+ (doc . " (clojure.repl/doc %s)" )
135+ (source . " (clojure.repl/source %s)" )
136+ (arglists .
137+ " (try
138+ (:arglists
139+ (clojure.core/meta
140+ (clojure.core/resolve
141+ (clojure.core/read-string \" %s\" ))))
142+ (catch #?(:clj Throwable :cljr Exception) e nil))" )
143+ (apropos . " (doseq [var (sort (clojure.repl/apropos \" %s\" ))] (println (str var)))" )
144+ (ns-vars . " (clojure.repl/dir %s)" )
145+ (set-ns . " (clojure.core/in-ns '%s)" )
146+ (macroexpand . " (clojure.core/macroexpand '%s)" )
147+ (macroexpand-1 . " (clojure.core/macroexpand-1 '%s)" )))))
148+
149+ (defun inf-clojure-get-feature (proc feature &optional no-error )
150+ " Get FEATURE based on repl type for PROC."
151+ (let* ((repl-type (or inf-clojure-repl-type
152+ (with-current-buffer (process-buffer proc)
153+ inf-clojure-repl-type)
154+ (error " Repl type is not known " )))
155+ (feature-form (alist-get feature (alist-get repl-type inf-clojure-repl-features))))
156+ (cond (feature-form feature-form)
157+ (no-error nil )
158+ (t (error " %s not configured for %s " feature repl-type)))))
202159
203160(defun inf-clojure-proc (&optional no-error )
204161 " Return the current inferior Clojure process.
@@ -234,11 +191,11 @@ See http://blog.jorgenschaefer.de/2014/05/race-conditions-in-emacs-process-filte
234191 " Set the REPL type to one of the available implementations."
235192 (interactive )
236193 (let* ((proc (inf-clojure-proc))
237- (types (hash-table-keys inf-clojure-implementations ))
194+ (types (mapcar # 'car inf-clojure-repl-features ))
238195 (type-to-set (intern
239196 (completing-read " Set repl type:"
240197 (sort (mapcar #'symbol-name types) #'string-lessp )))))
241- (setq-local inf-clojure-repl-type type-to-set)
198+ (setq-local inf-clojure-repl-type type-to-set)
242199 (with-current-buffer (process-buffer proc)
243200 (setq-local inf-clojure-repl-type type-to-set))))
244201
@@ -254,18 +211,6 @@ It requires a REPL PROC for inspecting the correct type."
254211 (setq-local inf-clojure-repl-type repl-type))
255212 inf-clojure-repl-type))
256213
257- (defun inf-clojure-get-feature (proc feature &optional no-error )
258- " Get FEATURE based on repl type for PROC."
259- (let* ((repl-type (or inf-clojure-repl-type
260- (with-current-buffer (process-buffer proc)
261- inf-clojure-repl-type)
262- (error " Repl type is not known " )))
263- (implementation (gethash repl-type inf-clojure-implementations))
264- (feature-form (and implementation (funcall implementation feature))))
265- (cond (feature-form feature-form)
266- (no-error nil )
267- (t (error " %s not configured for %s " feature repl-type)))))
268-
269214(defgroup inf-clojure nil
270215 " Run an external Clojure process (REPL) in an Emacs buffer."
271216 :prefix " inf-clojure-"
0 commit comments