Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions haskell-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,35 @@
"Run the given expression."
(let ((session (haskell-interactive-session))
(process (haskell-interactive-process)))
(haskell-process-queue-command
process
(make-haskell-command
:state (list session process expr 0)
:go (lambda (state)
(goto-char (point-max))
(insert "\n")
(setq haskell-interactive-mode-result-end
(point-max))
(haskell-process-send-string (cadr state)
(haskell-interactive-mode-multi-line (cl-caddr state)))
(haskell-process-set-evaluating (cadr state) t))
:live (lambda (state buffer)
(unless (and (string-prefix-p ":q" (cl-caddr state))
(string-prefix-p (cl-caddr state) ":quit"))
(let* ((cursor (cl-cadddr state))
(next (replace-regexp-in-string
haskell-process-prompt-regex
""
(substring buffer cursor))))
(haskell-interactive-mode-eval-result (car state) next)
(setf (cl-cdddr state) (list (length buffer)))
nil)))
:complete
(lambda (state response)
(haskell-process-set-evaluating (cadr state) nil)
(unless (haskell-interactive-mode-trigger-compile-error state response)
(haskell-interactive-mode-expr-result state response)))))))
(with-current-buffer (haskell-session-interactive-buffer session)
(haskell-process-queue-command
process
(make-haskell-command
:state (list session process expr 0)
:go (lambda (state)
(goto-char (point-max))
(insert "\n")
(setq haskell-interactive-mode-result-end
(point-max))
(haskell-process-send-string (cadr state)
(haskell-interactive-mode-multi-line (cl-caddr state)))
(haskell-process-set-evaluating (cadr state) t))
:live (lambda (state buffer)
(unless (and (string-prefix-p ":q" (cl-caddr state))
(string-prefix-p (cl-caddr state) ":quit"))
(let* ((cursor (cl-cadddr state))
(next (replace-regexp-in-string
haskell-process-prompt-regex
""
(substring buffer cursor))))
(haskell-interactive-mode-eval-result (car state) next)
(setf (cl-cdddr state) (list (length buffer)))
nil)))
:complete
(lambda (state response)
(haskell-process-set-evaluating (cadr state) nil)
(unless (haskell-interactive-mode-trigger-compile-error state response)
(haskell-interactive-mode-expr-result state response))))))))

(defun haskell-interactive-mode-expr-result (state response)
"Print the result of evaluating the expression."
Expand Down
7 changes: 7 additions & 0 deletions haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
(defvar interactive-haskell-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-l") 'haskell-process-load-file)
(define-key map (kbd "C-c RET") 'haskell-load-and-run) ;; == C-c C-m
(define-key map (kbd "C-c C-r") 'haskell-process-reload)
(define-key map (kbd "C-c C-t") 'haskell-process-do-type)
(define-key map (kbd "C-c C-i") 'haskell-process-do-info)
Expand Down Expand Up @@ -397,6 +398,12 @@ Give optional NEXT-P parameter to override value of
nil
(current-buffer)))

(defun haskell-load-and-run ()
"Loads the current buffer and runs the main function."
(interactive)
(haskell-process-load-file)
(haskell-interactive-mode-run-expr "main"))

;;;###autoload
(defun haskell-process-reload ()
"Re-load the current buffer file."
Expand Down
Loading