@@ -247,7 +247,12 @@ do the
247
247
:}"
248
248
(if (not (string-match-p " \n " expr))
249
249
expr
250
- (let ((len (length haskell-interactive-prompt))
250
+ (let ((len (if (or haskell-interactive-use-interactive-prompt
251
+ (not (string-match " \n .*\\ '" haskell-interactive-prompt)))
252
+ (length haskell-interactive-prompt)
253
+ (- (match-end 0 )
254
+ (match-beginning 0 )
255
+ 1 )))
251
256
(lines (split-string expr " \n " )))
252
257
(cl-loop for elt on (cdr lines) do
253
258
(setcar elt (substring (car elt) len)))
@@ -295,21 +300,30 @@ do the
295
300
(defun haskell-interactive-mode-prompt (&optional session )
296
301
" Show a prompt at the end of the REPL buffer.
297
302
If SESSION is non-nil, use the REPL buffer associated with
298
- SESSION, otherwise operate on the current buffer."
303
+ SESSION, otherwise operate on the current buffer. The prompt
304
+ inserted is specified by `haskell-interactive-prompt' .
305
+ When `haskell-interactive-use-interactive-prompt' is non-nil,
306
+ the prompt is inserted in this function. Otherwise it was already
307
+ set in the `haskell-process-send-startup' and has already been
308
+ inserted in the buffer by the process."
299
309
(with-current-buffer (if session
300
310
(haskell-session-interactive-buffer session)
301
311
(current-buffer ))
302
312
(goto-char (point-max ))
303
- (let ((prompt (propertize haskell-interactive-prompt
304
- 'font-lock-face 'haskell-interactive-face-prompt
305
- 'prompt t
306
- 'read-only t
307
- 'rear-nonsticky t )))
308
- ; ; At the time of writing, front-stickying the first char gives an error
309
- ; ; Has unfortunate side-effect of being able to insert before the prompt
310
- (insert (substring prompt 0 1 )
311
- (propertize (substring prompt 1 )
312
- 'front-sticky t )))
313
+ (if haskell-interactive-use-interactive-prompt
314
+ (let ((prompt (propertize haskell-interactive-prompt
315
+ 'font-lock-face 'haskell-interactive-face-prompt
316
+ 'prompt t
317
+ 'read-only t
318
+ 'rear-nonsticky t )))
319
+ ; ; At the time of writing, front-stickying the first char gives an error
320
+ ; ; Has unfortunate side-effect of being able to insert before the prompt
321
+ (insert (substring prompt 0 1 )
322
+ (propertize (substring prompt 1 )
323
+ 'front-sticky t )))
324
+ (let ((inhibit-read-only t ))
325
+ (unless (= (point ) (point-min ))
326
+ (put-text-property (1- (point )) (point ) 'prompt t ))))
313
327
(let ((marker (setq-local haskell-interactive-mode-prompt-start (make-marker ))))
314
328
(set-marker marker (point )))
315
329
(when haskell-interactive-mode-scroll-to-bottom
@@ -322,16 +336,13 @@ SESSION, otherwise operate on the current buffer."
322
336
(let ((prop-text (propertize text
323
337
'font-lock-face 'haskell-interactive-face-result
324
338
'front-sticky t
325
- 'prompt t
326
339
'read-only t
327
340
'rear-nonsticky t
328
341
'result t )))
329
342
(when (string= text haskell-interactive-prompt2)
330
- (put-text-property 0
331
- (length haskell-interactive-prompt2)
332
- 'font-lock-face
333
- 'haskell-interactive-face-prompt2
334
- prop-text))
343
+ (setq prop-text (propertize prop-text
344
+ 'font-lock-face 'haskell-interactive-face-prompt2
345
+ 'prompt2 t )))
335
346
(insert (ansi-color-apply prop-text))
336
347
(haskell-interactive-mode-handle-h)
337
348
(let ((marker (setq-local haskell-interactive-mode-result-end (make-marker ))))
@@ -973,20 +984,34 @@ don't care when the thing completes as long as it's soonish."
973
984
(setq haskell-interactive-mode-history-index 0 )
974
985
(haskell-interactive-mode-history-toggle -1 ))))
975
986
976
- (defun haskell-interactive-mode-prompt-previous ()
977
- " Jump to the previous prompt."
978
- (interactive )
979
- (let ((prev-prompt-pos
980
- (save-excursion
981
- (beginning-of-line ) ; ; otherwise prompt at current line matches
982
- (and (search-backward-regexp (haskell-interactive-prompt-regex) nil t )
983
- (match-end 0 )))))
984
- (when prev-prompt-pos (goto-char prev-prompt-pos))))
985
-
986
- (defun haskell-interactive-mode-prompt-next ()
987
- " Jump to the next prompt."
988
- (interactive )
989
- (search-forward-regexp (haskell-interactive-prompt-regex) nil t ))
987
+ (defun haskell-interactive-mode-prompt-previous (&optional arg )
988
+ " Jump to the ARGth previous prompt."
989
+ (interactive " p" )
990
+ (if (< arg 0 )
991
+ (haskell-interactive-mode-prompt-next (- arg))
992
+ (end-of-line 1 )
993
+ (unless (or (get-text-property (1- (point )) 'prompt )
994
+ (zerop arg))
995
+ (cl-incf arg 0.5 )) ; do it an extra time if not at a prompt
996
+ (dotimes (_ (* 2 arg))
997
+ (goto-char (or (previous-single-property-change (point ) 'prompt )
998
+ (point ))))
999
+ (when (get-text-property (point ) 'prompt )
1000
+ ; ; went too far (at first prompt)
1001
+ (goto-char (next-single-property-change (point ) 'prompt )))))
1002
+
1003
+ (defun haskell-interactive-mode-prompt-next (&optional arg )
1004
+ " Jump to the ARGth next prompt."
1005
+ (interactive " p" )
1006
+ (if (< arg 0 )
1007
+ (haskell-interactive-mode-prompt-previous (- arg))
1008
+ (when (and (get-text-property (point ) 'prompt )
1009
+ (not (zerop arg)))
1010
+ ; ; don't start on a prompt
1011
+ (haskell-interactive-mode-prompt-previous 1 ))
1012
+ (dotimes (_ (* 2 arg))
1013
+ (goto-char (or (next-single-property-change (point ) 'prompt )
1014
+ (point-max ))))))
990
1015
991
1016
(defun haskell-interactive-mode-clear ()
992
1017
" Clear the screen and put any current input into the history."
@@ -1054,14 +1079,15 @@ If there is one, pop that up in a buffer, similar to `debug-on-error'."
1054
1079
(with-current-buffer (haskell-session-interactive-buffer session)
1055
1080
(save-excursion
1056
1081
(haskell-interactive-mode-goto-end-point)
1057
- (insert (if mode
1058
- (haskell-fontify-as-mode
1059
- (concat message " \n " )
1060
- mode)
1061
- (propertize (concat message " \n " )
1062
- 'front-sticky t
1063
- 'read-only t
1064
- 'rear-nonsticky t ))))))
1082
+ (let ((inhibit-read-only t ))
1083
+ (insert (if mode
1084
+ (haskell-fontify-as-mode
1085
+ (concat message " \n " )
1086
+ mode)
1087
+ (propertize (concat message " \n " )
1088
+ 'front-sticky t
1089
+ 'read-only t
1090
+ 'rear-nonsticky t )))))))
1065
1091
1066
1092
(defun haskell-interactive-mode-splices-buffer (session )
1067
1093
" Get the splices buffer for the current SESSION."
0 commit comments