-
Notifications
You must be signed in to change notification settings - Fork 5
/
slime-info.el
168 lines (142 loc) · 6.52 KB
/
slime-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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
;;; slime-info --- Slime info -*- lexical-binding: t -*-
;; Copyright (C) 2021 Mariano Montone
;; Author: Mariano Montone <[email protected]>
;; URL: https://github.com/mmontone/slime-doc-contribs
;; Keywords: help, lisp, slime, common-lisp
;; Version: 0.1
;; Package-Requires: ((emacs "25"))
;; 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 is a package
;;; Code:
(require 'slime)
(require 'slime-asdf)
(require 'info)
(require 'texinfo)
(defun bury-compile-buffer-if-successful (buffer string)
"Bury a compilation buffer if succeeded without warnings."
(if (and
(string-match "compilation" (buffer-name buffer))
(string-match "finished" string)
(not
(with-current-buffer buffer
**(goto-char 1)**
(search-forward "warning" nil t))))
(run-with-timer 1 nil
(lambda (buf)
(bury-buffer buf)
(switch-to-prev-buffer (get-buffer-window buf) 'kill))
buffer)))
(defun slime-info/display-info-buffer (texinfo-source)
"Display TEXINFO-SOURCE in an Info buffer."
(let ((temp-file (make-temp-file "slime-info-")))
(with-temp-file temp-file
(insert texinfo-source))
(let ((buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(makeinfo-buffer)
;;(kill-buffer (get-buffer "*compilation*"))
;;(delete-window (get-buffer-window (get-buffer "*compilation*")))
;; Setup timer to kill *compilation* buffer after a second.
(unless slime-info-debug
(run-with-timer 1 nil
(lambda ()
(kill-buffer (get-buffer "*compilation*")))))
(display-buffer buffer)))))
(defun slime-info-symbol (symbol-name)
"Show a buffer with description of SYMBOL-NAME in an Info buffer."
(interactive (list (slime-read-symbol-name "Symbol: ")))
(when (not symbol-name)
(error "No symbol name given"))
(let ((texinfo-source (slime-eval `(swank-info:texinfo-source-for-symbol ,symbol-name))))
(slime-info/display-info-buffer texinfo-source)))
(defun slime-info-package (package-name)
"Show information about Common Lisp package named PACKAGE-NAME, using an Info buffer."
(interactive (list (slime-read-package-name "Package name: ")))
(when (not package-name)
(error "No package name given"))
(let ((texinfo-source (slime-eval `(swank-info:texinfo-source-for-package ,package-name))))
(slime-info/display-info-buffer texinfo-source)))
(defun slime-info-system (system-name)
"Show information about Common Lisp ASDF system named SYSTEM-NAME, using an Info buffer."
(interactive (list (slime-read-system-name "System name")))
(when (not system-name)
(error "No ASDF system name given"))
(let ((texinfo-source (slime-eval `(swank-info:texinfo-source-for-system ,system-name :use-pandoc ,slime-info-use-pandoc))))
(slime-info/display-info-buffer texinfo-source)))
;; (defun slime-info-apropos (symbol-name)
;; (interactive (list (slime-read-symbol-name "Apropos symbol info: ")))
;; (when (not symbol-name)
;; (error "No symbol given"))
;; (if (position 58 symbol-name) ;; 58 is the colon character
;; (info-apropos symbol-name)
;; (let* ((symbol-package-name
;; (slime-eval
;; `(cl:package-name
;; (cl:symbol-package (cl:read-from-string ,(concat (remove 58 (slime-current-package)) "::" symbol-name))))))
;; (index-entry (concat symbol-package-name ":" symbol-name)))
;; (info-apropos index-entry))))
(defun slime-info-apropos (string &optional only-external-p package
case-sensitive-p)
"Show all bound symbols whose names match STRING.
With prefix arg, you're interactively asked for parameters of the search.
ONLY-EXTERNAL-P: apropos only external symbols.
PACKAGE: package to apropos.
CASE-SENSITIVE-P: toggle case sensitiveness."
(interactive
(if current-prefix-arg
(list (read-string "SLIME Apropos: ")
(y-or-n-p "External symbols only? ")
(let ((pkg (slime-read-package-name "Package: ")))
(if (string= pkg "") nil pkg))
(y-or-n-p "Case-sensitive? "))
(list (read-string "SLIME Apropos: ") t nil nil)))
(let ((buffer-package (or package (slime-current-package))))
(let ((texinfo-source (slime-eval `(swank-info:texinfo-source-for-apropos ,string ,only-external-p ,case-sensitive-p ',package))))
(slime-info/display-info-buffer texinfo-source))))
(defun slime-info-apropos-all ()
"Shortcut for (slime-apropos <string> nil nil)."
(interactive)
(slime-info-apropos (read-string "SLIME Apropos: ") nil nil))
(defun slime-info-apropos-package (package &optional internal)
"Show apropos listing for symbols in PACKAGE.
With prefix argument include internal symbols.
INTERNAL: whether to include package internal symbols."
(interactive (list (let ((pkg (slime-read-package-name "Package: ")))
(if (string= pkg "") (slime-current-package) pkg))
current-prefix-arg))
(slime-info-apropos "" (not internal) package))
(define-slime-contrib slime-info
"Online Common Lisp documentation via Emacs Info."
(:authors "Mariano Montone <[email protected]>")
(:license "GPL")
(:slime-dependencies slime-asdf)
(:swank-dependencies swank-info))
;;; Utilities
(defgroup slime-info nil
"Show Lisp documentation using Info"
:prefix "slime-info-"
:group 'slime)
(defcustom slime-info-debug nil
"Toggle slime-info debug mode"
:type 'boolean
:group 'slime-info)
(defcustom slime-info-use-pandoc t
"When enabled, pandoc is used for processing ASDF system docs when available"
:type 'boolean
:group 'slime-info)
(defcustom slime-info-parse-docstrings t
"When enabled, docstrings are parsed and function arguments and code references are formatted accordingly."
:type 'boolean
:group 'slime-info)
(provide 'slime-info)
;;; slime-info.el ends here