@@ -65,6 +65,11 @@ interference with prompts that look like haskell expressions."
65
65
nil
66
66
" Mark used for the beginning of the prompt." )
67
67
68
+ (defvar haskell-interactive-mode-result-end
69
+ nil
70
+ " Mark used to figure out where the end of the current result
71
+ output is. Used to distinguish betwen user input." )
72
+
68
73
(defvar haskell-interactive-mode-old-prompt-start
69
74
nil
70
75
" Mark used for the old beginning of the prompt." )
@@ -219,12 +224,27 @@ Key bindings:
219
224
" Handle an inputted expression at the REPL."
220
225
(when (haskell-interactive-at-prompt)
221
226
(let ((expr (haskell-interactive-mode-input)))
222
- (when (not (string= " " (replace-regexp-in-string " " " " expr)))
223
- (setq haskell-interactive-mode-old-prompt-start
224
- (copy-marker haskell-interactive-mode-prompt-start))
225
- (set-marker haskell-interactive-mode-prompt-start (point-max ))
226
- (haskell-interactive-mode-history-add expr)
227
- (haskell-interactive-mode-do-expr expr)))))
227
+ (unless (string= " " (replace-regexp-in-string " " " " expr))
228
+ (cond
229
+ ; ; If already evaluating, then the user is trying to send
230
+ ; ; input to the REPL during evaluation. Most likely in
231
+ ; ; response to a getLine-like function.
232
+ ((and (haskell-process-evaluating-p (haskell-process))
233
+ (= (line-end-position ) (point-max )))
234
+ (goto-char (point-max ))
235
+ (let ((process (haskell-process))
236
+ (string (buffer-substring-no-properties
237
+ haskell-interactive-mode-result-end
238
+ (point ))))
239
+ (insert " \n " )
240
+ (haskell-process-set-sent-stdin process t )
241
+ (haskell-process-send-string process string)))
242
+ ; ; Otherwise we start a normal evaluation call.
243
+ (t (setq haskell-interactive-mode-old-prompt-start
244
+ (copy-marker haskell-interactive-mode-prompt-start))
245
+ (set-marker haskell-interactive-mode-prompt-start (point-max ))
246
+ (haskell-interactive-mode-history-add expr)
247
+ (haskell-interactive-mode-do-expr expr)))))))
228
248
229
249
(defun haskell-interactive-mode-do-expr (expr )
230
250
(cond
@@ -246,21 +266,19 @@ Key bindings:
246
266
:go (lambda (state )
247
267
(insert " \n " )
248
268
(haskell-process-send-string (cadr state)
249
- (haskell-interactive-mode-multi-line (caddr state))))
269
+ (haskell-interactive-mode-multi-line (caddr state)))
270
+ (haskell-process-set-evaluating (cadr state) t ))
250
271
:live (lambda (state buffer )
251
272
(unless (and (string-prefix-p " :q" (caddr state))
252
273
(string-prefix-p (caddr state) " :quit" ))
253
274
(let* ((cursor (cadddr state))
254
- (next (replace-regexp-in-string
255
- haskell-process-prompt-regex
256
- " "
257
- (substring buffer cursor ))))
275
+ (next (substring buffer cursor )))
258
276
(haskell-interactive-mode-eval-result (car state) next)
259
-
260
277
(setf (cdddr state) (list (length buffer)))
261
278
nil )))
262
279
:complete
263
280
(lambda (state response )
281
+ (haskell-process-set-evaluating (cadr state) nil )
264
282
(unless (haskell-interactive-mode-trigger-compile-error state response)
265
283
(haskell-interactive-mode-expr-result state response)))))))
266
284
@@ -324,12 +342,11 @@ Key bindings:
324
342
(caddr state) response)))
325
343
(cond
326
344
(haskell-interactive-mode-eval-mode
327
- (haskell-interactive-mode-eval-as-mode (car state) response))
345
+ (unless (haskell-process-sent-stdin-p (cadr state))
346
+ (haskell-interactive-mode-eval-as-mode (car state) response)))
328
347
((haskell-interactive-mode-line-is-query (elt state 2 ))
329
348
(let ((haskell-interactive-mode-eval-mode 'haskell-mode ))
330
- (haskell-interactive-mode-eval-as-mode (car state) response)))
331
- (haskell-interactive-mode-eval-pretty
332
- (haskell-interactive-mode-eval-pretty-result (car state) response))))
349
+ (haskell-interactive-mode-eval-as-mode (car state) response)))))
333
350
(haskell-interactive-mode-prompt (car state)))
334
351
335
352
(defun haskell-interactive-mode-cleanup-response (expr response )
@@ -482,7 +499,12 @@ SESSION, otherwise operate on the current buffer.
482
499
'rear-nonsticky t
483
500
'read-only t
484
501
'prompt t
485
- 'result t ))))
502
+ 'result t ))
503
+ (let ((marker (set (make-local-variable 'haskell-interactive-mode-result-end )
504
+ (make-marker ))))
505
+ (set-marker marker
506
+ (point )
507
+ (current-buffer )))))
486
508
487
509
(defun haskell-interactive-mode-eval-as-mode (session text )
488
510
" Insert TEXT font-locked according to `haskell-interactive-mode-eval-mode' ."
@@ -496,16 +518,6 @@ SESSION, otherwise operate on the current buffer.
496
518
(when haskell-interactive-mode-collapse
497
519
(haskell-collapse start (point )))))))
498
520
499
- (defun haskell-interactive-mode-eval-pretty-result (session text )
500
- " Insert the result of an eval as a pretty printed Showable, if
501
- parseable, or otherwise just as-is."
502
- (with-current-buffer (haskell-session-interactive-buffer session)
503
- (let ((inhibit-read-only t ))
504
- (delete-region haskell-interactive-mode-prompt-start (point ))
505
- (goto-char (point-max ))
506
- (haskell-show-parse-and-insert text)
507
- (insert " \n " ))))
508
-
509
521
;;;### autoload
510
522
(defun haskell-interactive-mode-echo (session message &optional mode )
511
523
" Echo a read only piece of text before the prompt."
0 commit comments