Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support rendering REPL results font-lock'd according to a given mode.

Example: (setq haskell-interactive-mode-eval-mode 'espresso-mode)
  • Loading branch information...
commit 8bb9da009f5d983e69c0b417cf6aff76c1ccb2d5 1 parent d0d1046
Chris Done chrisdone authored
Showing with 32 additions and 3 deletions.
  1. +32 −3 haskell-interactive-mode.el
35 haskell-interactive-mode.el
View
@@ -37,6 +37,12 @@
(defvar haskell-interactive-prompt "λ> "
"The prompt to use.")
+(defcustom haskell-interactive-mode-eval-mode
+ nil
+ "Use the given mode's font-locking to render some text."
+ :type 'boolean
+ :group 'haskell)
+
(defvar haskell-interactive-greetings
(list "Hello, Haskell!"
"The lambdas must flow."
@@ -166,14 +172,16 @@
(setf (cdddr state) (list (length buffer)))
nil)))
(lambda (state response)
- (when haskell-interactive-mode-eval-pretty
- (haskell-interactive-mode-eval-pretty-result (car state) response))
+ (if haskell-interactive-mode-eval-mode
+ (haskell-interactive-mode-eval-as-mode (car state) response)
+ (when haskell-interactive-mode-eval-pretty
+ (haskell-interactive-mode-eval-pretty-result (car state) response)))
(haskell-interactive-mode-prompt (car state)))))))))
(defun haskell-interactive-jump-to-error-line ()
"Jump to the error line."
(let ((orig-line (buffer-substring-no-properties (line-beginning-position)
- (line-end-position))))
+ (line-end-position))))
(and (string-match "^\\([^:]+\\):\\([0-9]+\\):\\([0-9]+\\):" orig-line)
(let ((file (match-string 1 orig-line))
(line (match-string 2 orig-line))
@@ -254,6 +262,27 @@
'prompt t
'result t))))
+(defun haskell-interactive-mode-eval-as-mode (session text)
+ "Insert the result of an eval as a pretty printed Showable, if
+ parseable, or otherwise just as-is."
+ (with-current-buffer (haskell-session-interactive-buffer session)
+ (let ((start-point (save-excursion (search-backward-regexp haskell-interactive-prompt)
+ (forward-line 1)
+ (point)))
+ (inhibit-read-only t))
+ (delete-region start-point (point))
+ (goto-char (point-max))
+ (insert (let ((mode haskell-interactive-mode-eval-mode))
+ (with-current-buffer (get-buffer-create (concat "*print-" (symbol-name mode) "*"))
+ (unless (eq major-mode mode)
+ (funcall mode))
+ (erase-buffer)
+ (insert text)
+ (font-lock-fontify-region (point-min) (point-max))
+ (buffer-substring (point-min)
+ (point-max)))))
+ (insert "\n"))))
+
(defun haskell-interactive-mode-eval-pretty-result (session text)
"Insert the result of an eval as a pretty printed Showable, if
parseable, or otherwise just as-is."
Please sign in to comment.
Something went wrong with that request. Please try again.