Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 line
3.5 KiB

5 年之前
  1. ;;; haskell-presentation-mode.el --- Presenting Haskell things -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2013 Chris Done
  3. ;; Author: Chris Done <chrisdone@gmail.com>
  4. ;; This file is not part of GNU Emacs.
  5. ;; This file is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation; either version 3, or (at your option)
  8. ;; any later version.
  9. ;; This file is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs; see the file COPYING. If not, write to
  15. ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. ;; Boston, MA 02110-1301, USA.
  17. ;;; Commentary:
  18. ;;; Code:
  19. (require 'haskell-mode)
  20. (require 'haskell-session)
  21. (defvar haskell-presentation-mode-map
  22. (let ((map (make-sparse-keymap)))
  23. (define-key map (kbd "q") 'quit-window)
  24. (define-key map (kbd "c") 'haskell-presentation-clear)
  25. map)
  26. "Keymap for `haskell-presentation-mode'.")
  27. (define-derived-mode haskell-presentation-mode
  28. haskell-mode "Presentation"
  29. "Major mode for viewing Haskell snippets.
  30. \\{hypertext-mode-map}"
  31. (setq case-fold-search nil))
  32. (defconst haskell-presentation-buffer-name
  33. "*Haskell Presentation*"
  34. "Haskell Presentation buffer name.")
  35. (defconst haskell-presentation-hint-message
  36. "-- Hit `q' to close this window; `c' to clear.\n\n"
  37. "Hint message appered in Haskell Presentation buffer.")
  38. (defun haskell-presentation-buffer ()
  39. "Return Haskell Presentaion buffer.
  40. Return current presenation buffer or create new one if absent.
  41. Never returns nil."
  42. ;; TODO Provide interactive calling options: when called interactively make
  43. ;; the presentation buffer current.
  44. (let ((may-buffer (get-buffer haskell-presentation-buffer-name)))
  45. (if may-buffer
  46. may-buffer
  47. (let ((buffer (generate-new-buffer haskell-presentation-buffer-name)))
  48. (with-current-buffer buffer
  49. (insert haskell-presentation-hint-message)
  50. (haskell-presentation-mode)
  51. (setq buffer-read-only t))
  52. buffer))))
  53. (defun haskell-presentation-clear ()
  54. "Clear Haskell Presentation buffer."
  55. (interactive)
  56. (let ((hp-buf (get-buffer haskell-presentation-buffer-name)))
  57. (when hp-buf
  58. (with-current-buffer hp-buf
  59. (let ((buffer-read-only nil))
  60. (erase-buffer)
  61. (insert haskell-presentation-hint-message))))))
  62. (defun haskell-presentation-present (session code &optional clear)
  63. "Present given code in a popup buffer.
  64. Creates temporal Haskell Presentation buffer and assigns it to
  65. given haskell SESSION; presented CODE will be fontified as
  66. haskell code. Give an optional non-nil CLEAR arg to clear the
  67. buffer before presenting message."
  68. (let ((buffer (haskell-presentation-buffer)))
  69. (with-current-buffer buffer
  70. (when (boundp 'shm-display-quarantine)
  71. (setq-local shm-display-quarantine nil))
  72. (when clear (haskell-presentation-clear))
  73. (haskell-session-assign session)
  74. (goto-char (point-min))
  75. (forward-line 2)
  76. (save-excursion
  77. (let ((buffer-read-only nil))
  78. (insert code "\n\n"))))
  79. (if (eq major-mode 'haskell-presentation-mode)
  80. (switch-to-buffer buffer)
  81. (pop-to-buffer buffer))))
  82. (provide 'haskell-presentation-mode)
  83. ;;; haskell-presentation-mode.el ends here