Skip to content

Commit b4fe973

Browse files
committed
Clean up multi-line in haskell-interactive a bit
* Using indent-relative explicitly disables some unwanted heuristics that indent-according-to-mode uses. I've found that this way is better, but it could certainly use improvement. * Make haskell-interactive-mode-multi-line properly indent the expression. * haskell-interactive-mode-cleanup-response is now useless as far as I can tell.
1 parent 32207ac commit b4fe973

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

haskell-interactive-mode.el

+13-31
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ be nil.")
167167
"Make newline and indent."
168168
(interactive)
169169
(newline)
170-
(indent-according-to-mode))
170+
(indent-to (length haskell-interactive-prompt))
171+
(indent-relative))
171172

172173
(defun haskell-interactive-mode-kill-whole-line ()
173174
"Kill the whole REPL line."
@@ -236,22 +237,6 @@ be nil.")
236237
(point-min))
237238
end))))))))
238239

239-
(defun haskell-interactive-mode-cleanup-response (expr response)
240-
"Ignore the mess that GHCi outputs on multi-line input."
241-
(if (not (string-match "\n" expr))
242-
response
243-
(let ((i 0)
244-
(out "")
245-
(lines (length (split-string expr "\n"))))
246-
(cl-loop for part in (split-string response "| ")
247-
do (setq out
248-
(concat out
249-
(if (> i lines)
250-
(concat (if (or (= i 0) (= i (1+ lines))) "" "| ") part)
251-
"")))
252-
do (setq i (1+ i)))
253-
out)))
254-
255240
(defun haskell-interactive-mode-multi-line (expr)
256241
"If a multi-line expression EXPR has been entered, then reformat it to be:
257242
@@ -260,21 +245,18 @@ do the
260245
multi-liner
261246
expr
262247
:}"
263-
(if (not (string-match "\n" expr))
248+
(if (not (string-match-p "\n" expr))
264249
expr
265-
(let* ((i 0)
266-
(lines (split-string expr "\n"))
267-
(len (length lines)))
268-
(mapconcat 'identity
269-
(cl-loop for line in lines
270-
collect (cond ((= i 0)
271-
(concat ":{" "\n" line))
272-
((= i (1- len))
273-
(concat line "\n" ":}"))
274-
(t
275-
line))
276-
do (setq i (1+ i)))
277-
"\n"))))
250+
(let ((len (length haskell-interactive-prompt))
251+
(lines (split-string expr "\n")))
252+
(cl-loop for elt on (cdr lines) do
253+
(setcar elt (substring (car elt) len)))
254+
;; Temporarily set prompt2 to be empty to avoid unwanted output
255+
(concat ":set prompt2 \"\"\n"
256+
":{\n"
257+
(mapconcat #'identity lines "\n")
258+
"\n:}\n"
259+
(format ":set prompt2 \"%s\"" haskell-interactive-prompt2)))))
278260

279261
(defun haskell-interactive-trim (line)
280262
"Trim indentation off of LINE in the REPL."

haskell-repl.el

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@
101101
"Print the result of evaluating the expression."
102102
(let ((response
103103
(with-temp-buffer
104-
(insert (haskell-interactive-mode-cleanup-response
105-
(cl-caddr state) response))
104+
(insert response)
106105
(haskell-interactive-mode-handle-h)
107106
(buffer-string))))
108107
(when haskell-interactive-mode-eval-mode

0 commit comments

Comments
 (0)