@@ -683,6 +683,29 @@ HOST is the host the process is running on, PORT is where it's listening."
683
683
(interactive " shost: \n nport: " )
684
684
(inf-clojure (cons host port)))
685
685
686
+ (defun inf-clojure--forms-without-newlines (str )
687
+ " Remove newlines between toplevel forms.
688
+ STR is a string of contents to be evaluated. When sending
689
+ multiple forms to a socket repl, each newline triggers a prompt.
690
+ So we replace all newlines between top level forms but not inside
691
+ of forms."
692
+ (condition-case nil
693
+ (with-temp-buffer
694
+ (progn
695
+ (clojurec-mode)
696
+ (insert str)
697
+ (whitespace-cleanup )
698
+ (goto-char (point-min ))
699
+ (while (not (eobp ))
700
+ (while (looking-at " \n " )
701
+ (delete-char 1 ))
702
+ (unless (eobp )
703
+ (clojure-forward-logical-sexp))
704
+ (unless (eobp )
705
+ (forward-char )))
706
+ (buffer-substring-no-properties (point-min ) (point-max ))))
707
+ (scan-error str)))
708
+
686
709
(defun inf-clojure-eval-region (start end &optional and-go )
687
710
" Send the current region to the inferior Clojure process.
688
711
Sends substring between START and END. Prefix argument AND-GO
@@ -692,22 +715,7 @@ means switch to the Clojure buffer afterwards."
692
715
; ; newlines over a socket repl between top level forms cause
693
716
; ; a prompt to be returned. so here we dump the region into a
694
717
; ; temp buffer, and delete all newlines between the forms
695
- (formatted (condition-case nil
696
- (with-temp-buffer
697
- (progn
698
- (clojurec-mode)
699
- (insert str)
700
- (whitespace-cleanup )
701
- (goto-char (point-min ))
702
- (while (not (eobp ))
703
- (while (looking-at " \n " )
704
- (delete-char 1 ))
705
- (unless (eobp )
706
- (clojure-forward-logical-sexp))
707
- (unless (eobp )
708
- (forward-char )))
709
- (buffer-substring-no-properties (point-min ) (point-max ))))
710
- (scan-error str))))
718
+ (formatted (inf-clojure--forms-without-newlines str)))
711
719
(inf-clojure--send-string (inf-clojure-proc) formatted))
712
720
(when and-go (inf-clojure-switch-to-repl t )))
713
721
0 commit comments