Skip to content

Commit 4e80276

Browse files
slipsetbbatsov
authored andcommitted
[Fix #56] Add special handling for Planck REPLS (#66)
1 parent dda0a43 commit 4e80276

File tree

3 files changed

+128
-8
lines changed

3 files changed

+128
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features
66

7+
* [#66](https://github.com/clojure-emacs/inf-clojure/pull/56): Add Planck support.
78
* [#51](https://github.com/clojure-emacs/inf-clojure/pull/51): Commands do not prompt by default anymore, unless they receive a non-nil prefix argument.
89
* [#44](https://github.com/clojure-emacs/inf-clojure/pull/44): Add REPL types and Lumo support.
910
* [#50](https://github.com/clojure-emacs/inf-clojure/pull/50): Rename defcustoms to `inf-clojure-*-form` where appropriate.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ docstring for.
7777
## REPL Type
7878

7979
An `inf-clojure` REPL can be of different types: Clojure, ClojureScript, Lumo and Planck are all potentially valid options.
80-
At the moment, the default Clojure REPL and the Lumo REPL (though partially, see https://github.com/clojure-emacs/inf-clojure/pull/44) are supported.
80+
At the moment, the default Clojure REPL, the Lumo REPL (though partially, see https://github.com/clojure-emacs/inf-clojure/pull/44), and the Planck REPL are supported.
8181

8282
To hook up a custom REPL type, just use the right launch command (or connect through socket).
8383
For example, for Lumo just add the following in your `.dir-locals.el`:

inf-clojure.el

Lines changed: 126 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ See http://blog.jorgenschaefer.de/2014/05/race-conditions-in-emacs-process-filte
205205
(let ((inf-clojure--repl-type-lock t))
206206
(cond
207207
((inf-clojure--lumo-p proc) 'lumo)
208+
((inf-clojure--planck-p proc) 'planck)
208209
(t 'clojure)))))
209210

210211
(defun inf-clojure--set-repl-type (proc)
@@ -221,7 +222,7 @@ STRING (for example set the buffer local REPL type). It should
221222
always be preferred over `comint-send-string`. It delegates to
222223
`comint-simple-send` so it always appends a newline at the end of
223224
the string for evaluation. Refer to `comint-simple-send` for
224-
customizations. "
225+
customizations."
225226
(inf-clojure--set-repl-type proc)
226227
(comint-simple-send proc string))
227228

@@ -236,7 +237,15 @@ Clojure to load that file."
236237
(define-obsolete-variable-alias 'inf-clojure-load-command 'inf-clojure-load-form "2.0.0")
237238

238239
(defcustom inf-clojure-load-form-lumo "(clojure.core/load-file \"%s\")"
239-
"Format-string for building a Clojure expression to load a file.
240+
"Lumo format-string for building a Clojure expression to load a file.
241+
This format string should use `%s' to substitute a file name and
242+
should result in a Clojure form that will be sent to the inferior
243+
Clojure to load that file."
244+
:type 'string
245+
:package-version '(inf-clojure . "2.0.0"))
246+
247+
(defcustom inf-clojure-load-form-planck "(load-file \"%s\")"
248+
"Planck format-string for building a Clojure expression to load a file.
240249
This format string should use `%s' to substitute a file name and
241250
should result in a Clojure form that will be sent to the inferior
242251
Clojure to load that file."
@@ -249,6 +258,7 @@ If you are using REPL types, it will pickup the most approapriate
249258
`inf-clojure-var-doc-form` variant."
250259
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
251260
(`lumo inf-clojure-load-form-lumo)
261+
(`planck inf-clojure-load-form-planck)
252262
(_ inf-clojure-load-form)))
253263

254264
(defcustom inf-clojure-prompt "^[^=> \n]+=> *"
@@ -592,12 +602,19 @@ The prefix argument SWITCH-TO-REPL controls whether to switch to REPL after the
592602
:type 'string
593603
:package-version '(inf-clojure . "2.0.0"))
594604

605+
(defcustom inf-clojure-var-doc-form-planck
606+
"(planck.repl/doc %s)\n"
607+
"Planck form to query inferior Clojure for a var's documentation."
608+
:type 'string
609+
:package-version '(inf-clojure . "2.0.0"))
610+
595611
(defun inf-clojure-var-doc-form ()
596612
"Return the form to query inferior Clojure for a var's documentation.
597613
If you are using REPL types, it will pickup the most approapriate
598614
`inf-clojure-var-doc-form` variant."
599615
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
600616
(`lumo inf-clojure-var-doc-form-lumo)
617+
(`planck inf-clojure-var-doc-form-planck)
601618
(_ inf-clojure-var-doc-form)))
602619

603620
(defcustom inf-clojure-var-source-form
@@ -606,6 +623,20 @@ If you are using REPL types, it will pickup the most approapriate
606623
:type 'string
607624
:package-version '(inf-clojure . "2.0.0"))
608625

626+
(defcustom inf-clojure-var-source-form-planck
627+
"(planck.repl/source %s)\n"
628+
"Planck form to query inferior Clojure for a var's source."
629+
:type 'string
630+
:package-version '(inf-clojure . "2.0.0"))
631+
632+
(defun inf-clojure-var-source-form ()
633+
"Return the form to query inferior Clojure for a var's source.
634+
If you are using REPL types, it will pickup the most approapriate
635+
`inf-clojure-var-source-form` variant."
636+
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
637+
(`planck inf-clojure-var-source-form-planck)
638+
(_ inf-clojure-var-source-form)))
639+
609640
(define-obsolete-variable-alias 'inf-clojure-var-source-command 'inf-clojure-var-source-form "2.0.0")
610641

611642
(defcustom inf-clojure-arglists-form
@@ -649,12 +680,19 @@ If you are using REPL types, it will pickup the most approapriate
649680
:type 'string
650681
:package-version '(inf-clojure . "2.0.0"))
651682

683+
(defcustom inf-clojure-completion-form-planck
684+
"(planck.repl/get-completions \"%s\")\n"
685+
"Planck form to query inferior Clojure for completion candidates."
686+
:type 'string
687+
:package-version '(inf-clojure . "2.0.0"))
688+
652689
(defun inf-clojure-completion-form ()
653690
"Return the form to query inferior Clojure for a var's documentation.
654691
If you are using REPL types, it will pickup the most approapriate
655692
`inf-clojure-completion-form` variant."
656693
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
657694
(`lumo inf-clojure-completion-form-lumo)
695+
(`planck inf-clojure-completion-form-planck)
658696
(_ inf-clojure-completion-form)))
659697

660698
(defcustom inf-clojure-ns-vars-form
@@ -669,12 +707,19 @@ If you are using REPL types, it will pickup the most approapriate
669707
:type 'string
670708
:package-version '(inf-clojure . "2.0.0"))
671709

710+
(defcustom inf-clojure-ns-vars-form-planck
711+
"(planck.repl/dir %s)\n"
712+
"Planck form to show the public vars in a namespace."
713+
:type 'string
714+
:package-version '(inf-clojure . "2.0.0"))
715+
672716
(defun inf-clojure-ns-vars-form ()
673717
"Return the form to query inferior Clojure for public vars in a namespace.
674718
If you are using REPL types, it will pickup the most approapriate
675719
`inf-clojure-ns-vars-form` variant."
676720
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
677721
(`lumo inf-clojure-ns-vars-form-lumo)
722+
(`planck inf-clojure-ns-vars-form-lumo)
678723
(_ inf-clojure-ns-vars-form)))
679724

680725
(define-obsolete-variable-alias 'inf-clojure-ns-vars-command 'inf-clojure-ns-vars-form "2.0.0")
@@ -685,6 +730,20 @@ If you are using REPL types, it will pickup the most approapriate
685730
:type 'string
686731
:package-version '(inf-clojure . "2.0.0"))
687732

733+
(defcustom inf-clojure-set-ns-form-planck
734+
"(in-ns '%s)\n"
735+
"Planck form to set the namespace of the inferior Clojure process."
736+
:type 'string
737+
:package-version '(inf-clojure . "2.0.0"))
738+
739+
(defun inf-clojure-set-ns-form ()
740+
"Return the form to set the ns of the inferior Clojure process.
741+
If you are using REPL types, it will pickup the most approapriate
742+
`inf-clojure-set-ns-form` variant."
743+
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
744+
(`planck inf-clojure-set-ns-form-planck)
745+
(_ inf-clojure-ns-form)))
746+
688747
(define-obsolete-variable-alias 'inf-clojure-set-ns-command 'inf-clojure-set-ns-form "2.0.0")
689748

690749
(defcustom inf-clojure-apropos-form
@@ -694,6 +753,21 @@ If you are using REPL types, it will pickup the most approapriate
694753
:type 'string
695754
:package-version '(inf-clojure . "2.0.0"))
696755

756+
(defcustom inf-clojure-apropos-form-planck
757+
"(doseq [var (sort (planck.repl/apropos \"%s\"))]
758+
(println (str var)))\n"
759+
"Planck form to invoke apropos."
760+
:type 'string
761+
:package-version '(inf-clojure . "2.0.0"))
762+
763+
(defun inf-clojure-apropos-form ()
764+
"Return the form to query inferior Clojure for public vars in a namespace.
765+
If you are using REPL types, it will pickup the most approapriate
766+
`inf-clojure-ns-vars-form` variant."
767+
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
768+
(`planck inf-clojure-apropos-form-planck)
769+
(_ inf-clojure-apropos-form)))
770+
697771
(define-obsolete-variable-alias 'inf-clojure-apropos-command 'inf-clojure-apropos-form "2.0.0")
698772

699773
(defcustom inf-clojure-macroexpand-form
@@ -702,6 +776,20 @@ If you are using REPL types, it will pickup the most approapriate
702776
:type 'string
703777
:package-version '(inf-clojure . "2.0.0"))
704778

779+
(defcustom inf-clojure-macroexpand-form-planck
780+
"(macroexpand '%s)\n"
781+
"Planck form to invoke macroexpand."
782+
:type 'string
783+
:package-version '(inf-clojure . "2.0.0"))
784+
785+
(defun inf-clojure-macroexpand-form ()
786+
"Return the form for macroexpansion in the inferior Clojure process.
787+
If you are using REPL types, it will pickup the most approapriate
788+
`inf-clojure-macroexpand-form` variant."
789+
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
790+
(`planck inf-clojure-macroexpand-form-planck)
791+
(_ inf-clojure-macroexpand-form)))
792+
705793
(define-obsolete-variable-alias 'inf-clojure-macroexpand-command 'inf-clojure-macroexpand-form "2.0.0")
706794

707795
(defcustom inf-clojure-macroexpand-1-form
@@ -710,6 +798,20 @@ If you are using REPL types, it will pickup the most approapriate
710798
:type 'string
711799
:package-version '(inf-clojure . "2.0.0"))
712800

801+
(defcustom inf-clojure-macroexpand-1-form-planck
802+
"(macroexpand-1 '%s)\n"
803+
"Planck form to invoke macroexpand-1."
804+
:type 'string
805+
:package-version '(inf-clojure . "2.0.0"))
806+
807+
(defun inf-clojure-macroexpand-1-form ()
808+
"Return the form for macroexpand-1 in the inferior Clojure process.
809+
If you are using REPL types, it will pickup the most approapriate
810+
`inf-clojure-macroexpand-1-form` variant."
811+
(pcase (inf-clojure--set-repl-type (inf-clojure-proc))
812+
(`planck inf-clojure-macroexpand-1-planck)
813+
(_ inf-clojure-macroexpand-1-form)))
814+
713815
(define-obsolete-variable-alias 'inf-clojure-macroexpand-1-command 'inf-clojure-macroexpand-1-form "2.0.0")
714816

715817
;;; Ancillary functions
@@ -763,7 +865,7 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
763865
(let ((var (if prompt-for-symbol
764866
(car (inf-clojure-symprompt "Var source" (inf-clojure-symbol-at-point)))
765867
(inf-clojure-symbol-at-point))))
766-
(comint-proc-query (inf-clojure-proc) (format inf-clojure-var-source-form var))))
868+
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-source-form) var))))
767869

768870
(defun inf-clojure-match-arglists (input-form string)
769871
"Return the arglists match from INPUT-FORM and STRING.
@@ -825,13 +927,13 @@ PROMPT-FOR-NS, it prompts for a namespace name."
825927
(clojure-find-ns))))
826928
(when (or (not ns) (equal ns ""))
827929
(user-error "No namespace selected"))
828-
(comint-proc-query (inf-clojure-proc) (format inf-clojure-set-ns-form ns))))
930+
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-set-ns-form) ns))))
829931

830932
(defun inf-clojure-apropos (var)
831933
"Send a form to the inferior Clojure to give apropos for VAR.
832934
See variable `inf-clojure-apropos-form'."
833935
(interactive (inf-clojure-symprompt "Var apropos" (inf-clojure-symbol-at-point)))
834-
(comint-proc-query (inf-clojure-proc) (format inf-clojure-apropos-form var)))
936+
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-apropos-form) var)))
835937

836938
(defun inf-clojure-macroexpand (&optional macro-1)
837939
"Send a form to the inferior Clojure to give apropos for VAR.
@@ -842,8 +944,8 @@ With a prefix arg MACRO-1 uses `inf-clojure-macroexpand-1-form'."
842944
(inf-clojure--send-string
843945
(inf-clojure-proc)
844946
(format (if macro-1
845-
inf-clojure-macroexpand-1-form
846-
inf-clojure-macroexpand-form)
947+
(inf-clojure-macroexpand-1-form)
948+
(inf-clojure-macroexpand-form))
847949
last-sexp))))
848950

849951

@@ -1067,5 +1169,22 @@ for evaluation, therefore FORM should not include it."
10671169
(string-match-p "\\Ca*true\\Ca*" string)))
10681170
"Ascertain that PROC is a Lumo REPL.")
10691171

1172+
1173+
;;;; Planck
1174+
;;;; ====
1175+
1176+
(defcustom inf-clojure--planck-repl-form
1177+
"(js/global.hasOwnProperty \"PLANCK_VERSION\")"
1178+
"Form to invoke in order to verify that we launched a Planck REPL."
1179+
:type 'string
1180+
:package-version '(inf-clojure . "2.0.0"))
1181+
1182+
(defalias 'inf-clojure--planck-p
1183+
(apply-partially 'inf-clojure--response-match-p
1184+
inf-clojure--planck-repl-form
1185+
(lambda (string)
1186+
(string-match-p "\\Ca*true\\Ca*" string)))
1187+
"Ascertain that PROC is a Planck REPL.")
1188+
10701189
(provide 'inf-clojure)
10711190
;;; inf-clojure.el ends here

0 commit comments

Comments
 (0)