@@ -247,7 +247,9 @@ do the
247247:}"
248248 (if (not (string-match-p " \n " expr))
249249 expr
250- (let ((len (length haskell-interactive-prompt))
250+ (let ((len (if haskell-interactive-use-interactive-prompt
251+ (length haskell-interactive-prompt)
252+ (length (last (split-string haskell-interactive-prompt " \n " )))))
251253 (lines (split-string expr " \n " )))
252254 (cl-loop for elt on (cdr lines) do
253255 (setcar elt (substring (car elt) len)))
@@ -295,21 +297,30 @@ do the
295297(defun haskell-interactive-mode-prompt (&optional session )
296298 " Show a prompt at the end of the REPL buffer.
297299If SESSION is non-nil, use the REPL buffer associated with
298- SESSION, otherwise operate on the current buffer."
300+ SESSION, otherwise operate on the current buffer. The prompt
301+ inserted is specified by `haskell-interactive-prompt' .
302+ When `haskell-interactive-use-interactive-prompt' is non-nil,
303+ the prompt is inserted in this function. Otherwise it was already
304+ set in the `haskell-process-send-startup' and has already been
305+ inserted in the buffer by the process."
299306 (with-current-buffer (if session
300307 (haskell-session-interactive-buffer session)
301308 (current-buffer ))
302309 (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 )))
310+ (if haskell-interactive-use-interactive-prompt
311+ (let ((prompt (propertize haskell-interactive-prompt
312+ 'font-lock-face 'haskell-interactive-face-prompt
313+ 'prompt t
314+ 'read-only t
315+ 'rear-nonsticky t )))
316+ ; ; At the time of writing, front-stickying the first char gives an error
317+ ; ; Has unfortunate side-effect of being able to insert before the prompt
318+ (insert (substring prompt 0 1 )
319+ (propertize (substring prompt 1 )
320+ 'front-sticky t )))
321+ (let ((inhibit-read-only t ))
322+ (unless (= (point ) (point-min ))
323+ (put-text-property (1- (point )) (point ) 'prompt t ))))
313324 (let ((marker (setq-local haskell-interactive-mode-prompt-start (make-marker ))))
314325 (set-marker marker (point )))
315326 (when haskell-interactive-mode-scroll-to-bottom
@@ -322,16 +333,13 @@ SESSION, otherwise operate on the current buffer."
322333 (let ((prop-text (propertize text
323334 'font-lock-face 'haskell-interactive-face-result
324335 'front-sticky t
325- 'prompt t
326336 'read-only t
327337 'rear-nonsticky t
328338 'result t )))
329339 (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))
340+ (setq prop-text (propertize prop-text
341+ 'font-lock-face 'haskell-interactive-face-prompt2
342+ 'prompt2 t )))
335343 (insert (ansi-color-apply prop-text))
336344 (haskell-interactive-mode-handle-h)
337345 (let ((marker (setq-local haskell-interactive-mode-result-end (make-marker ))))
@@ -973,20 +981,34 @@ don't care when the thing completes as long as it's soonish."
973981 (setq haskell-interactive-mode-history-index 0 )
974982 (haskell-interactive-mode-history-toggle -1 ))))
975983
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 ))
984+ (defun haskell-interactive-mode-prompt-previous (&optional arg )
985+ " Jump to the ARGth previous prompt."
986+ (interactive " p" )
987+ (if (< arg 0 )
988+ (haskell-interactive-mode-prompt-next (- arg))
989+ (end-of-line 1 )
990+ (unless (or (get-text-property (1- (point )) 'prompt )
991+ (zerop arg))
992+ (cl-incf arg 0.5 )) ; do it an extra time if not at a prompt
993+ (dotimes (_ (* 2 arg))
994+ (goto-char (or (previous-single-property-change (point ) 'prompt )
995+ (point ))))
996+ (when (get-text-property (point ) 'prompt )
997+ ; ; went too far (at first prompt)
998+ (goto-char (next-single-property-change (point ) 'prompt )))))
999+
1000+ (defun haskell-interactive-mode-prompt-next (&optional arg )
1001+ " Jump to the ARGth next prompt."
1002+ (interactive " p" )
1003+ (if (< arg 0 )
1004+ (haskell-interactive-mode-prompt-previous (- arg))
1005+ (when (and (get-text-property (point ) 'prompt )
1006+ (not (zerop arg)))
1007+ ; ; don't start on a prompt
1008+ (haskell-interactive-mode-prompt-previous 1 ))
1009+ (dotimes (_ (* 2 arg))
1010+ (goto-char (or (next-single-property-change (point ) 'prompt )
1011+ (point-max ))))))
9901012
9911013(defun haskell-interactive-mode-clear ()
9921014 " Clear the screen and put any current input into the history."
@@ -1054,14 +1076,15 @@ If there is one, pop that up in a buffer, similar to `debug-on-error'."
10541076 (with-current-buffer (haskell-session-interactive-buffer session)
10551077 (save-excursion
10561078 (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 ))))))
1079+ (let ((inhibit-read-only t ))
1080+ (insert (if mode
1081+ (haskell-fontify-as-mode
1082+ (concat message " \n " )
1083+ mode)
1084+ (propertize (concat message " \n " )
1085+ 'front-sticky t
1086+ 'read-only t
1087+ 'rear-nonsticky t )))))))
10651088
10661089(defun haskell-interactive-mode-splices-buffer (session )
10671090 " Get the splices buffer for the current SESSION."
0 commit comments