Skip to content

Commit 29538ca

Browse files
authored
Merge branch 'master' into fix-79
2 parents 0d41d3b + 9fa8f37 commit 29538ca

File tree

2 files changed

+85
-45
lines changed

2 files changed

+85
-45
lines changed

CHANGELOG.md

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

99
* [#77](https://github.com/clojure-emacs/inf-clojure/pull/77): Fix request "Eval expression:" if arglists return is `nil`.
1010
* [#79](https://github.com/clojure-emacs/inf-clojure/pull/82): Eldoc error when running boot repl.
11+
* [#83](https://github.com/clojure-emacs/inf-clojure/pull/85): No such namespace: complete.core in lumo REPL.
1112

1213
## 2.0.0 (2017-05-01)
1314

inf-clojure.el

Lines changed: 84 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,10 @@ If you are using REPL types, it will pickup the most approapriate
703703
(define-obsolete-variable-alias 'inf-clojure-arglist-command 'inf-clojure-arglists-form "2.0.0")
704704

705705
(defcustom inf-clojure-arglists-form-lumo
706-
"(pr-str (lumo.repl/get-arglists \"%s\"))"
706+
"(let [old-value lumo.repl/*pprint-results*]
707+
(set! lumo.repl/*pprint-results* false)
708+
(js/setTimeout #(set! lumo.repl/*pprint-results* old-value) 0)
709+
(lumo.repl/get-arglists \"%s\"))"
707710
"Lumo form to query inferior Clojure for a function's arglists."
708711
:type 'string
709712
:package-version '(inf-clojure . "2.0.0"))
@@ -726,7 +729,7 @@ If you are using REPL types, it will pickup the most approapriate
726729
(define-obsolete-variable-alias 'inf-clojure-completion-command 'inf-clojure-completion-form "2.0.0")
727730

728731
(defcustom inf-clojure-completion-form-lumo
729-
"(let [ret (atom)]
732+
"(let [ret (atom nil)]
730733
(lumo.repl/get-completions \"%s\"
731734
(fn [res] (reset! ret (map str res))))
732735
@ret)"
@@ -940,17 +943,22 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
940943
(inf-clojure-symbol-at-point))))
941944
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-source-form) var))))
942945

946+
;;;; Response parsing
947+
;;;; ================
948+
949+
(defvar inf-clojure--redirect-buffer-name " *Inf-Clojure Redirect Buffer*")
950+
943951
;; Originally from:
944952
;; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
945-
(defun inf-clojure-results-from-process (process command &optional beg-string end-string)
946-
"Send COMMAND to PROCESS.
953+
(defun inf-clojure--process-response (command process &optional beg-string end-string)
954+
"Send COMMAND to PROCESS and return the response.
947955
Return the result of COMMAND starting with BEG-STRING and ending
948956
with END-STRING if non-nil. If BEG-STRING is nil, the result
949957
string will start from (point) in the results buffer. If
950958
END-STRING is nil, the result string will end at (point-max) in
951-
the results buffer. It cuts out the output from
952-
`inf-clojure-prompt` onwards unconditionally."
953-
(let ((work-buffer " *Inf-Clojure Redirect Work Buffer*"))
959+
the results buffer. It cuts out the output from and including
960+
the `inf-clojure-prompt`."
961+
(let ((work-buffer inf-clojure--redirect-buffer-name))
954962
(save-excursion
955963
(set-buffer (get-buffer-create work-buffer))
956964
(erase-buffer)
@@ -963,29 +971,68 @@ the results buffer. It cuts out the output from
963971
;; Collect the output
964972
(set-buffer work-buffer)
965973
(goto-char (point-min))
966-
;; Skip past the command, if it was echoed
967-
(and (looking-at command)
968-
(forward-line))
969-
(let* ((beg (if beg-string
970-
(progn (search-forward beg-string nil t) (match-beginning 0))
971-
(point)))
972-
(end (if end-string
973-
(search-forward end-string nil t)
974-
(point-max)))
975-
(buffer-string (buffer-substring-no-properties beg end)))
976-
(when (and buffer-string (string-match inf-clojure-prompt buffer-string))
977-
(substring buffer-string 0 (match-beginning 0)))))))
974+
(let* ((beg (or (when (and beg-string (search-forward beg-string nil t))
975+
(match-beginning 0))
976+
(point-min)))
977+
(end (or (when end-string
978+
(search-forward end-string nil t))
979+
(point-max)))
980+
(prompt (when (search-forward inf-clojure-prompt nil t)
981+
(match-beginning 0))))
982+
(buffer-substring-no-properties beg (or prompt end))))))
983+
984+
(defun inf-clojure--nil-string-match-p (string)
985+
"Return true iff STRING is not nil.
986+
This function also takes into consideration weird escape
987+
character and matches if nil is anywhere within the input
988+
string."
989+
(string-match-p "\\Ca*nil\\Ca*" string))
990+
991+
(defun inf-clojure--some (data)
992+
"Return DATA unless nil or includes \"nil\" as string."
993+
(cond
994+
((null data) nil)
995+
((and (stringp data)
996+
(inf-clojure--nil-string-match-p data)) nil)
997+
(t data)))
998+
999+
(defun inf-clojure--read-or-nil (response)
1000+
"Read RESPONSE and return it as data.
1001+
1002+
If response is nil or includes the \"nil\" string return nil
1003+
instead.
1004+
1005+
Note that the read operation will always return the first
1006+
readable sexp only."
1007+
;; The following reads the first LISP expression
1008+
(inf-clojure--some
1009+
(when response
1010+
(ignore-errors (read response)))))
1011+
1012+
(defun inf-clojure--process-response-match-p (match-p proc form)
1013+
"Eval MATCH-P on the response of sending to PROC the input FORM.
1014+
Note that this function will add a \n to the end (or )f the string
1015+
for evaluation, therefore FORM should not include it."
1016+
(when-let ((response (inf-clojure--process-response form proc)))
1017+
(funcall match-p response)))
1018+
1019+
(defun inf-clojure--some-response-p (proc form)
1020+
"Return true iff PROC's response after evaluating FORM is not nil."
1021+
(inf-clojure--process-response-match-p
1022+
(lambda (string)
1023+
(not (inf-clojure--nil-string-match-p string)))
1024+
proc form))
1025+
1026+
;;;; Commands
1027+
;;;; ========
9781028

9791029
(defun inf-clojure-arglists (fn)
9801030
"Send a query to the inferior Clojure for the arglists for function FN.
9811031
See variable `inf-clojure-arglists-form'."
982-
(let* ((arglists-snippet (format (inf-clojure-arglists-form) fn))
983-
(arglists-result (inf-clojure-results-from-process (inf-clojure-proc) arglists-snippet))
984-
(arglists-data (when arglists-result (read arglists-result))))
985-
(cond
986-
((null arglists-data) nil)
987-
((stringp arglists-data) arglists-data)
988-
((listp arglists-data) arglists-result))))
1032+
(thread-first
1033+
(format (inf-clojure-arglists-form) fn)
1034+
(inf-clojure--process-response (inf-clojure-proc) "(" ")")
1035+
(inf-clojure--some)))
9891036

9901037
(defun inf-clojure-show-arglists (prompt-for-symbol)
9911038
"Show the arglists for function FN in the mini-buffer.
@@ -1051,26 +1098,18 @@ See variable `inf-clojure-buffer'."
10511098
(or proc
10521099
(error "No Clojure subprocess; see variable `inf-clojure-buffer'"))))
10531100

1101+
(defun inf-clojure--list-or-nil (data)
1102+
"Return DATA if and only if it is a list."
1103+
(when (listp data) data))
1104+
10541105
(defun inf-clojure-completions (expr)
10551106
"Return a list of completions for the Clojure expression starting with EXPR."
1056-
(let* ((proc (inf-clojure-proc))
1057-
(comint-filt (process-filter proc))
1058-
(kept "")
1059-
completions)
1060-
(set-process-filter proc (lambda (_proc string) (setq kept (concat kept string))))
1061-
(unwind-protect
1062-
(let ((completion-snippet
1063-
(format
1064-
(inf-clojure-completion-form) (substring-no-properties expr))))
1065-
(process-send-string proc completion-snippet)
1066-
(while (and (not (string-match inf-clojure-prompt kept))
1067-
(accept-process-output proc 2)))
1068-
(setq completions (read kept))
1069-
;; Subprocess echoes output on Windows and OS X.
1070-
(when (and completions (string= (concat (car completions) "\n") completion-snippet))
1071-
(setq completions (cdr completions))))
1072-
(set-process-filter proc comint-filt))
1073-
completions))
1107+
(when (not (string-blank-p expr))
1108+
(thread-first
1109+
(format (inf-clojure-completion-form) (substring-no-properties expr))
1110+
(inf-clojure--process-response (inf-clojure-proc) "(" ")")
1111+
(inf-clojure--read-or-nil)
1112+
(inf-clojure--list-or-nil))))
10741113

10751114
(defconst inf-clojure-clojure-expr-break-chars " \t\n\"\'`><,;|&{(")
10761115

@@ -1232,7 +1271,7 @@ to suppress the usage of the target buffer discovery logic."
12321271
"Return MATCH-P on the result of sending FORM to PROC.
12331272
Note that this function will add a \n to the end of the string
12341273
for evaluation, therefore FORM should not include it."
1235-
(funcall match-p (inf-clojure-results-from-process proc form nil)))
1274+
(funcall match-p (inf-clojure--process-response form proc nil)))
12361275

12371276
;;;; Lumo
12381277
;;;; ====

0 commit comments

Comments
 (0)