forked from idris-hackers/idris-mode
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidris-info.el
87 lines (66 loc) · 3.02 KB
/
idris-info.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;;; idris-info.el --- Facilities for showing Idris help information -*- lexical-binding: t -*-
;; Copyright (C) 2014 David Raymond Christiansen
;; Author: David Raymond Christiansen <[email protected]>
;; Keywords: languages, tools
;; This program 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 of the License, or
;; (at your option) any later version.
;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This module contains facilities for showing information provided by the
;; Idris compiler in a separate buffer, as well as keeping the irritation of
;; that buffer to a minimum.
;;; Code:
(require 'idris-core)
(require 'idris-common-utils)
(defvar idris-info-buffer-name (idris-buffer-name :info)
"The name of the buffer containing Idris help information")
(defvar idris-info-mode-map
(let ((map (make-keymap)))
(suppress-keymap map) ; remove the self-inserting char commands
(define-key map (kbd "q") 'idris-info-quit)
(define-key map (kbd "C-c C-t") 'idris-type-at-point)
(define-key map (kbd "C-c C-d") 'idris-docs-at-point)
map))
(easy-menu-define idris-info-mode-menu idris-info-mode-map
"Menu for the Idris info buffer"
`("Idris Info"
["Close Idris info buffer" idris-info-quit t]))
(define-derived-mode idris-info-mode fundamental-mode "Idris Info"
"Major mode used for transient Idris information buffers
\\{idris-info-mode-map}
Invokes `idris-info-mode-hook'.")
; if we use view-mode here, our key binding q would be shadowed.
(defun idris-info-buffer ()
"Return the Idris info buffer, creating one if there is not one"
(get-buffer-create idris-info-buffer-name))
(defun idris-info-quit ()
(interactive)
(idris-kill-buffer idris-info-buffer-name))
(defun idris-info-buffer-visible-p ()
(if (get-buffer-window idris-info-buffer-name 'visible) t nil))
(defmacro with-idris-info-buffer (&rest cmds)
`(progn (with-current-buffer (idris-info-buffer)
(idris-info-mode)
(setq buffer-read-only nil)
(erase-buffer)
,@cmds
(setq buffer-read-only t))
(unless (idris-info-buffer-visible-p)
(pop-to-buffer (idris-info-buffer))
(message "Press q to close the Idris info buffer."))))
(defun idris-show-info (info-string &optional spans)
"Show INFO-STRING in the Idris info buffer, obliterating its previous contents."
(with-idris-info-buffer
(idris-propertize-spans (idris-repl-semantic-text-props spans)
(insert info-string))
(insert "\n\n"))
info-string)
(provide 'idris-info)
;;; idris-info.el ends here