Skip to content

Commit 862309b

Browse files
committed
Merge pull request haskell#613 from geraldus/simple-echo
Tidy up `haskell-present` and `haskell-process-do-simple-echo` according to haskell#607
2 parents 18da298 + 6e272dd commit 862309b

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

haskell-commands.el

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ If PROMPT-VALUE is non-nil, request identifier via mini-buffer."
300300
(or ident
301301
at-point))))))
302302
(when command
303-
(haskell-process-do-simple-echo command 'haskell-mode))))))
303+
(haskell-process-show-repl-response command))))))
304304

305305
;;;###autoload
306306
(defun haskell-process-do-type (&optional insert-value)
@@ -318,14 +318,13 @@ If PROMPT-VALUE is non-nil, request identifier via mini-buffer."
318318
;; No newlines in expressions, and surround with parens if it
319319
;; might be a slice expression
320320
(when expr-okay
321-
(haskell-process-do-simple-echo
321+
(haskell-process-show-repl-response
322322
(format
323323
(if (or (string-match-p "\\`(" expr)
324-
(string-match-p "\\`[_[:alpha:]]" expr))
324+
(string-match-p "\\`[_[:alpha:]]" expr))
325325
":type %s"
326326
":type (%s)")
327-
expr)
328-
'haskell-mode)))))
327+
expr))))))
329328

330329
;;;###autoload
331330
(defun haskell-mode-jump-to-def-or-tag (&optional next-p)

haskell-interactive-mode.el

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,30 +1094,23 @@ don't care when the thing completes as long as it's soonish."
10941094
'rear-nonsticky t)))))
10951095

10961096
;;;###autoload
1097-
(defun haskell-process-do-simple-echo (line &optional mode)
1098-
"Send LINE to the GHCi process and echo the result in some
1099-
fashion, such as printing in the minibuffer, or using
1100-
haskell-present, depending on configuration."
1097+
(defun haskell-process-show-repl-response (line)
1098+
"Send LINE to the GHCi process and echo the result in some fashion.
1099+
Result will be printed in the minibuffer or presented using
1100+
haskell-present, depending on variable `haskell-process-use-presentation-mode'."
11011101
(let ((process (haskell-interactive-process)))
11021102
(haskell-process-queue-command
11031103
process
11041104
(make-haskell-command
1105-
:state (list process line mode)
1105+
:state (cons process line)
11061106
:go (lambda (state)
1107-
(haskell-process-send-string (car state) (cadr state)))
1107+
(haskell-process-send-string (car state) (cdr state)))
11081108
:complete (lambda (state response)
1109-
;; TODO: TBD: don't do this if
1110-
;; `haskell-process-use-presentation-mode' is t.
1111-
(haskell-interactive-mode-echo
1112-
(haskell-process-session (car state))
1113-
(replace-regexp-in-string "\n\\'" "" response)
1114-
(cl-caddr state))
11151109
(if haskell-process-use-presentation-mode
1116-
(progn (haskell-present (cadr state)
1117-
(haskell-process-session (car state))
1118-
response)
1119-
(haskell-session-assign
1120-
(haskell-process-session (car state))))
1110+
(haskell-present
1111+
(cdr state)
1112+
(haskell-process-session (car state))
1113+
response)
11211114
(haskell-mode-message-line response)))))))
11221115

11231116
(provide 'haskell-interactive-mode)

haskell-presentation-mode.el

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
;;; Code:
2727

2828
(require 'haskell-mode)
29+
(require 'haskell-session)
2930

3031
(define-derived-mode haskell-presentation-mode
3132
haskell-mode "Presentation"
@@ -36,23 +37,25 @@
3637
(define-key haskell-presentation-mode-map (kbd "q") 'quit-window)
3738

3839
(defun haskell-present (name session code)
39-
"Present CODE in a popup buffer suffixed with NAME and set
40-
SESSION as the current haskell-session."
41-
(let* ((name (format "*Haskell Presentation%s*" name))
42-
(buffer (get-buffer-create name)))
40+
"Present given code in a popup buffer.
41+
Creates temporal buffer with given NAME and assigns it to given
42+
haskell SESSION; presented CODE will be fontified as haskell code."
43+
(let ((buffer (get-buffer-create name)))
4344
(with-current-buffer buffer
4445
(haskell-presentation-mode)
45-
(if (boundp 'shm-display-quarantine)
46-
(set (make-local-variable 'shm-display-quarantine) nil))
47-
(let ((buffer-read-only nil))
46+
47+
(when (boundp 'shm-display-quarantine)
48+
(set (make-local-variable 'shm-display-quarantine) nil))
49+
50+
(let ((buffer-read-only nil)
51+
(hint "-- Hit `q' to close this window.\n\n"))
52+
(haskell-session-assign session)
4853
(erase-buffer)
49-
(insert (propertize "-- Hit `q' to close this window.\n\n"
50-
'face
51-
'font-lock-comment-face))
52-
(let ((point (point)))
53-
(insert code "\n\n")
54-
(font-lock-fontify-region point (point))
55-
(goto-char point))))
54+
(insert hint)
55+
(save-excursion
56+
(insert code "\n\n")))
57+
(setq buffer-read-only t))
58+
5659
(if (eq major-mode 'haskell-presentation-mode)
5760
(switch-to-buffer buffer)
5861
(pop-to-buffer buffer))))

haskell-session.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@
8787
"haskell")))
8888

8989
(defun haskell-session-assign (session)
90-
"Set the current session."
90+
"Assing current buffer to SESSION.
91+
More verbose doc string for `haskell-session-assign`
92+
This could be helpfull for temporal or auxilar buffers such as
93+
presentation mode buffers (e.g. in case when session is killed
94+
with all relevant buffers)."
9195
(set (make-local-variable 'haskell-session) session))
9296

9397
(defun haskell-session-choose ()

0 commit comments

Comments
 (0)