@@ -361,11 +361,11 @@ Clojure to load that file."
361361 :safe #'stringp
362362 :package-version '(inf-clojure . " 2.0.0" ))
363363
364- (defun inf-clojure-load-form ()
365- " Return the form to query inferior Clojure for a var's documentation.
364+ (defun inf-clojure-load-form (proc )
365+ " Return the form to query the Inf- Clojure PROC for var's documentation.
366366If you are using REPL types, it will pickup the most appropriate
367367`inf-clojure-var-doc-form` variant."
368- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
368+ (pcase (inf-clojure--set-repl-type proc)
369369 (`lumo inf-clojure-load-form-lumo)
370370 (`planck inf-clojure-load-form-planck)
371371 (_ inf-clojure-load-form)))
@@ -595,12 +595,12 @@ Prefix argument AND-GO means switch to the Clojure buffer afterwards."
595595 (let ((str (replace-regexp-in-string
596596 " [\n ]+\\ '" " "
597597 (buffer-substring-no-properties start end))))
598- (inf-clojure--send-string (inf-clojure-proc) str))
598+ (inf-clojure--send-string (inf-clojure-- proc-or-error ) str))
599599 (when and-go (inf-clojure-switch-to-repl t )))
600600
601601(defun inf-clojure-eval-string (code )
602602 " Send the string CODE to the inferior Clojure process to be executed."
603- (inf-clojure--send-string (inf-clojure-proc) code))
603+ (inf-clojure--send-string (inf-clojure-- proc-or-error ) code))
604604
605605(defun inf-clojure-eval-defun (&optional and-go )
606606 " Send the current defun to the inferior Clojure process.
@@ -684,15 +684,15 @@ Used by this command to determine defaults."
684684
685685The prefix argument SWITCH-TO-REPL controls whether to switch to REPL after the file is loaded or not."
686686 (interactive " P" )
687- (let ((file-name (or file-name
687+ (let ((proc (inf-clojure--proc-or-error))
688+ (file-name (or file-name
688689 (car (comint-get-source " Load Clojure file: " inf-clojure-prev-l/c-dir/file
689690 ; ; nil because doesn't need an exact name
690691 inf-clojure-source-modes nil )))))
691692 (comint-check-source file-name) ; Check to see if buffer needs saved.
692693 (setq inf-clojure-prev-l/c-dir/file (cons (file-name-directory file-name)
693694 (file-name-nondirectory file-name)))
694- (inf-clojure--send-string (inf-clojure-proc)
695- (format (inf-clojure-load-form) file-name))
695+ (inf-clojure--send-string proc (format (inf-clojure-load-form proc) file-name))
696696 (when switch-to-repl
697697 (inf-clojure-switch-to-repl t ))))
698698
@@ -731,12 +731,12 @@ The prefix argument SWITCH-TO-REPL controls whether to switch to REPL after the
731731 :safe #'stringp
732732 :package-version '(inf-clojure . " 2.0.0" ))
733733
734- (defun inf-clojure-var-doc-form ()
735- " Return the form to query inferior Clojure for a var's documentation.
734+ (defun inf-clojure-var-doc-form (proc )
735+ " Return the form to query the Inf- Clojure PROC for a var's documentation.
736736If you are using REPL types, it will pickup the most approapriate
737737`inf-clojure-var-doc-form` variant."
738738 (inf-clojure--sanitize-command
739- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
739+ (pcase (inf-clojure--set-repl-type proc)
740740 (`lumo inf-clojure-var-doc-form-lumo)
741741 (`planck inf-clojure-var-doc-form-planck)
742742 (_ inf-clojure-var-doc-form))))
@@ -762,12 +762,12 @@ If you are using REPL types, it will pickup the most approapriate
762762 :safe #'stringp
763763 :package-version '(inf-clojure . " 2.0.0" ))
764764
765- (defun inf-clojure-var-source-form ()
766- " Return the form to query inferior Clojure for a var's source.
765+ (defun inf-clojure-var-source-form (proc )
766+ " Return the form to query the Inf- Clojure PROC for a var's source.
767767If you are using REPL types, it will pickup the most approapriate
768768`inf-clojure-var-source-form` variant."
769769 (inf-clojure--sanitize-command
770- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
770+ (pcase (inf-clojure--set-repl-type proc)
771771 (`lumo inf-clojure-var-source-form-lumo)
772772 (`planck inf-clojure-var-source-form-planck)
773773 (_ inf-clojure-var-source-form))))
@@ -805,12 +805,12 @@ If you are using REPL types, it will pickup the most approapriate
805805 :safe #'stringp
806806 :package-version '(inf-clojure . " 2.1.0" ))
807807
808- (defun inf-clojure-arglists-form ()
809- " Return the form to query inferior Clojure for arglists of a var.
808+ (defun inf-clojure-arglists-form (proc )
809+ " Return the form to query the Inf- Clojure PROC for arglists of a var.
810810If you are using REPL types, it will pickup the most approapriate
811811`inf-clojure-arglists-form` variant."
812812 (inf-clojure--sanitize-command
813- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
813+ (pcase (inf-clojure--set-repl-type proc)
814814 (`lumo inf-clojure-arglists-form-lumo)
815815 (`planck inf-clojure-arglists-form-planck)
816816 (_ inf-clojure-arglists-form))))
@@ -841,12 +841,12 @@ If you are using REPL types, it will pickup the most approapriate
841841 :safe #'stringp
842842 :package-version '(inf-clojure . " 2.0.0" ))
843843
844- (defun inf-clojure-completion-form ()
845- " Return the form to query inferior Clojure for a var's documentation .
844+ (defun inf-clojure-completion-form (proc )
845+ " Return the form to query the Inf- Clojure PROC for completions .
846846If you are using REPL types, it will pickup the most approapriate
847847`inf-clojure-completion-form` variant."
848848 (inf-clojure--sanitize-command
849- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
849+ (pcase (inf-clojure--set-repl-type proc)
850850 (`lumo inf-clojure-completion-form-lumo)
851851 (`planck inf-clojure-completion-form-planck)
852852 (_ inf-clojure-completion-form))))
@@ -872,12 +872,12 @@ If you are using REPL types, it will pickup the most approapriate
872872 :safe #'stringp
873873 :package-version '(inf-clojure . " 2.0.0" ))
874874
875- (defun inf-clojure-ns-vars-form ()
876- " Return the form to query inferior Clojure for public vars in a namespace.
875+ (defun inf-clojure-ns-vars-form (proc )
876+ " Return the form to query the Inf- Clojure PROC for public vars in a namespace.
877877If you are using REPL types, it will pickup the most approapriate
878878`inf-clojure-ns-vars-form` variant."
879879 (inf-clojure--sanitize-command
880- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
880+ (pcase (inf-clojure--set-repl-type proc)
881881 (`lumo inf-clojure-ns-vars-form-lumo)
882882 (`planck inf-clojure-ns-vars-form-planck)
883883 (_ inf-clojure-ns-vars-form))))
@@ -905,11 +905,11 @@ If you are using REPL types, it will pickup the most approapriate
905905 :safe #'stringp
906906 :package-version '(inf-clojure . " 2.0.0" ))
907907
908- (defun inf-clojure-set-ns-form ()
909- " Return the form to set the ns of the inferior Clojure process .
908+ (defun inf-clojure-set-ns-form (proc )
909+ " Return the form to set the namespace of the Inf- Clojure PROC .
910910If you are using REPL types, it will pickup the most approapriate
911911`inf-clojure-set-ns-form` variant."
912- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
912+ (pcase (inf-clojure--set-repl-type proc)
913913 (`planck inf-clojure-set-ns-form-planck)
914914 (`lumo inf-clojure-set-ns-form-lumo)
915915 (_ inf-clojure-set-ns-form)))
@@ -939,12 +939,12 @@ If you are using REPL types, it will pickup the most approapriate
939939 :safe #'stringp
940940 :package-version '(inf-clojure . " 2.0.0" ))
941941
942- (defun inf-clojure-apropos-form ()
943- " Return the form to query inferior Clojure for public vars in a namespace .
942+ (defun inf-clojure-apropos-form (proc )
943+ " Return the form to query the Inf- Clojure PROC for a var's apropos .
944944If you are using REPL types, it will pickup the most approapriate
945- `inf-clojure-ns-vars -form` variant."
945+ `inf-clojure-apropos -form` variant."
946946 (inf-clojure--sanitize-command
947- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
947+ (pcase (inf-clojure--set-repl-type proc)
948948 (`lumo inf-clojure-apropos-form-lumo)
949949 (`planck inf-clojure-apropos-form-planck)
950950 (_ inf-clojure-apropos-form))))
@@ -965,12 +965,12 @@ If you are using REPL types, it will pickup the most approapriate
965965 :safe #'stringp
966966 :package-version '(inf-clojure . " 2.0.0" ))
967967
968- (defun inf-clojure-macroexpand-form ()
969- " Return the form for macroexpansion in the inferior Clojure process .
968+ (defun inf-clojure-macroexpand-form (proc )
969+ " Return the form for macroexpansion in the Inf- Clojure PROC .
970970If you are using REPL types, it will pickup the most approapriate
971971`inf-clojure-macroexpand-form` variant."
972972 (inf-clojure--sanitize-command
973- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
973+ (pcase (inf-clojure--set-repl-type proc)
974974 (`planck inf-clojure-macroexpand-form-planck)
975975 (_ inf-clojure-macroexpand-form))))
976976
@@ -990,12 +990,12 @@ If you are using REPL types, it will pickup the most approapriate
990990 :safe #'stringp
991991 :package-version '(inf-clojure . " 2.0.0" ))
992992
993- (defun inf-clojure-macroexpand-1-form ()
994- " Return the form for macroexpand-1 in the inferior Clojure process .
993+ (defun inf-clojure-macroexpand-1-form (proc )
994+ " Return the form for macroexpand-1 in the Inf- Clojure PROC .
995995If you are using REPL types, it will pickup the most approapriate
996996`inf-clojure-macroexpand-1-form` variant."
997997 (inf-clojure--sanitize-command
998- (pcase (inf-clojure--set-repl-type (inf-clojure- proc) )
998+ (pcase (inf-clojure--set-repl-type proc)
999999 (`planck inf-clojure-macroexpand-1-form-planck)
10001000 (_ inf-clojure-macroexpand-1-form))))
10011001
@@ -1039,20 +1039,22 @@ The value is nil if it can't find one."
10391039See function `inf-clojure-var-doc-form' . When invoked with a
10401040prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
10411041 (interactive " P" )
1042- (let ((var (if prompt-for-symbol
1043- (car (inf-clojure-symprompt " Var doc" (inf-clojure-symbol-at-point)))
1044- (inf-clojure-symbol-at-point))))
1045- (inf-clojure--send-string (inf-clojure-proc) (format (inf-clojure-var-doc-form) var))))
1042+ (let ((proc (inf-clojure--proc-or-error))
1043+ (var (if prompt-for-symbol
1044+ (car (inf-clojure-symprompt " Var doc" (inf-clojure-symbol-at-point)))
1045+ (inf-clojure-symbol-at-point))))
1046+ (inf-clojure--send-string proc (format (inf-clojure-var-doc-form proc) var))))
10461047
10471048(defun inf-clojure-show-var-source (prompt-for-symbol )
10481049 " Send a command to the inferior Clojure to give source for VAR.
10491050See variable `inf-clojure-var-source-form' . When invoked with a
10501051prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
10511052 (interactive " P" )
1052- (let ((var (if prompt-for-symbol
1053+ (let ((proc (inf-clojure--proc-or-error))
1054+ (var (if prompt-for-symbol
10531055 (car (inf-clojure-symprompt " Var source" (inf-clojure-symbol-at-point)))
10541056 (inf-clojure-symbol-at-point))))
1055- (inf-clojure--send-string (inf-clojure- proc) (format (inf-clojure-var-source-form) var))))
1057+ (inf-clojure--send-string proc (format (inf-clojure-var-source-form proc ) var))))
10561058
10571059; ;;; Response parsing
10581060; ;;; ================
@@ -1182,10 +1184,11 @@ for evaluation, therefore FORM should not include it."
11821184(defun inf-clojure-arglists (fn )
11831185 " Send a query to the inferior Clojure for the arglists for function FN.
11841186See variable `inf-clojure-arglists-form' ."
1185- (thread-first
1186- (format (inf-clojure-arglists-form) fn)
1187- (inf-clojure--process-response (inf-clojure-proc) " (" " )" )
1188- (inf-clojure--some)))
1187+ (when-let ((proc (inf-clojure-proc)))
1188+ (thread-first
1189+ (format (inf-clojure-arglists-form proc) fn)
1190+ (inf-clojure--process-response proc " (" " )" )
1191+ (inf-clojure--some))))
11891192
11901193(defun inf-clojure-show-arglists (prompt-for-symbol )
11911194 " Show the arglists for function FN in the mini-buffer.
@@ -1204,52 +1207,60 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
12041207See variable `inf-clojure-ns-vars-form' . When invoked with a
12051208prefix argument PROMPT-FOR-NS, it prompts for a namespace name."
12061209 (interactive " P" )
1207- (let ((ns (if prompt-for-ns
1208- (car (inf-clojure-symprompt " Ns vars" (clojure-find-ns)))
1209- (clojure-find-ns))))
1210- (inf-clojure--send-string (inf-clojure-proc) (format (inf-clojure-ns-vars-form) ns))))
1210+ (let ((proc (inf-clojure--proc-or-error))
1211+ (ns (if prompt-for-ns
1212+ (car (inf-clojure-symprompt " Ns vars" (clojure-find-ns)))
1213+ (clojure-find-ns))))
1214+ (inf-clojure--send-string proc (format (inf-clojure-ns-vars-form proc) ns))))
12111215
12121216(defun inf-clojure-set-ns (prompt-for-ns )
12131217 " Set the ns of the inferior Clojure process to NS.
12141218See variable `inf-clojure-set-ns-form' . It defaults to the ns of
12151219the current buffer. When invoked with a prefix argument
12161220PROMPT-FOR-NS, it prompts for a namespace name."
12171221 (interactive " P" )
1218- (let ((ns (if prompt-for-ns
1222+ (let ((proc (inf-clojure--proc-or-error))
1223+ (ns (if prompt-for-ns
12191224 (car (inf-clojure-symprompt " Set ns to" (clojure-find-ns)))
12201225 (clojure-find-ns))))
12211226 (when (or (not ns) (equal ns " " ))
12221227 (user-error " No namespace selected" ))
1223- (inf-clojure--send-string (inf-clojure- proc) (format (inf-clojure-set-ns-form) ns))))
1228+ (inf-clojure--send-string proc (format (inf-clojure-set-ns-form proc ) ns))))
12241229
12251230(defun inf-clojure-apropos (var )
12261231 " Send a form to the inferior Clojure to give apropos for VAR.
12271232See variable `inf-clojure-apropos-form' ."
1228- (interactive (inf-clojure-symprompt " Var apropos" (inf-clojure-symbol-at-point)))
1229- (inf-clojure--send-string (inf-clojure-proc) (format (inf-clojure-apropos-form) var)))
1233+ (interactive )
1234+ (let ((proc (inf-clojure--proc-or-error))
1235+ (expression (or (car (inf-clojure-symprompt " Var apropos" (inf-clojure-symbol-at-point)))
1236+ (inf-clojure-symbol-at-point))))
1237+ (inf-clojure--send-string proc (format (inf-clojure-apropos-form proc) expression))))
12301238
12311239(defun inf-clojure-macroexpand (&optional macro-1 )
12321240 " Send a form to the inferior Clojure to give apropos for VAR.
12331241See variable `inf-clojure-macroexpand-form' .
12341242With a prefix arg MACRO-1 uses `inf-clojure-macroexpand-1-form' ."
12351243 (interactive " P" )
1236- (let ((last-sexp (buffer-substring-no-properties (save-excursion (backward-sexp ) (point )) (point ))))
1244+ (let ((proc (inf-clojure--proc-or-error))
1245+ (last-sexp (buffer-substring-no-properties (save-excursion (backward-sexp ) (point )) (point ))))
12371246 (inf-clojure--send-string
1238- (inf-clojure- proc)
1247+ proc
12391248 (format (if macro-1
1240- (inf-clojure-macroexpand-1-form)
1241- (inf-clojure-macroexpand-form))
1249+ (inf-clojure-macroexpand-1-form proc )
1250+ (inf-clojure-macroexpand-form proc ))
12421251 last-sexp))))
12431252
1244-
12451253(defun inf-clojure-proc ()
12461254 " Return the current inferior Clojure process.
12471255See variable `inf-clojure-buffer' ."
1248- (let ((proc (get-buffer-process (if (derived-mode-p 'inf-clojure-mode )
1249- (current-buffer )
1250- inf-clojure-buffer))))
1251- (or proc
1252- (error " No Clojure subprocess; see variable `inf-clojure-buffer' " ))))
1256+ (get-buffer-process (if (derived-mode-p 'inf-clojure-mode )
1257+ (current-buffer )
1258+ inf-clojure-buffer)))
1259+
1260+ (defun inf-clojure--proc-or-error ()
1261+ " Return the current inferior Clojure process.
1262+ See variable `inf-clojure-buffer' ."
1263+ (or (inf-clojure-proc) (error " No Clojure subprocess; see variable `inf-clojure-buffer' " )))
12531264
12541265(defun inf-clojure--list-or-nil (data )
12551266 " Return DATA if and only if it is a list."
@@ -1271,11 +1282,11 @@ every other EXPR will be discarded and nil will be returned."
12711282Under the hood it calls the function
12721283\\ [inf-clojure-completions-fn] passing in the result of
12731284evaluating \\ [inf-clojure-completion-form] at the REPL."
1274- (when ( not ( string-blank-p expr ))
1275- (let (( proc (inf-clojure-proc ))
1276- ( completion-form (format (inf-clojure-completion-form) (substring-no-properties expr))))
1277- (funcall inf-clojure-completions-fn
1278- (inf-clojure--process-response completion-form proc " (" " )" )))))
1285+ (let ((proc (inf-clojure-proc) ))
1286+ (when ( and proc (not ( string-blank-p expr) ))
1287+ ( let (( completion-form (format (inf-clojure-completion-form proc ) (substring-no-properties expr))))
1288+ (funcall inf-clojure-completions-fn
1289+ (inf-clojure--process-response completion-form proc " (" " )" ) )))))
12791290
12801291(defcustom inf-clojure-completions-fn 'inf-clojure-list-completions
12811292 " The function that parses completion results.
0 commit comments