Skip to content

Commit 5811278

Browse files
committed
Avoid throwing an error for frequent operations like completion
This patch introduces reduces inf-clojure-proc's responsabilities to only one: return the processs. The new inf-clojure--proc-or-error will do both returning and erroring. This is necessary because while it is good to communicate an error on "eval" operations, it is not good to have it on "under the hood" and very frequent ones like completion and get arglists.
1 parent 247ca70 commit 5811278

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

inf-clojure.el

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -691,7 +691,7 @@ The prefix argument SWITCH-TO-REPL controls whether to switch to REPL after the
691691
(comint-check-source file-name) ; Check to see if buffer needs saved.
692692
(setq inf-clojure-prev-l/c-dir/file (cons (file-name-directory file-name)
693693
(file-name-nondirectory file-name)))
694-
(inf-clojure--send-string (inf-clojure-proc)
694+
(inf-clojure--send-string (inf-clojure--proc-or-error)
695695
(format (inf-clojure-load-form) file-name))
696696
(when switch-to-repl
697697
(inf-clojure-switch-to-repl t))))
@@ -995,7 +995,7 @@ If you are using REPL types, it will pickup the most approapriate
995995
If 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 (inf-clojure--proc-or-error))
999999
(`planck inf-clojure-macroexpand-1-form-planck)
10001000
(_ inf-clojure-macroexpand-1-form))))
10011001

@@ -1042,7 +1042,7 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
10421042
(let ((var (if prompt-for-symbol
10431043
(car (inf-clojure-symprompt "Var doc" (inf-clojure-symbol-at-point)))
10441044
(inf-clojure-symbol-at-point))))
1045-
(inf-clojure--send-string (inf-clojure-proc) (format (inf-clojure-var-doc-form) var))))
1045+
(inf-clojure--send-string (inf-clojure--proc-or-error) (format (inf-clojure-var-doc-form) var))))
10461046

10471047
(defun inf-clojure-show-var-source (prompt-for-symbol)
10481048
"Send a command to the inferior Clojure to give source for VAR.
@@ -1052,7 +1052,7 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
10521052
(let ((var (if prompt-for-symbol
10531053
(car (inf-clojure-symprompt "Var source" (inf-clojure-symbol-at-point)))
10541054
(inf-clojure-symbol-at-point))))
1055-
(inf-clojure--send-string (inf-clojure-proc) (format (inf-clojure-var-source-form) var))))
1055+
(inf-clojure--send-string (inf-clojure--proc-or-error) (format (inf-clojure-var-source-form) var))))
10561056

10571057
;;;; Response parsing
10581058
;;;; ================
@@ -1182,10 +1182,11 @@ for evaluation, therefore FORM should not include it."
11821182
(defun inf-clojure-arglists (fn)
11831183
"Send a query to the inferior Clojure for the arglists for function FN.
11841184
See 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)))
1185+
(when-let ((proc (inf-clojure-proc)))
1186+
(thread-first
1187+
(format (inf-clojure-arglists-form) fn)
1188+
(inf-clojure--process-response proc "(" ")")
1189+
(inf-clojure--some))))
11891190

11901191
(defun inf-clojure-show-arglists (prompt-for-symbol)
11911192
"Show the arglists for function FN in the mini-buffer.
@@ -1207,7 +1208,7 @@ prefix argument PROMPT-FOR-NS, it prompts for a namespace name."
12071208
(let ((ns (if prompt-for-ns
12081209
(car (inf-clojure-symprompt "Ns vars" (clojure-find-ns)))
12091210
(clojure-find-ns))))
1210-
(inf-clojure--send-string (inf-clojure-proc) (format (inf-clojure-ns-vars-form) ns))))
1211+
(inf-clojure--send-string (inf-clojure-proc--or-error) (format (inf-clojure-ns-vars-form) ns))))
12111212

12121213
(defun inf-clojure-set-ns (prompt-for-ns)
12131214
"Set the ns of the inferior Clojure process to NS.
@@ -1220,13 +1221,13 @@ PROMPT-FOR-NS, it prompts for a namespace name."
12201221
(clojure-find-ns))))
12211222
(when (or (not ns) (equal ns ""))
12221223
(user-error "No namespace selected"))
1223-
(inf-clojure--send-string (inf-clojure-proc) (format (inf-clojure-set-ns-form) ns))))
1224+
(inf-clojure--send-string (inf-clojure-proc--or-error) (format (inf-clojure-set-ns-form) ns))))
12241225

12251226
(defun inf-clojure-apropos (var)
12261227
"Send a form to the inferior Clojure to give apropos for VAR.
12271228
See variable `inf-clojure-apropos-form'."
12281229
(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)))
1230+
(inf-clojure--send-string (inf-clojure--proc-or-error) (format (inf-clojure-apropos-form) var)))
12301231

12311232
(defun inf-clojure-macroexpand (&optional macro-1)
12321233
"Send a form to the inferior Clojure to give apropos for VAR.
@@ -1235,21 +1236,23 @@ With a prefix arg MACRO-1 uses `inf-clojure-macroexpand-1-form'."
12351236
(interactive "P")
12361237
(let ((last-sexp (buffer-substring-no-properties (save-excursion (backward-sexp) (point)) (point))))
12371238
(inf-clojure--send-string
1238-
(inf-clojure-proc)
1239+
(inf-clojure--proc-or-error)
12391240
(format (if macro-1
12401241
(inf-clojure-macroexpand-1-form)
12411242
(inf-clojure-macroexpand-form))
12421243
last-sexp))))
12431244

1244-
12451245
(defun inf-clojure-proc ()
12461246
"Return the current inferior Clojure process.
12471247
See 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'"))))
1248+
(get-buffer-process (if (derived-mode-p 'inf-clojure-mode)
1249+
(current-buffer)
1250+
inf-clojure-buffer)))
1251+
1252+
(defun inf-clojure--proc-or-error ()
1253+
"Return the current inferior Clojure process.
1254+
See variable `inf-clojure-buffer'."
1255+
(or (inf-clojure-proc) (error "No Clojure subprocess; see variable `inf-clojure-buffer'")))
12531256

12541257
(defun inf-clojure--list-or-nil (data)
12551258
"Return DATA if and only if it is a list."
@@ -1271,11 +1274,11 @@ every other EXPR will be discarded and nil will be returned."
12711274
Under the hood it calls the function
12721275
\\[inf-clojure-completions-fn] passing in the result of
12731276
evaluating \\[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 "(" ")")))))
1277+
(let ((proc (inf-clojure-proc)))
1278+
(when (and proc (not (string-blank-p expr)))
1279+
(let ((completion-form (format (inf-clojure-completion-form) (substring-no-properties expr))))
1280+
(funcall inf-clojure-completions-fn
1281+
(inf-clojure--process-response completion-form proc "(" ")"))))))
12791282

12801283
(defcustom inf-clojure-completions-fn 'inf-clojure-list-completions
12811284
"The function that parses completion results.

0 commit comments

Comments
 (0)