Skip to content

Commit 6431491

Browse files
committed
Merge pull request #457 from cmears/copy-to-prompt
Add haskell-interactive-copy-to-prompt.
2 parents 560859a + 8f63011 commit 6431491

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

haskell-interactive-mode.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ be nil.")
180180
(switch-to-buffer-other-window haskell-interactive-previous-buffer)
181181
(message "No previous buffer.")))
182182

183+
(defun haskell-interactive-copy-to-prompt ()
184+
"Copy the current line to the prompt, overwriting the current
185+
prompt."
186+
(interactive)
187+
(let ((l (buffer-substring-no-properties (line-beginning-position)
188+
(line-end-position))))
189+
;; If it looks like the prompt is at the start of the line, chop
190+
;; it off.
191+
(when (and (>= (length l) (length haskell-interactive-prompt))
192+
(string= (substring l 0 (length haskell-interactive-prompt))
193+
haskell-interactive-prompt))
194+
(setq l (substring l (length haskell-interactive-prompt))))
195+
196+
(haskell-interactive-mode-set-prompt l)))
197+
183198
(defun haskell-interactive-mode-space (n)
184199
"Handle the space key."
185200
(interactive "p")

haskell.el

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,17 @@
125125
"Handle the return key."
126126
(interactive)
127127
(cond
128+
;; At a compile message, jump to the location of the error in the
129+
;; source.
128130
((haskell-interactive-at-compile-message)
129131
(next-error-internal))
132+
;; At the input prompt, handle the expression in the usual way.
133+
((haskell-interactive-at-prompt)
134+
(haskell-interactive-handle-expr))
135+
;; At any other location in the buffer, copy the line to the
136+
;; current prompt.
130137
(t
131-
(haskell-interactive-handle-expr))))
138+
(haskell-interactive-copy-to-prompt))))
132139

133140
;;;###autoload
134141
(defun haskell-session-kill (&optional leave-interactive-buffer)

0 commit comments

Comments
 (0)