Skip to content

Tidy up haskell-present and haskell-process-do-simple-echo according to #607 #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2015
Merged
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
9 changes: 4 additions & 5 deletions haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ If PROMPT-VALUE is non-nil, request identifier via mini-buffer."
(or ident
at-point))))))
(when command
(haskell-process-do-simple-echo command 'haskell-mode))))))
(haskell-process-show-repl-response command))))))

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

;;;###autoload
(defun haskell-mode-jump-to-def-or-tag (&optional next-p)
Expand Down
27 changes: 10 additions & 17 deletions haskell-interactive-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1094,30 +1094,23 @@ don't care when the thing completes as long as it's soonish."
'rear-nonsticky t)))))

;;;###autoload
(defun haskell-process-do-simple-echo (line &optional mode)
"Send LINE to the GHCi process and echo the result in some
fashion, such as printing in the minibuffer, or using
haskell-present, depending on configuration."
(defun haskell-process-show-repl-response (line)
"Send LINE to the GHCi process and echo the result in some fashion.
Result will be printed in the minibuffer or presented using
haskell-present, depending on variable `haskell-process-use-presentation-mode'."
(let ((process (haskell-interactive-process)))
(haskell-process-queue-command
process
(make-haskell-command
:state (list process line mode)
:state (cons process line)
:go (lambda (state)
(haskell-process-send-string (car state) (cadr state)))
(haskell-process-send-string (car state) (cdr state)))
:complete (lambda (state response)
;; TODO: TBD: don't do this if
;; `haskell-process-use-presentation-mode' is t.
(haskell-interactive-mode-echo
(haskell-process-session (car state))
(replace-regexp-in-string "\n\\'" "" response)
(cl-caddr state))
(if haskell-process-use-presentation-mode
(progn (haskell-present (cadr state)
(haskell-process-session (car state))
response)
(haskell-session-assign
(haskell-process-session (car state))))
(haskell-present
(cdr state)
(haskell-process-session (car state))
response)
(haskell-mode-message-line response)))))))

(provide 'haskell-interactive-mode)
Expand Down
31 changes: 17 additions & 14 deletions haskell-presentation-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
;;; Code:

(require 'haskell-mode)
(require 'haskell-session)

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

(defun haskell-present (name session code)
"Present CODE in a popup buffer suffixed with NAME and set
SESSION as the current haskell-session."
(let* ((name (format "*Haskell Presentation%s*" name))
(buffer (get-buffer-create name)))
"Present given code in a popup buffer.
Creates temporal buffer with given NAME and assigns it to given
haskell SESSION; presented CODE will be fontified as haskell code."
(let ((buffer (get-buffer-create name)))
(with-current-buffer buffer
(haskell-presentation-mode)
(if (boundp 'shm-display-quarantine)
(set (make-local-variable 'shm-display-quarantine) nil))
(let ((buffer-read-only nil))

(when (boundp 'shm-display-quarantine)
(set (make-local-variable 'shm-display-quarantine) nil))

(let ((buffer-read-only nil)
(hint "-- Hit `q' to close this window.\n\n"))
(haskell-session-assign session)
(erase-buffer)
(insert (propertize "-- Hit `q' to close this window.\n\n"
'face
'font-lock-comment-face))
(let ((point (point)))
(insert code "\n\n")
(font-lock-fontify-region point (point))
(goto-char point))))
(insert hint)
(save-excursion
(insert code "\n\n")))
(setq buffer-read-only t))

(if (eq major-mode 'haskell-presentation-mode)
(switch-to-buffer buffer)
(pop-to-buffer buffer))))
Expand Down
6 changes: 5 additions & 1 deletion haskell-session.el
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@
"haskell")))

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

(defun haskell-session-choose ()
Expand Down