forked from haskell/haskell-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
haskell-presentation-mode.el
69 lines (55 loc) · 2.28 KB
/
haskell-presentation-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;; haskell-presentation-mode.el --- Presenting Haskell things
;; Copyright (C) 2013 Chris Done
;; Author: Chris Done <[email protected]>
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;; Code:
(require 'haskell-mode)
(defvar haskell-presentation-mode-keymap
(let ((map (make-keymap)))
(suppress-keymap map)
(define-key map (kbd "q") 'quit-window)
map)
"Key map for the presentation mode.")
(define-minor-mode haskell-presentation-mode
"Mode for presenting Haskell values."
:lighter "-Presentation"
:keymap haskell-presentation-mode-keymap
(setq buffer-read-only t))
(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)))
(with-current-buffer buffer
(unless (eq major-mode 'haskell-mode)
(haskell-mode)
(haskell-presentation-mode)
(font-lock-mode -1))
(let ((buffer-read-only nil))
(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))))
(if (and (boundp 'haskell-presentation-mode)
haskell-presentation-mode)
(switch-to-buffer buffer)
(pop-to-buffer buffer))))
(provide 'haskell-presentation-mode)
;;; haskell-presentation-mode.el ends here