Skip to content

Instantly share code, notes, and snippets.

@noprompt
Last active May 1, 2017 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noprompt/56214379faf2fae2599826a31307c1bb to your computer and use it in GitHub Desktop.
Save noprompt/56214379faf2fae2599826a31307c1bb to your computer and use it in GitHub Desktop.
Intero scratch buffer which provides minimal facilities for sending code to the Intero REPL.
(defun intero-scratch-send-paragraph ()
(interactive)
(let* ((source-code-start (save-excursion
(backward-paragraph)
(point)))
(source-code-end (save-excursion
(forward-paragraph)
(point)))
(source-code (buffer-substring-no-properties source-code-start
source-code-end))
(repl-buffer (intero-repl-buffer nil))
(intero-process (get-buffer-process repl-buffer)))
(with-current-buffer repl-buffer
(dolist (line (split-string (concat ":{\n"
(string-trim source-code)
"\n:}")
"\n"))
(goto-char (point-max))
(insert line)
(sleep-for 0 5)
(call-interactively (key-binding (kbd "<RET>")))))))
(defun intero-scratch ()
(interactive)
(let ((maybe-intero-scratch-buffer (get-buffer "*intero-scratch*")))
(if maybe-intero-scratch-buffer
(pop-to-buffer maybe-intero-scratch-buffer)
(let ((intero-scratch-buffer (get-buffer-create "*intero-scratch*")))
(with-current-buffer intero-scratch-buffer
(haskell-font-lock-defaults-create)
(font-lock-mode)
(local-set-key (kbd "C-c C-c") 'intero-scratch-send-paragraph))
(pop-to-buffer inter-scratch-buffer)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment