|
37 | 37 | (defvar haskell-interactive-prompt "λ> "
|
38 | 38 | "The prompt to use.")
|
39 | 39 |
|
| 40 | +(defcustom haskell-interactive-mode-eval-mode |
| 41 | + nil |
| 42 | + "Use the given mode's font-locking to render some text." |
| 43 | + :type 'boolean |
| 44 | + :group 'haskell) |
| 45 | + |
40 | 46 | (defvar haskell-interactive-greetings
|
41 | 47 | (list "Hello, Haskell!"
|
42 | 48 | "The lambdas must flow."
|
|
166 | 172 | (setf (cdddr state) (list (length buffer)))
|
167 | 173 | nil)))
|
168 | 174 | (lambda (state response)
|
169 |
| - (when haskell-interactive-mode-eval-pretty |
170 |
| - (haskell-interactive-mode-eval-pretty-result (car state) response)) |
| 175 | + (if haskell-interactive-mode-eval-mode |
| 176 | + (haskell-interactive-mode-eval-as-mode (car state) response) |
| 177 | + (when haskell-interactive-mode-eval-pretty |
| 178 | + (haskell-interactive-mode-eval-pretty-result (car state) response))) |
171 | 179 | (haskell-interactive-mode-prompt (car state)))))))))
|
172 | 180 |
|
173 | 181 | (defun haskell-interactive-jump-to-error-line ()
|
174 | 182 | "Jump to the error line."
|
175 | 183 | (let ((orig-line (buffer-substring-no-properties (line-beginning-position)
|
176 |
| - (line-end-position)))) |
| 184 | + (line-end-position)))) |
177 | 185 | (and (string-match "^\\([^:]+\\):\\([0-9]+\\):\\([0-9]+\\):" orig-line)
|
178 | 186 | (let ((file (match-string 1 orig-line))
|
179 | 187 | (line (match-string 2 orig-line))
|
|
254 | 262 | 'prompt t
|
255 | 263 | 'result t))))
|
256 | 264 |
|
| 265 | +(defun haskell-interactive-mode-eval-as-mode (session text) |
| 266 | + "Insert the result of an eval as a pretty printed Showable, if |
| 267 | + parseable, or otherwise just as-is." |
| 268 | + (with-current-buffer (haskell-session-interactive-buffer session) |
| 269 | + (let ((start-point (save-excursion (search-backward-regexp haskell-interactive-prompt) |
| 270 | + (forward-line 1) |
| 271 | + (point))) |
| 272 | + (inhibit-read-only t)) |
| 273 | + (delete-region start-point (point)) |
| 274 | + (goto-char (point-max)) |
| 275 | + (insert (let ((mode haskell-interactive-mode-eval-mode)) |
| 276 | + (with-current-buffer (get-buffer-create (concat "*print-" (symbol-name mode) "*")) |
| 277 | + (unless (eq major-mode mode) |
| 278 | + (funcall mode)) |
| 279 | + (erase-buffer) |
| 280 | + (insert text) |
| 281 | + (font-lock-fontify-region (point-min) (point-max)) |
| 282 | + (buffer-substring (point-min) |
| 283 | + (point-max))))) |
| 284 | + (insert "\n")))) |
| 285 | + |
257 | 286 | (defun haskell-interactive-mode-eval-pretty-result (session text)
|
258 | 287 | "Insert the result of an eval as a pretty printed Showable, if
|
259 | 288 | parseable, or otherwise just as-is."
|
|
0 commit comments