428
|
1 ;;; hyper-apropos.el --- Hypertext emacs lisp documentation interface.
|
|
2
|
502
|
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
|
428
|
4 ;; Copyright (C) 1994, 1995 Tinker Systems and INS Engineering Corp.
|
|
5 ;; Copyright (C) 1995 Sun Microsystems.
|
|
6 ;; Copyright (C) 1996 Ben Wing.
|
|
7
|
502
|
8 ;; Author: Jonathan Stigelman <stig@xemacs.org>
|
|
9 ;; Maintainer: XEmacs Development Team
|
428
|
10 ;; Keywords: lisp, tools, help, docs, matching
|
|
11
|
|
12 ;; This file is part of XEmacs.
|
|
13
|
|
14 ;; XEmacs is free software; you can redistribute it and/or modify
|
|
15 ;; it under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2 of the License, or
|
|
17 ;; (at your option) any later version.
|
|
18 ;;
|
|
19 ;; XEmacs is distributed in the hope that it will be useful,
|
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;; GNU General Public License for more details.
|
|
23 ;;
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with XEmacs; if not, write to the Free Software
|
|
26 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
27
|
|
28 ;;; Synched up with: Not in FSF.
|
|
29
|
|
30 ;;; Commentary:
|
|
31
|
|
32 ;; based upon emacs-apropos.el by Frank C. Guida <fcg@philabs.philips.com>
|
|
33 ;;
|
|
34 ;; Rather than run apropos and print all the documentation at once,
|
|
35 ;; I find it easier to view a "table of contents" first, then
|
|
36 ;; get the details for symbols as you need them.
|
|
37 ;;
|
|
38 ;; This version of apropos prints two lists of symbols matching the
|
|
39 ;; given regexp: functions/macros and variables/constants.
|
|
40 ;;
|
|
41 ;; The user can then do the following:
|
|
42 ;;
|
|
43 ;; - add an additional regexp to narrow the search
|
|
44 ;; - display documentation for the current symbol
|
|
45 ;; - find the tag for the current symbol
|
|
46 ;; - show any keybindings if the current symbol is a command
|
|
47 ;; - invoke functions
|
|
48 ;; - set variables
|
|
49 ;;
|
|
50 ;; An additional feature is the ability to search the current tags
|
|
51 ;; table, allowing you to interrogate functions not yet loaded (this
|
|
52 ;; isn't available with the standard package).
|
|
53 ;;
|
|
54 ;; Mouse bindings and menus are provided for XEmacs.
|
|
55 ;;
|
|
56 ;; additions by Ben Wing <ben@xemacs.org> July 1995:
|
|
57 ;; added support for function aliases, made programmer's apropos be the
|
|
58 ;; default, various other hacking.
|
|
59 ;; Massive changes by Christoph Wedler <wedler@fmi.uni-passau.de>
|
|
60 ;; Some changes for XEmacs 20.3 by hniksic
|
|
61
|
440
|
62 ;; #### The maintainer is supposed to be stig, but I haven't seen him
|
428
|
63 ;; around for ages. The real maintainer for the moment is Hrvoje
|
|
64 ;; Niksic <hniksic@xemacs.org>.
|
|
65
|
|
66 ;;; Code:
|
|
67
|
|
68 (defgroup hyper-apropos nil
|
|
69 "Hypertext emacs lisp documentation interface."
|
|
70 :group 'docs
|
|
71 :group 'lisp
|
|
72 :group 'tools
|
|
73 :group 'help
|
|
74 :group 'matching)
|
|
75
|
|
76 (defcustom hyper-apropos-show-brief-docs t
|
|
77 "*If non-nil, display some documentation in the \"*Hyper Apropos*\" buffer.
|
|
78 Setting this to nil will speed up searches."
|
|
79 :type 'boolean
|
|
80 :group 'hyper-apropos)
|
|
81 (define-obsolete-variable-alias
|
|
82 'hypropos-show-brief-docs 'hyper-apropos-show-brief-docs)
|
502
|
83
|
|
84 ;; I changed the following to true because it's obviously more useful
|
|
85 ;; that way, and is a very good example of following the principle of
|
|
86 ;; least surprise. --ben
|
428
|
87
|
|
88 (defcustom hyper-apropos-programming-apropos t
|
|
89 "*If non-nil, list all the functions and variables.
|
|
90 This will cause more output to be generated, and take a longer time.
|
502
|
91 Otherwise, only the interactive functions and user variables will be listed.
|
428
|
92
|
502
|
93 If you're thinking of setting it to nil, consider that you can get the
|
|
94 equivalent just by using the command \\[command-hyper-apropos]. (And if you do set it to nil,
|
|
95 you can get the full output by using \\[universal-argument] \\[hyper-apropos].)"
|
428
|
96 :type 'boolean
|
|
97 :group 'hyper-apropos)
|
|
98 (define-obsolete-variable-alias
|
|
99 'hypropos-programming-apropos 'hyper-apropos-programming-apropos)
|
|
100
|
|
101 (defcustom hyper-apropos-shrink-window nil
|
|
102 "*If non-nil, shrink *Hyper Help* buffer if possible."
|
|
103 :type 'boolean
|
|
104 :group 'hyper-apropos)
|
|
105 (define-obsolete-variable-alias
|
|
106 'hypropos-shrink-window 'hyper-apropos-shrink-window)
|
|
107
|
|
108 (defcustom hyper-apropos-prettyprint-long-values t
|
|
109 "*If non-nil, then try to beautify the printing of very long values."
|
|
110 :type 'boolean
|
|
111 :group 'hyper-apropos)
|
|
112 (define-obsolete-variable-alias
|
|
113 'hypropos-prettyprint-long-values 'hyper-apropos-prettyprint-long-values)
|
|
114
|
|
115 (defgroup hyper-apropos-faces nil
|
|
116 "Faces defined by hyper-apropos."
|
|
117 :prefix "hyper-apropos-"
|
|
118 :group 'faces)
|
|
119
|
|
120 (defface hyper-apropos-documentation
|
|
121 '((((class color) (background light))
|
|
122 (:foreground "darkred"))
|
|
123 (((class color) (background dark))
|
|
124 (:foreground "gray90")))
|
|
125 "Hyper-apropos documentation."
|
|
126 :group 'hyper-apropos-faces)
|
|
127
|
|
128 (defface hyper-apropos-hyperlink
|
|
129 '((((class color) (background light))
|
|
130 (:foreground "blue4"))
|
|
131 (((class color) (background dark))
|
|
132 (:foreground "lightseagreen"))
|
|
133 (t
|
|
134 (:bold t)))
|
|
135 "Hyper-apropos hyperlinks."
|
|
136 :group 'hyper-apropos-faces)
|
|
137
|
|
138 (defface hyper-apropos-major-heading '((t (:bold t)))
|
|
139 "Hyper-apropos major heading."
|
|
140 :group 'hyper-apropos-faces)
|
|
141
|
|
142 (defface hyper-apropos-section-heading '((t (:bold t :italic t)))
|
|
143 "Hyper-apropos section heading."
|
|
144 :group 'hyper-apropos-faces)
|
|
145
|
|
146 (defface hyper-apropos-heading '((t (:bold t)))
|
|
147 "Hyper-apropos heading."
|
|
148 :group 'hyper-apropos-faces)
|
|
149
|
|
150 (defface hyper-apropos-warning '((t (:bold t :foreground "red")))
|
|
151 "Hyper-apropos warning."
|
|
152 :group 'hyper-apropos-faces)
|
|
153
|
|
154 ;;; Internal variables below this point
|
|
155
|
|
156 (defvar hyper-apropos-ref-buffer)
|
|
157 (defvar hyper-apropos-prev-wconfig)
|
|
158
|
|
159 (defvar hyper-apropos-help-map
|
|
160 (let ((map (make-sparse-keymap)))
|
|
161 (suppress-keymap map)
|
|
162 (set-keymap-name map 'hyper-apropos-help-map)
|
|
163 ;; movement
|
|
164 (define-key map " " 'scroll-up)
|
|
165 (define-key map "b" 'scroll-down)
|
|
166 (define-key map [delete] 'scroll-down)
|
|
167 (define-key map [backspace] 'scroll-down)
|
|
168 (define-key map "/" 'isearch-forward)
|
|
169 (define-key map "?" 'isearch-backward)
|
|
170 ;; follow links
|
|
171 (define-key map [return] 'hyper-apropos-get-doc)
|
|
172 (define-key map "s" 'hyper-apropos-set-variable)
|
|
173 (define-key map "t" 'hyper-apropos-find-tag)
|
|
174 (define-key map "l" 'hyper-apropos-last-help)
|
|
175 (define-key map "c" 'hyper-apropos-customize-variable)
|
|
176 (define-key map "f" 'hyper-apropos-find-function)
|
718
|
177 (define-key map "v" 'hyper-apropos-find-variable)
|
428
|
178 (define-key map [button2] 'hyper-apropos-mouse-get-doc)
|
|
179 (define-key map [button3] 'hyper-apropos-popup-menu)
|
|
180 ;; for the totally hardcore...
|
|
181 (define-key map "D" 'hyper-apropos-disassemble)
|
|
182 ;; administrativa
|
|
183 (define-key map "a" 'hyper-apropos)
|
|
184 (define-key map "n" 'hyper-apropos)
|
|
185 (define-key map "q" 'hyper-apropos-quit)
|
|
186 map)
|
|
187 "Keybindings for the *Hyper Help* buffer and the *Hyper Apropos* buffer")
|
|
188 (define-obsolete-variable-alias
|
|
189 'hypropos-help-map 'hyper-apropos-help-map)
|
|
190
|
|
191 (defvar hyper-apropos-map
|
|
192 (let ((map (make-sparse-keymap)))
|
|
193 (set-keymap-name map 'hyper-apropos-map)
|
|
194 (set-keymap-parents map (list hyper-apropos-help-map))
|
|
195 ;; slightly different scrolling...
|
|
196 (define-key map " " 'hyper-apropos-scroll-up)
|
|
197 (define-key map "b" 'hyper-apropos-scroll-down)
|
|
198 (define-key map [delete] 'hyper-apropos-scroll-down)
|
|
199 (define-key map [backspace] 'hyper-apropos-scroll-down)
|
|
200 ;; act on the current line...
|
|
201 (define-key map "w" 'hyper-apropos-where-is)
|
|
202 (define-key map "i" 'hyper-apropos-invoke-fn)
|
|
203 ;; this is already defined in the parent-keymap above, isn't it?
|
|
204 ;; (define-key map "s" 'hyper-apropos-set-variable)
|
|
205 ;; more administrativa...
|
|
206 (define-key map "P" 'hyper-apropos-toggle-programming-flag)
|
|
207 (define-key map "k" 'hyper-apropos-add-keyword)
|
|
208 (define-key map "e" 'hyper-apropos-eliminate-keyword)
|
|
209 map)
|
|
210 "Keybindings for the *Hyper Apropos* buffer.
|
|
211 This map inherits from `hyper-apropos-help-map.'")
|
|
212 (define-obsolete-variable-alias
|
|
213 'hypropos-map 'hyper-apropos-map)
|
|
214
|
|
215 ;;(defvar hyper-apropos-mousable-keymap
|
|
216 ;; (let ((map (make-sparse-keymap)))
|
|
217 ;; (define-key map [button2] 'hyper-apropos-mouse-get-doc)
|
|
218 ;; map))
|
|
219
|
|
220 (defvar hyper-apropos-mode-hook nil
|
|
221 "*User function run after hyper-apropos mode initialization. Usage:
|
|
222 \(add-hook 'hyper-apropos-mode-hook #'(lambda () ... your init forms ...)).")
|
|
223
|
|
224 ;; ---------------------------------------------------------------------- ;;
|
|
225
|
|
226 (defconst hyper-apropos-junk-regexp
|
|
227 "^Apropos\\|^Functions\\|^Variables\\|^$")
|
|
228
|
|
229 (defvar hyper-apropos-currently-showing nil) ; symbol documented in
|
|
230 ; help buffer now
|
|
231 (defvar hyper-apropos-help-history nil) ; chain of symbols followed as links in
|
|
232 ; help buffer
|
|
233 (defvar hyper-apropos-face-history nil)
|
|
234 ;;;(defvar hyper-apropos-variable-history nil)
|
|
235 ;;;(defvar hyper-apropos-function-history nil)
|
|
236 (defvar hyper-apropos-regexp-history nil)
|
|
237 (defvar hyper-apropos-last-regexp nil) ; regex used for last apropos
|
|
238 (defconst hyper-apropos-apropos-buf "*Hyper Apropos*")
|
|
239 (defconst hyper-apropos-help-buf "*Hyper Help*")
|
|
240
|
|
241 ;;;###autoload
|
502
|
242 (defun command-hyper-apropos (regexp)
|
|
243 "Display lists of commands and user options matching REGEXP
|
|
244 in buffer \"*Hyper Apropos*\". See `hyper-apropos-mode' for a
|
|
245 description of the available commands in a Hyper-Apropos buffer."
|
|
246 (interactive (list (read-from-minibuffer
|
|
247 "List symbols matching regexp: "
|
|
248 nil nil nil 'hyper-apropos-regexp-history)))
|
|
249 (let ((hyper-apropos-programming-apropos nil))
|
|
250 (hyper-apropos regexp nil)))
|
|
251
|
|
252 ;;;###autoload
|
428
|
253 (defun hyper-apropos (regexp toggle-apropos)
|
|
254 "Display lists of functions and variables matching REGEXP
|
|
255 in buffer \"*Hyper Apropos*\". If optional prefix arg is given, then the
|
|
256 value of `hyper-apropos-programming-apropos' is toggled for this search.
|
502
|
257 See `hyper-apropos-mode' for a description of the available commands in
|
|
258 a Hyper-Apropos buffer."
|
|
259 (interactive (list (read-from-minibuffer
|
|
260 "List symbols matching regexp: "
|
|
261 nil nil nil 'hyper-apropos-regexp-history)
|
428
|
262 current-prefix-arg))
|
|
263 (or (memq major-mode '(hyper-apropos-mode hyper-apropos-help-mode))
|
|
264 (setq hyper-apropos-prev-wconfig (current-window-configuration)))
|
|
265 (if (string= "" regexp)
|
|
266 (if (get-buffer hyper-apropos-apropos-buf)
|
434
|
267 (progn
|
|
268 (setq regexp hyper-apropos-last-regexp)
|
|
269 (if toggle-apropos
|
|
270 (hyper-apropos-toggle-programming-flag)
|
|
271 (message "Using last search results")))
|
428
|
272 (error "Be more specific..."))
|
|
273 (set-buffer (get-buffer-create hyper-apropos-apropos-buf))
|
|
274 (setq buffer-read-only nil)
|
|
275 (erase-buffer)
|
|
276 (if toggle-apropos
|
434
|
277 (if (local-variable-p 'hyper-apropos-programming-apropos
|
|
278 (current-buffer))
|
|
279 (setq hyper-apropos-programming-apropos
|
|
280 (not hyper-apropos-programming-apropos))
|
|
281 (set (make-local-variable 'hyper-apropos-programming-apropos)
|
|
282 (not (default-value 'hyper-apropos-programming-apropos)))))
|
428
|
283 (let ((flist (apropos-internal regexp
|
|
284 (if hyper-apropos-programming-apropos
|
|
285 #'fboundp
|
|
286 #'commandp)))
|
|
287 (vlist (apropos-internal regexp
|
|
288 (if hyper-apropos-programming-apropos
|
|
289 #'boundp
|
|
290 #'user-variable-p))))
|
|
291 (insert-face (format "Apropos search for: %S\n\n" regexp)
|
|
292 'hyper-apropos-major-heading)
|
|
293 (insert-face "* = command (M-x) or user-variable.\n"
|
|
294 'hyper-apropos-documentation)
|
|
295 (insert-face "\
|
|
296 a = autoloaded, b = byte-compiled, i = internal, l = lambda, m = macro.\n\n"
|
|
297 'hyper-apropos-documentation)
|
|
298 (insert-face "Functions and Macros:\n\n" 'hyper-apropos-major-heading)
|
|
299 (hyper-apropos-grok-functions flist)
|
|
300 (insert-face "\n\nVariables and Constants:\n\n"
|
|
301 'hyper-apropos-major-heading)
|
|
302 (hyper-apropos-grok-variables vlist)
|
|
303 (goto-char (point-min))))
|
|
304 (switch-to-buffer hyper-apropos-apropos-buf)
|
|
305 (hyper-apropos-mode regexp))
|
|
306
|
|
307 (defun hyper-apropos-toggle-programming-flag ()
|
|
308 (interactive)
|
|
309 (with-current-buffer hyper-apropos-apropos-buf
|
|
310 (set (make-local-variable 'hyper-apropos-programming-apropos)
|
|
311 (not hyper-apropos-programming-apropos)))
|
|
312 (message "Re-running apropos...")
|
|
313 (hyper-apropos hyper-apropos-last-regexp nil))
|
|
314
|
|
315 (defun hyper-apropos-grok-functions (fns)
|
|
316 (let (bind doc type)
|
|
317 (dolist (fn fns)
|
|
318 (setq bind (symbol-function fn)
|
|
319 type (cond ((subrp bind) ?i)
|
|
320 ((compiled-function-p bind) ?b)
|
|
321 ((consp bind) (or (cdr
|
|
322 (assq (car bind) '((autoload . ?a)
|
|
323 (lambda . ?l)
|
|
324 (macro . ?m))))
|
|
325 ??))
|
|
326 (t ?\ )))
|
|
327 (insert type (if (commandp fn) "* " " "))
|
|
328 (let ((e (insert-face (format "%S" fn) 'hyper-apropos-hyperlink)))
|
|
329 (set-extent-property e 'mouse-face 'highlight))
|
|
330 (insert-char ?\ (let ((l (- 30 (length (format "%S" fn)))))
|
|
331 (if (natnump l) l 0)))
|
|
332 (and hyper-apropos-show-brief-docs
|
|
333 (setq doc
|
|
334 ;; A symbol's function slot can point to an unbound symbol.
|
|
335 ;; In that case, `documentation' will fail.
|
|
336 (ignore-errors
|
|
337 (documentation fn)))
|
|
338 (if (string-match
|
|
339 "^([^\n\t )]+[\t ]*\\([^\n)]+\\)?)\\(:[\t ]*\\|\n?\\'\\)"
|
|
340 doc)
|
|
341 (setq doc (substring doc (match-end 0) (string-match "\n" doc)))
|
|
342 t)
|
|
343 (insert-face (if doc
|
|
344 (concat " - "
|
|
345 (substring doc 0 (string-match "\n" doc)))
|
|
346 " Not documented.")
|
|
347 'hyper-apropos-documentation))
|
|
348 (insert ?\n))))
|
|
349
|
|
350 (defun hyper-apropos-grok-variables (vars)
|
|
351 (let (doc userp)
|
|
352 (dolist (var vars)
|
|
353 (setq userp (user-variable-p var))
|
|
354 (insert (if userp " * " " "))
|
|
355 (let ((e (insert-face (format "%S" var) 'hyper-apropos-hyperlink)))
|
|
356 (set-extent-property e 'mouse-face 'highlight))
|
|
357 (insert-char ?\ (let ((l (- 30 (length (format "%S" var)))))
|
|
358 (if (natnump l) l 0)))
|
|
359 (and hyper-apropos-show-brief-docs
|
|
360 (setq doc (documentation-property var 'variable-documentation))
|
|
361 (insert-face (if doc
|
|
362 (concat " - " (substring doc (if userp 1 0)
|
|
363 (string-match "\n" doc)))
|
|
364 " - Not documented.")
|
|
365 'hyper-apropos-documentation))
|
|
366 (insert ?\n))))
|
|
367
|
|
368 ;; ---------------------------------------------------------------------- ;;
|
|
369
|
|
370 (defun hyper-apropos-mode (regexp)
|
|
371 "Improved apropos mode for displaying Emacs documentation. Function and
|
|
372 variable names are displayed in the buffer \"*Hyper Apropos*\".
|
|
373
|
|
374 Functions are preceded by a single character to indicates their types:
|
|
375 a = autoloaded, b = byte-compiled, i = internal, l = lambda, m = macro.
|
|
376 Interactive functions are also preceded by an asterisk.
|
|
377 Variables are preceded by an asterisk if they are user variables.
|
|
378
|
|
379 General Commands:
|
|
380
|
|
381 SPC - scroll documentation or apropos window forward
|
|
382 b - scroll documentation or apropos window backward
|
|
383 k - eliminate all hits that don't contain keyword
|
|
384 n - new search
|
|
385 / - isearch-forward
|
|
386 q - quit and restore previous window configuration
|
|
387
|
|
388 Operations for Symbol on Current Line:
|
|
389
|
|
390 RET - toggle display of symbol's documentation
|
|
391 (also on button2 in xemacs)
|
|
392 w - show the keybinding if symbol is a command
|
|
393 i - invoke function on current line
|
|
394 s - set value of variable on current line
|
|
395 t - display the C or lisp source (find-tag)"
|
|
396 (delete-other-windows)
|
|
397 (setq mode-name "Hyper-Apropos"
|
|
398 major-mode 'hyper-apropos-mode
|
|
399 buffer-read-only t
|
|
400 truncate-lines t
|
|
401 hyper-apropos-last-regexp regexp
|
|
402 modeline-buffer-identification
|
|
403 (list (cons modeline-buffer-id-left-extent "Hyper Apropos: ")
|
|
404 (cons modeline-buffer-id-right-extent (concat "\"" regexp "\""))))
|
|
405 (use-local-map hyper-apropos-map)
|
|
406 (run-hooks 'hyper-apropos-mode-hook))
|
|
407
|
|
408 ;; ---------------------------------------------------------------------- ;;
|
|
409
|
|
410 ;; similar to `describe-key-briefly', copied from help.el by CW
|
|
411
|
|
412 ;;;###autoload
|
|
413 (defun hyper-describe-key (key)
|
|
414 (interactive "kDescribe key: ")
|
|
415 (hyper-describe-key-briefly key t))
|
|
416
|
|
417 ;;;###autoload
|
|
418 (defun hyper-describe-key-briefly (key &optional show)
|
|
419 (interactive "kDescribe key briefly: \nP")
|
|
420 (let (menup defn interm final msg)
|
|
421 (setq defn (key-or-menu-binding key 'menup))
|
|
422 (if (or (null defn) (integerp defn))
|
|
423 (or (numberp show) (message "%s is undefined" (key-description key)))
|
|
424 (cond ((stringp defn)
|
|
425 (setq interm defn
|
|
426 final (key-binding defn)))
|
|
427 ((vectorp defn)
|
|
428 (setq interm (append defn nil))
|
|
429 (while (and interm
|
|
430 (member (key-binding (vector (car interm)))
|
|
431 '(universal-argument digit-argument)))
|
|
432 (setq interm (cdr interm)))
|
|
433 (while (and interm
|
|
434 (not (setq final (key-binding (vconcat interm)))))
|
|
435 (setq interm (butlast interm)))
|
|
436 (if final
|
|
437 (setq interm (vconcat interm))
|
|
438 (setq interm defn
|
|
439 final (key-binding defn)))))
|
|
440 (setq msg (format
|
|
441 "%s runs %s%s%s"
|
|
442 ;; This used to say 'This menu item' but it could also
|
|
443 ;; be a scrollbar event. We can't distinguish at the
|
|
444 ;; moment.
|
|
445 (if menup "This item" (key-description key))
|
|
446 ;;(if (symbolp defn) defn (key-description defn))
|
|
447 (if (symbolp defn) defn (prin1-to-string defn))
|
|
448 (if final (concat ", " (key-description interm) " runs ") "")
|
|
449 (if final
|
|
450 (if (symbolp final) final (prin1-to-string final))
|
|
451 "")))
|
|
452 (if (numberp show)
|
|
453 (or (not (symbolp defn))
|
|
454 (memq (symbol-function defn)
|
|
455 '(zkey-init-kbd-macro zkey-init-kbd-fn))
|
|
456 (progn (princ msg) (princ "\n")))
|
|
457 (message "%s" msg)
|
|
458 (if final (setq defn final))
|
|
459 (if (and (or (symbolp defn) (symbolp (setq defn (car-safe defn))))
|
|
460 defn
|
|
461 show)
|
438
|
462 (hyper-apropos-get-doc defn t))
|
|
463 (or (memq major-mode '(hyper-apropos-mode hyper-apropos-help-mode))
|
|
464 (setq hyper-apropos-prev-wconfig (current-window-configuration)))))))
|
428
|
465
|
|
466 ;;;###autoload
|
|
467 (defun hyper-describe-face (symbol &optional this-ref-buffer)
|
|
468 "Describe face..
|
|
469 See also `hyper-apropos' and `hyper-describe-function'."
|
|
470 ;; #### - perhaps a prefix arg should suppress the prompt...
|
|
471 (interactive
|
|
472 (let (v val)
|
|
473 (setq v (hyper-apropos-this-symbol)) ; symbol under point
|
|
474 (or (find-face v)
|
|
475 (setq v (variable-at-point)))
|
|
476 (setq val (let ((enable-recursive-minibuffers t))
|
|
477 (completing-read
|
|
478 (concat (if (hyper-apropos-follow-ref-buffer current-prefix-arg)
|
|
479 "Follow face"
|
|
480 "Describe face")
|
|
481 (if v
|
|
482 (format " (default %s): " v)
|
|
483 ": "))
|
|
484 (mapcar #'(lambda (x) (list (symbol-name x)))
|
|
485 (face-list))
|
438
|
486 nil t nil 'hyper-apropos-face-history
|
|
487 (and v (symbol-name v)))))
|
|
488 (list (intern-soft val)
|
428
|
489 current-prefix-arg)))
|
|
490 (if (null symbol)
|
|
491 (message "Sorry, nothing to describe.")
|
|
492 (or (memq major-mode '(hyper-apropos-mode hyper-apropos-help-mode))
|
|
493 (setq hyper-apropos-prev-wconfig (current-window-configuration)))
|
|
494 (hyper-apropos-get-doc symbol t nil this-ref-buffer)))
|
|
495
|
|
496 ;;;###autoload
|
|
497 (defun hyper-describe-variable (symbol &optional this-ref-buffer)
|
|
498 "Hypertext drop-in replacement for `describe-variable'.
|
|
499 See also `hyper-apropos' and `hyper-describe-function'."
|
|
500 ;; #### - perhaps a prefix arg should suppress the prompt...
|
|
501 (interactive (list (hyper-apropos-read-variable-symbol
|
|
502 (if (hyper-apropos-follow-ref-buffer current-prefix-arg)
|
|
503 "Follow variable"
|
|
504 "Describe variable"))
|
|
505 current-prefix-arg))
|
|
506 (if (null symbol)
|
|
507 (message "Sorry, nothing to describe.")
|
|
508 (or (memq major-mode '(hyper-apropos-mode hyper-apropos-help-mode))
|
|
509 (setq hyper-apropos-prev-wconfig (current-window-configuration)))
|
|
510 (hyper-apropos-get-doc symbol t nil this-ref-buffer)))
|
|
511
|
|
512 ;;;###autoload
|
|
513 (defun hyper-where-is (symbol)
|
|
514 "Print message listing key sequences that invoke specified command."
|
|
515 (interactive (list (hyper-apropos-read-function-symbol "Where is function")))
|
|
516 (if (null symbol)
|
|
517 (message "Sorry, nothing to describe.")
|
|
518 (where-is symbol)))
|
|
519
|
|
520 ;;;###autoload
|
|
521 (defun hyper-describe-function (symbol &optional this-ref-buffer)
|
|
522 "Hypertext replacement for `describe-function'. Unlike `describe-function'
|
|
523 in that the symbol under the cursor is the default if it is a function.
|
|
524 See also `hyper-apropos' and `hyper-describe-variable'."
|
|
525 ;; #### - perhaps a prefix arg should suppress the prompt...
|
|
526 (interactive (list (hyper-apropos-read-function-symbol
|
|
527 (if (hyper-apropos-follow-ref-buffer current-prefix-arg)
|
|
528 "Follow function"
|
|
529 "Describe function"))
|
|
530 current-prefix-arg))
|
|
531 (if (null symbol)
|
|
532 (message "Sorry, nothing to describe.")
|
|
533 (or (memq major-mode '(hyper-apropos-mode hyper-apropos-help-mode))
|
|
534 (setq hyper-apropos-prev-wconfig (current-window-configuration)))
|
|
535 (hyper-apropos-get-doc symbol t nil this-ref-buffer)))
|
|
536
|
|
537 ;;;###autoload
|
|
538 (defun hyper-apropos-read-variable-symbol (prompt &optional predicate)
|
|
539 "Hypertext drop-in replacement for `describe-variable'.
|
|
540 See also `hyper-apropos' and `hyper-describe-function'."
|
|
541 ;; #### - perhaps a prefix arg should suppress the prompt...
|
|
542 (or predicate (setq predicate 'boundp))
|
|
543 (let (v val)
|
|
544 (setq v (hyper-apropos-this-symbol)) ; symbol under point
|
|
545 (or (funcall predicate v)
|
|
546 (setq v (variable-at-point)))
|
|
547 (or (funcall predicate v)
|
|
548 (setq v nil))
|
|
549 (setq val (let ((enable-recursive-minibuffers t))
|
|
550 (completing-read
|
|
551 (concat prompt
|
|
552 (if v
|
|
553 (format " (default %s): " v)
|
|
554 ": "))
|
438
|
555 obarray predicate t nil 'variable-history
|
|
556 (and v (symbol-name v)))))
|
|
557 (intern-soft val)))
|
|
558
|
428
|
559 ;;;###autoload
|
|
560 (define-obsolete-function-alias
|
|
561 'hypropos-read-variable-symbol 'hyper-apropos-read-variable-symbol)
|
|
562
|
|
563 (defun hyper-apropos-read-function-symbol (prompt)
|
|
564 "Read function symbol from minibuffer."
|
|
565 (let ((fn (hyper-apropos-this-symbol))
|
|
566 val)
|
|
567 (or (fboundp fn)
|
|
568 (setq fn (function-at-point)))
|
|
569 (setq val (let ((enable-recursive-minibuffers t))
|
|
570 (completing-read (if fn
|
|
571 (format "%s (default %s): " prompt fn)
|
|
572 (format "%s: " prompt))
|
|
573 obarray 'fboundp t nil
|
438
|
574 'function-history
|
|
575 (and fn (symbol-name fn)))))
|
|
576 (intern-soft val)))
|
428
|
577
|
|
578 (defun hyper-apropos-last-help (arg)
|
|
579 "Go back to the last symbol documented in the *Hyper Help* buffer."
|
|
580 (interactive "P")
|
|
581 (let ((win (get-buffer-window hyper-apropos-help-buf)))
|
|
582 (or arg (setq arg (if win 1 0)))
|
|
583 (cond ((= arg 0))
|
|
584 ((<= (length hyper-apropos-help-history) arg)
|
|
585 ;; go back as far as we can...
|
|
586 (setcdr (nreverse hyper-apropos-help-history) nil))
|
|
587 (t
|
|
588 (setq hyper-apropos-help-history
|
|
589 (nthcdr arg hyper-apropos-help-history))))
|
|
590 (if (or win (> arg 0))
|
|
591 (hyper-apropos-get-doc (car hyper-apropos-help-history) t)
|
|
592 (display-buffer hyper-apropos-help-buf))))
|
|
593
|
|
594 (defun hyper-apropos-insert-face (string &optional face)
|
|
595 "Insert STRING and fontify some parts with face `hyper-apropos-hyperlink'."
|
|
596 (let ((beg (point)) end)
|
|
597 (insert-face string (or face 'hyper-apropos-documentation))
|
|
598 (setq end (point))
|
|
599 (goto-char beg)
|
|
600 (while (re-search-forward
|
|
601 "`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
|
|
602 end 'limit)
|
|
603 (let ((e (make-extent (match-beginning 1) (match-end 1))))
|
|
604 (set-extent-face e 'hyper-apropos-hyperlink)
|
|
605 (set-extent-property e 'mouse-face 'highlight)))
|
|
606 (goto-char beg)
|
|
607 (while (re-search-forward
|
|
608 "M-x \\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)"
|
|
609 end 'limit)
|
|
610 (let ((e (make-extent (match-beginning 1) (match-end 1))))
|
|
611 (set-extent-face e 'hyper-apropos-hyperlink)
|
|
612 (set-extent-property e 'mouse-face 'highlight)))))
|
|
613
|
|
614 (defun hyper-apropos-insert-keybinding (keys string)
|
|
615 (if keys
|
|
616 (insert " (" string " bound to \""
|
|
617 (mapconcat 'key-description
|
|
618 (sort* keys #'< :key #'length)
|
|
619 "\", \"")
|
|
620 "\")\n")))
|
|
621
|
|
622 (defun hyper-apropos-insert-section-heading (alias-desc &optional desc)
|
|
623 (or desc (setq desc alias-desc
|
|
624 alias-desc nil))
|
|
625 (if alias-desc
|
|
626 (setq desc (concat alias-desc
|
|
627 (if (memq (aref desc 0)
|
|
628 '(?a ?e ?i ?o ?u))
|
|
629 ", an " ", a ")
|
|
630 desc)))
|
|
631 (aset desc 0 (upcase (aref desc 0))) ; capitalize
|
|
632 (goto-char (point-max))
|
|
633 (newline 3) (delete-blank-lines) (newline 2)
|
|
634 (hyper-apropos-insert-face desc 'hyper-apropos-section-heading))
|
|
635
|
|
636 (defun hyper-apropos-insert-value (string symbol val)
|
|
637 (insert-face string 'hyper-apropos-heading)
|
|
638 (insert (if (symbol-value symbol)
|
|
639 (if (or (null val) (eq val t) (integerp val))
|
|
640 (prog1
|
|
641 (symbol-value symbol)
|
|
642 (set symbol nil))
|
|
643 "see below")
|
|
644 "is void")))
|
|
645
|
|
646 (defun hyper-apropos-follow-ref-buffer (this-ref-buffer)
|
|
647 (and (not this-ref-buffer)
|
|
648 (eq major-mode 'hyper-apropos-help-mode)
|
|
649 hyper-apropos-ref-buffer
|
|
650 (buffer-live-p hyper-apropos-ref-buffer)))
|
|
651
|
|
652 (defun hyper-apropos-get-alias (symbol alias-p next-symbol &optional use)
|
|
653 "Return (TERMINAL-SYMBOL . ALIAS-DESC)."
|
|
654 (let (aliases)
|
|
655 (while (funcall alias-p symbol)
|
|
656 (setq aliases (cons (if use (funcall use symbol) symbol) aliases))
|
|
657 (setq symbol (funcall next-symbol symbol)))
|
|
658 (cons symbol
|
|
659 (and aliases
|
|
660 (concat "an alias for `"
|
|
661 (mapconcat 'symbol-name
|
|
662 (nreverse aliases)
|
|
663 "',\nwhich is an alias for `")
|
|
664 "'")))))
|
|
665
|
|
666 (defun hyper-apropos-get-doc (&optional symbol force type this-ref-buffer)
|
|
667 ;; #### - update this docstring
|
|
668 "Toggle display of documentation for the symbol on the current line."
|
|
669 ;; SYMBOL is the symbol to document. FORCE, if non-nil, means to
|
|
670 ;; regenerate the documentation even if it already seems to be there. And
|
|
671 ;; TYPE, if present, forces the generation of only variable documentation
|
|
672 ;; or only function documentation. Normally, if both are present, then
|
|
673 ;; both will be generated.
|
|
674 ;;
|
|
675 ;; TYPES TO IMPLEMENT: obsolete face
|
|
676 ;;
|
|
677 (interactive)
|
|
678 (or symbol
|
|
679 (setq symbol (hyper-apropos-this-symbol)))
|
|
680 (or type
|
|
681 (setq type '(function variable face)))
|
|
682 (if (and (eq hyper-apropos-currently-showing symbol)
|
|
683 (get-buffer hyper-apropos-help-buf)
|
|
684 (get-buffer-window hyper-apropos-help-buf)
|
|
685 (not force))
|
|
686 ;; we're already displaying this help, so toggle its display.
|
|
687 (delete-windows-on hyper-apropos-help-buf)
|
|
688 ;; OK, we've got to refresh and display it...
|
|
689 (or (eq symbol (car hyper-apropos-help-history))
|
|
690 (setq hyper-apropos-help-history
|
|
691 (if (eq major-mode 'hyper-apropos-help-mode)
|
|
692 ;; if we're following a link in the help buffer, then
|
|
693 ;; record that in the help history.
|
|
694 (cons symbol hyper-apropos-help-history)
|
|
695 ;; otherwise clear the history because it's a new search.
|
|
696 (list symbol))))
|
|
697 (save-excursion
|
|
698 (if (hyper-apropos-follow-ref-buffer this-ref-buffer)
|
|
699 (set-buffer hyper-apropos-ref-buffer)
|
|
700 (setq hyper-apropos-ref-buffer (current-buffer)))
|
|
701 (let (standard-output
|
|
702 ok beg
|
|
703 newsym symtype doc obsolete
|
|
704 (local mode-name)
|
|
705 global local-str global-str
|
|
706 font fore back undl
|
|
707 aliases alias-desc desc)
|
|
708 (save-excursion
|
|
709 (set-buffer (get-buffer-create hyper-apropos-help-buf))
|
|
710 ;;(setq standard-output (current-buffer))
|
|
711 (setq buffer-read-only nil)
|
|
712 (erase-buffer)
|
|
713 (insert-face (format "`%s'" symbol) 'hyper-apropos-major-heading)
|
|
714 (insert (format " (buffer: %s, mode: %s)\n"
|
|
715 (buffer-name hyper-apropos-ref-buffer)
|
|
716 local)))
|
|
717 ;; function ----------------------------------------------------------
|
|
718 (and (memq 'function type)
|
|
719 (fboundp symbol)
|
|
720 (progn
|
|
721 (setq ok t)
|
|
722 (setq aliases (hyper-apropos-get-alias (symbol-function symbol)
|
|
723 'symbolp
|
|
724 'symbol-function)
|
|
725 newsym (car aliases)
|
|
726 alias-desc (cdr aliases))
|
|
727 (if (eq 'macro (car-safe newsym))
|
|
728 (setq desc "macro"
|
|
729 newsym (cdr newsym))
|
|
730 (setq desc "function"))
|
|
731 (setq symtype (cond ((subrp newsym) 'subr)
|
|
732 ((compiled-function-p newsym) 'bytecode)
|
|
733 ((eq (car-safe newsym) 'autoload) 'autoload)
|
|
734 ((eq (car-safe newsym) 'lambda) 'lambda))
|
|
735 desc (concat (if (commandp symbol) "interactive ")
|
|
736 (cdr (assq symtype
|
|
737 '((subr . "built-in ")
|
|
738 (bytecode . "compiled Lisp ")
|
|
739 (autoload . "autoloaded Lisp ")
|
|
740 (lambda . "Lisp "))))
|
|
741 desc
|
|
742 (case symtype
|
|
743 ((autoload) (format ",\n(autoloaded from \"%s\")"
|
|
744 (nth 1 newsym)))
|
|
745 ((bytecode) (format ",\n(loaded from \"%s\")"
|
|
746 (symbol-file symbol)))))
|
|
747 local (current-local-map)
|
|
748 global (current-global-map)
|
|
749 obsolete (get symbol 'byte-obsolete-info)
|
|
750 doc (or (documentation symbol) "function not documented"))
|
|
751 (save-excursion
|
|
752 (set-buffer hyper-apropos-help-buf)
|
|
753 (goto-char (point-max))
|
|
754 (setq standard-output (current-buffer))
|
|
755 (hyper-apropos-insert-section-heading alias-desc desc)
|
|
756 (insert ":\n")
|
|
757 (if local
|
|
758 (hyper-apropos-insert-keybinding
|
|
759 (where-is-internal symbol (list local) nil nil nil)
|
|
760 "locally"))
|
|
761 (hyper-apropos-insert-keybinding
|
|
762 (where-is-internal symbol (list global) nil nil nil)
|
|
763 "globally")
|
|
764 (insert "\n")
|
|
765 (if obsolete
|
|
766 (hyper-apropos-insert-face
|
|
767 (format "%s is an obsolete function; %s\n\n" symbol
|
|
768 (if (stringp (car obsolete))
|
|
769 (car obsolete)
|
|
770 (format "use `%s' instead." (car obsolete))))
|
|
771 'hyper-apropos-warning))
|
|
772 (setq beg (point))
|
|
773 (insert-face "arguments: " 'hyper-apropos-heading)
|
|
774 (cond ((eq symtype 'lambda)
|
|
775 (princ (or (nth 1 newsym) "()")))
|
|
776 ((eq symtype 'bytecode)
|
|
777 (princ (or (compiled-function-arglist newsym)
|
|
778 "()")))
|
|
779 ((and (eq symtype 'subr)
|
|
780 (string-match
|
|
781 "[\n\t ]*\narguments: ?\\((.*)\\)\n?\\'"
|
|
782 doc))
|
|
783 (insert (substring doc
|
|
784 (match-beginning 1)
|
|
785 (match-end 1)))
|
|
786 (setq doc (substring doc 0 (match-beginning 0))))
|
|
787 ((and (eq symtype 'subr)
|
|
788 (string-match
|
|
789 "\
|
|
790 \[\n\t ]*([^\n\t )]+[\t ]*\\([^\n)]+\\)?)\\(:[\t ]*\\|\n?\\'\\)"
|
|
791 doc))
|
|
792 (insert "("
|
|
793 (if (match-end 1)
|
|
794 (substring doc
|
|
795 (match-beginning 1)
|
|
796 (match-end 1)))
|
|
797 ")")
|
|
798 (setq doc (substring doc (match-end 0))))
|
|
799 (t (princ "[not available]")))
|
|
800 (insert "\n\n")
|
|
801 (hyper-apropos-insert-face doc)
|
|
802 (insert "\n")
|
|
803 (indent-rigidly beg (point) 2))))
|
|
804 ;; variable ----------------------------------------------------------
|
|
805 (and (memq 'variable type)
|
|
806 (or (boundp symbol) (default-boundp symbol))
|
|
807 (progn
|
|
808 (setq ok t)
|
|
809 (setq aliases (hyper-apropos-get-alias symbol
|
|
810 'variable-alias
|
|
811 'variable-alias
|
|
812 'variable-alias)
|
|
813 newsym (car aliases)
|
|
814 alias-desc (cdr aliases))
|
|
815 (setq symtype (or (local-variable-p newsym (current-buffer))
|
|
816 (and (local-variable-p newsym
|
|
817 (current-buffer) t)
|
|
818 'auto-local))
|
|
819 desc (concat (and (get newsym 'custom-type)
|
|
820 "customizable ")
|
|
821 (if (user-variable-p newsym)
|
|
822 "user variable"
|
|
823 "variable")
|
|
824 (cond ((eq symtype t) ", buffer-local")
|
|
825 ((eq symtype 'auto-local)
|
|
826 ", local when set")))
|
|
827 local (and (boundp newsym)
|
|
828 (symbol-value newsym))
|
|
829 local-str (and (boundp newsym)
|
|
830 (prin1-to-string local))
|
|
831 global (and (eq symtype t)
|
|
832 (default-boundp newsym)
|
|
833 (default-value newsym))
|
|
834 global-str (and (eq symtype t)
|
|
835 (default-boundp newsym)
|
|
836 (prin1-to-string global))
|
|
837 obsolete (get symbol 'byte-obsolete-variable)
|
|
838 doc (or (documentation-property symbol
|
|
839 'variable-documentation)
|
|
840 "variable not documented"))
|
|
841 (save-excursion
|
|
842 (set-buffer hyper-apropos-help-buf)
|
|
843 (goto-char (point-max))
|
|
844 (setq standard-output (current-buffer))
|
|
845 (hyper-apropos-insert-section-heading alias-desc desc)
|
|
846 (when (and (user-variable-p newsym)
|
|
847 (get newsym 'custom-type))
|
|
848 (let ((e (make-extent (point-at-bol) (point))))
|
|
849 (set-extent-property e 'mouse-face 'highlight)
|
|
850 (set-extent-property e 'help-echo
|
|
851 (format "Customize %s" newsym))
|
|
852 (set-extent-property
|
|
853 e 'hyper-apropos-custom
|
|
854 `(lambda () (customize-variable (quote ,newsym))))))
|
|
855 (insert ":\n\n")
|
|
856 (setq beg (point))
|
|
857 (if obsolete
|
|
858 (hyper-apropos-insert-face
|
|
859 (format "%s is an obsolete function; %s\n\n" symbol
|
|
860 (if (stringp obsolete)
|
|
861 obsolete
|
|
862 (format "use `%s' instead." obsolete)))
|
|
863 'hyper-apropos-warning))
|
|
864 ;; generally, the value of the variable is short and the
|
|
865 ;; documentation of the variable long, so it's desirable
|
|
866 ;; to see all of the value and the start of the
|
|
867 ;; documentation. Some variables, though, have huge and
|
|
868 ;; nearly meaningless values that force you to page
|
|
869 ;; forward just to find the doc string. That is
|
|
870 ;; undesirable.
|
|
871 (if (and (or (null local-str) (< (length local-str) 69))
|
|
872 (or (null global-str) (< (length global-str) 69)))
|
|
873 ; 80 cols. docstrings assume this.
|
|
874 (progn (insert-face "value: " 'hyper-apropos-heading)
|
|
875 (insert (or local-str "is void"))
|
|
876 (if (eq symtype t)
|
|
877 (progn
|
|
878 (insert "\n")
|
|
879 (insert-face "default value: " 'hyper-apropos-heading)
|
|
880 (insert (or global-str "is void"))))
|
|
881 (insert "\n\n")
|
|
882 (hyper-apropos-insert-face doc))
|
|
883 (hyper-apropos-insert-value "value: " 'local-str local)
|
|
884 (if (eq symtype t)
|
|
885 (progn
|
|
886 (insert ", ")
|
|
887 (hyper-apropos-insert-value "default-value: "
|
|
888 'global-str global)))
|
|
889 (insert "\n\n")
|
|
890 (hyper-apropos-insert-face doc)
|
|
891 (if local-str
|
|
892 (progn
|
|
893 (newline 3) (delete-blank-lines) (newline 1)
|
|
894 (insert-face "value: " 'hyper-apropos-heading)
|
|
895 (if hyper-apropos-prettyprint-long-values
|
|
896 (condition-case nil
|
|
897 (cl-prettyprint local)
|
|
898 (error (insert local-str)))
|
|
899 (insert local-str))))
|
|
900 (if global-str
|
|
901 (progn
|
|
902 (newline 3) (delete-blank-lines) (newline 1)
|
|
903 (insert-face "default value: " 'hyper-apropos-heading)
|
|
904 (if hyper-apropos-prettyprint-long-values
|
|
905 (condition-case nil
|
|
906 (cl-prettyprint global)
|
|
907 (error (insert global-str)))
|
|
908 (insert global-str)))))
|
|
909 (indent-rigidly beg (point) 2))))
|
|
910 ;; face --------------------------------------------------------------
|
|
911 (and (memq 'face type)
|
|
912 (find-face symbol)
|
|
913 (progn
|
|
914 (setq ok t)
|
|
915 (copy-face symbol 'hyper-apropos-temp-face 'global)
|
|
916 (mapcar #'(lambda (property)
|
|
917 (setq symtype (face-property-instance symbol
|
|
918 property))
|
|
919 (if symtype
|
|
920 (set-face-property 'hyper-apropos-temp-face
|
|
921 property
|
|
922 symtype)))
|
|
923 built-in-face-specifiers)
|
|
924 (setq font (cons (face-property-instance symbol 'font nil 0 t)
|
|
925 (face-property-instance symbol 'font))
|
|
926 fore (cons (face-foreground-instance symbol nil 0 t)
|
|
927 (face-foreground-instance symbol))
|
|
928 back (cons (face-background-instance symbol nil 0 t)
|
|
929 (face-background-instance symbol))
|
|
930 undl (cons (face-underline-p symbol nil 0 t)
|
|
931 (face-underline-p symbol))
|
|
932 doc (face-doc-string symbol))
|
|
933 ;; #### - add some code here
|
|
934 (save-excursion
|
|
935 (set-buffer hyper-apropos-help-buf)
|
|
936 (setq standard-output (current-buffer))
|
|
937 (hyper-apropos-insert-section-heading
|
|
938 (concat "Face"
|
|
939 (when (get symbol 'face-defface-spec)
|
|
940 (let* ((str " (customizable)")
|
|
941 (e (make-extent 1 (length str) str)))
|
|
942 (set-extent-property e 'mouse-face 'highlight)
|
|
943 (set-extent-property e 'help-echo
|
|
944 (format "Customize %s" symbol))
|
|
945 (set-extent-property e 'unique t)
|
|
946 (set-extent-property e 'duplicable t)
|
|
947 (set-extent-property
|
|
948 e 'hyper-apropos-custom
|
|
949 `(lambda () (customize-face (quote ,symbol))))
|
|
950 str))
|
|
951 ":\n\n "))
|
|
952 (insert-face "\
|
|
953 ABCDEFHIJKLMNOPQRSTUVWXYZ abcdefhijklmnopqrstuvwxyz 0123456789"
|
|
954 'hyper-apropos-temp-face)
|
|
955 (newline 2)
|
|
956 (insert-face " Font: " 'hyper-apropos-heading)
|
|
957 (insert (format (if (numberp (car font)) "(%s)\n" "%s\n")
|
|
958 (and (cdr font)
|
|
959 (font-instance-name (cdr font)))))
|
|
960 (insert-face " Foreground: " 'hyper-apropos-heading)
|
|
961 (insert (format (if (numberp (car fore)) "(%s)\n" "%s\n")
|
|
962 (and (cdr fore)
|
|
963 (color-instance-name (cdr fore)))))
|
|
964 (insert-face " Background: " 'hyper-apropos-heading)
|
|
965 (insert (format (if (numberp (car back)) "(%s)\n" "%s\n")
|
|
966 (and (cdr back)
|
|
967 (color-instance-name (cdr back)))))
|
|
968 (insert-face " Underline: " 'hyper-apropos-heading)
|
|
969 (insert (format (if (numberp (car undl)) "(%s)\n" "%s\n")
|
|
970 (cdr undl)))
|
|
971 (if doc
|
|
972 (progn
|
|
973 (newline)
|
|
974 (setq beg (point))
|
|
975 (insert doc)
|
|
976 (indent-rigidly beg (point) 2))))))
|
|
977 ;; not bound & property list -----------------------------------------
|
|
978 (or ok
|
|
979 (save-excursion
|
|
980 (set-buffer hyper-apropos-help-buf)
|
|
981 (hyper-apropos-insert-section-heading
|
|
982 "symbol is not currently bound\n")))
|
|
983 (if (and (setq symtype (symbol-plist symbol))
|
|
984 (or (> (length symtype) 2)
|
|
985 (not (memq 'variable-documentation symtype))))
|
|
986 (save-excursion
|
|
987 (set-buffer hyper-apropos-help-buf)
|
|
988 (goto-char (point-max))
|
|
989 (setq standard-output (current-buffer))
|
|
990 (hyper-apropos-insert-section-heading "property-list:\n\n")
|
|
991 (while symtype
|
|
992 (if (memq (car symtype)
|
|
993 '(variable-documentation byte-obsolete-info))
|
|
994 (setq symtype (cdr symtype))
|
|
995 (insert-face (concat " " (symbol-name (car symtype))
|
|
996 ": ")
|
|
997 'hyper-apropos-heading)
|
|
998 (setq symtype (cdr symtype))
|
|
999 (indent-to 32)
|
|
1000 (insert (prin1-to-string (car symtype)) "\n"))
|
|
1001 (setq symtype (cdr symtype)))))))
|
|
1002 (save-excursion
|
|
1003 (set-buffer hyper-apropos-help-buf)
|
|
1004 (goto-char (point-min))
|
|
1005 ;; pop up window and shrink it if it's wasting space
|
|
1006 (if hyper-apropos-shrink-window
|
|
1007 (shrink-window-if-larger-than-buffer
|
|
1008 (display-buffer (current-buffer)))
|
|
1009 (display-buffer (current-buffer)))
|
|
1010 (hyper-apropos-help-mode))
|
|
1011 (setq hyper-apropos-currently-showing symbol)))
|
|
1012 ;;;###autoload
|
|
1013 (define-obsolete-function-alias
|
|
1014 'hypropos-get-doc 'hyper-apropos-get-doc)
|
|
1015
|
|
1016 ; -----------------------------------------------------------------------------
|
|
1017
|
|
1018 (defun hyper-apropos-help-mode ()
|
|
1019 "Major mode for hypertext XEmacs help. In this mode, you can quickly
|
|
1020 follow links between back and forth between the documentation strings for
|
|
1021 different variables and functions. Common commands:
|
|
1022
|
|
1023 \\{hyper-apropos-help-map}"
|
|
1024 (setq buffer-read-only t
|
|
1025 major-mode 'hyper-apropos-help-mode
|
|
1026 mode-name "Hyper-Help")
|
|
1027 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
1028 (use-local-map hyper-apropos-help-map))
|
|
1029
|
|
1030 ;; ---------------------------------------------------------------------- ;;
|
|
1031
|
|
1032 (defun hyper-apropos-scroll-up ()
|
|
1033 "Scroll up the \"*Hyper Help*\" buffer if it's visible.
|
|
1034 Otherwise, scroll the selected window up."
|
|
1035 (interactive)
|
|
1036 (let ((win (get-buffer-window hyper-apropos-help-buf))
|
|
1037 (owin (selected-window)))
|
|
1038 (if win
|
|
1039 (progn
|
|
1040 (select-window win)
|
|
1041 (condition-case nil
|
|
1042 (scroll-up nil)
|
|
1043 (error (goto-char (point-max))))
|
|
1044 (select-window owin))
|
|
1045 (scroll-up nil))))
|
|
1046
|
|
1047 (defun hyper-apropos-scroll-down ()
|
|
1048 "Scroll down the \"*Hyper Help*\" buffer if it's visible.
|
|
1049 Otherwise, scroll the selected window down."
|
|
1050 (interactive)
|
|
1051 (let ((win (get-buffer-window hyper-apropos-help-buf))
|
|
1052 (owin (selected-window)))
|
|
1053 (if win
|
|
1054 (progn
|
|
1055 (select-window win)
|
|
1056 (condition-case nil
|
|
1057 (scroll-down nil)
|
|
1058 (error (goto-char (point-max))))
|
|
1059 (select-window owin))
|
|
1060 (scroll-down nil))))
|
|
1061
|
|
1062 ;; ---------------------------------------------------------------------- ;;
|
|
1063
|
|
1064 (defun hyper-apropos-mouse-get-doc (event)
|
|
1065 "Get the documentation for the symbol the mouse is on."
|
|
1066 (interactive "e")
|
|
1067 (mouse-set-point event)
|
|
1068 (let ((e (extent-at (point) nil 'hyper-apropos-custom)))
|
|
1069 (if e
|
|
1070 (funcall (extent-property e 'hyper-apropos-custom))
|
|
1071 (save-excursion
|
|
1072 (let ((symbol (hyper-apropos-this-symbol)))
|
|
1073 (if symbol
|
|
1074 (hyper-apropos-get-doc symbol)
|
|
1075 (error "Click on a symbol")))))))
|
|
1076
|
|
1077 ;; ---------------------------------------------------------------------- ;;
|
|
1078
|
|
1079 (defun hyper-apropos-add-keyword (pattern)
|
|
1080 "Use additional keyword to narrow regexp match.
|
|
1081 Deletes lines which don't match PATTERN."
|
|
1082 (interactive "sAdditional Keyword: ")
|
|
1083 (save-excursion
|
|
1084 (goto-char (point-min))
|
|
1085 (let (buffer-read-only)
|
|
1086 (keep-lines (concat pattern "\\|" hyper-apropos-junk-regexp))
|
|
1087 )))
|
|
1088
|
|
1089 (defun hyper-apropos-eliminate-keyword (pattern)
|
|
1090 "Use additional keyword to eliminate uninteresting matches.
|
|
1091 Deletes lines which match PATTERN."
|
|
1092 (interactive "sKeyword to eliminate: ")
|
|
1093 (save-excursion
|
|
1094 (goto-char (point-min))
|
|
1095 (let (buffer-read-only)
|
|
1096 (flush-lines pattern))
|
|
1097 ))
|
|
1098
|
|
1099 ;; ---------------------------------------------------------------------- ;;
|
|
1100
|
|
1101 (defun hyper-apropos-this-symbol ()
|
|
1102 (save-excursion
|
|
1103 (cond ((eq major-mode 'hyper-apropos-mode)
|
|
1104 (beginning-of-line)
|
|
1105 (if (looking-at hyper-apropos-junk-regexp)
|
|
1106 nil
|
|
1107 (forward-char 3)
|
|
1108 (read (point-marker))))
|
444
|
1109 ;; What's this? This ends up in the same symbol already described.
|
|
1110 ;; ((and
|
|
1111 ;; (eq major-mode 'hyper-apropos-help-mode)
|
|
1112 ;; (> (point) (point-min)))
|
|
1113 ;; (save-excursion
|
|
1114 ;; (goto-char (point-min))
|
|
1115 ;; (hyper-apropos-this-symbol)))
|
428
|
1116 (t
|
|
1117 (let* ((st (progn
|
|
1118 (skip-syntax-backward "w_")
|
|
1119 ;; !@(*$^%%# stupid backquote implementation!!!
|
|
1120 (skip-chars-forward "`")
|
|
1121 (point)))
|
|
1122 (en (progn
|
|
1123 (skip-syntax-forward "w_")
|
|
1124 (skip-chars-backward ".':") ; : for Local Variables
|
|
1125 (point))))
|
|
1126 (and (not (eq st en))
|
|
1127 (intern-soft (buffer-substring st en))))))))
|
|
1128
|
|
1129 (defun hyper-apropos-where-is (symbol)
|
|
1130 "Find keybinding for symbol on current line."
|
|
1131 (interactive (list (hyper-apropos-this-symbol)))
|
|
1132 (where-is symbol))
|
|
1133
|
|
1134 (defun hyper-apropos-invoke-fn (fn)
|
|
1135 "Interactively invoke the function on the current line."
|
|
1136 (interactive (list (hyper-apropos-this-symbol)))
|
|
1137 (cond ((not (fboundp fn))
|
|
1138 (error "%S is not a function" fn))
|
|
1139 (t (call-interactively fn))))
|
|
1140
|
|
1141 ;;;###autoload
|
|
1142 (defun hyper-set-variable (var val &optional this-ref-buffer)
|
|
1143 (interactive
|
|
1144 (let ((var (hyper-apropos-read-variable-symbol
|
|
1145 (if (hyper-apropos-follow-ref-buffer current-prefix-arg)
|
|
1146 "In ref buffer, set user option"
|
|
1147 "Set user option")
|
|
1148 'user-variable-p)))
|
|
1149 (list var (hyper-apropos-read-variable-value var) current-prefix-arg)))
|
|
1150 (hyper-apropos-set-variable var val this-ref-buffer))
|
|
1151
|
|
1152 ;;;###autoload
|
|
1153 (defun hyper-apropos-set-variable (var val &optional this-ref-buffer)
|
|
1154 "Interactively set the variable on the current line."
|
|
1155 (interactive
|
|
1156 (let ((var (hyper-apropos-this-symbol)))
|
|
1157 (or (and var (boundp var))
|
|
1158 (setq var nil))
|
|
1159 (list var (hyper-apropos-read-variable-value var))))
|
|
1160 (and var
|
|
1161 (boundp var)
|
|
1162 (progn
|
|
1163 (if (hyper-apropos-follow-ref-buffer this-ref-buffer)
|
|
1164 (save-excursion
|
|
1165 (set-buffer hyper-apropos-ref-buffer)
|
|
1166 (set var val))
|
|
1167 (set var val))
|
|
1168 (hyper-apropos-get-doc var t '(variable) this-ref-buffer))))
|
|
1169 ;;;###autoload
|
|
1170 (define-obsolete-function-alias
|
|
1171 'hypropos-set-variable 'hyper-apropos-set-variable)
|
|
1172
|
|
1173 (defun hyper-apropos-read-variable-value (var &optional this-ref-buffer)
|
|
1174 (and var
|
|
1175 (boundp var)
|
|
1176 (let ((prop (get var 'variable-interactive))
|
|
1177 (print-readably t)
|
|
1178 val str)
|
|
1179 (hyper-apropos-get-doc var t '(variable) current-prefix-arg)
|
|
1180 (if prop
|
|
1181 (call-interactively (list 'lambda '(arg)
|
|
1182 (list 'interactive prop)
|
|
1183 'arg))
|
|
1184 (setq val (if (hyper-apropos-follow-ref-buffer this-ref-buffer)
|
|
1185 (save-excursion
|
|
1186 (set-buffer hyper-apropos-ref-buffer)
|
|
1187 (symbol-value var))
|
|
1188 (symbol-value var))
|
|
1189 str (prin1-to-string val))
|
|
1190 (eval-minibuffer
|
|
1191 (format "Set %s `%s' to value (evaluated): "
|
|
1192 (if (user-variable-p var) "user option" "Variable")
|
|
1193 var)
|
|
1194 (condition-case nil
|
|
1195 (progn
|
|
1196 (read str)
|
|
1197 (format (if (or (consp val)
|
|
1198 (and (symbolp val)
|
|
1199 (not (memq val '(t nil)))))
|
|
1200 "'%s" "%s")
|
|
1201 str))
|
|
1202 (error nil)))))))
|
|
1203
|
|
1204 (defun hyper-apropos-customize-variable ()
|
|
1205 (interactive)
|
|
1206 (let ((var (hyper-apropos-this-symbol)))
|
430
|
1207 (and
|
|
1208 (or (and var (boundp var))
|
|
1209 (setq var nil))
|
|
1210 (customize-variable var))))
|
428
|
1211
|
|
1212 ;; ---------------------------------------------------------------------- ;;
|
|
1213
|
|
1214 (defun hyper-apropos-find-tag (&optional tag-name)
|
|
1215 "Find the tag for the symbol on the current line in other window. In
|
|
1216 order for this to work properly, the variable `tag-table-alist' or
|
|
1217 `tags-file-name' must be set so that a TAGS file with tags for the emacs
|
|
1218 source is found for the \"*Hyper Apropos*\" buffer."
|
|
1219 (interactive)
|
|
1220 ;; there ought to be a default tags file for this...
|
|
1221 (or tag-name (setq tag-name (symbol-name (hyper-apropos-this-symbol))))
|
|
1222 (find-tag-other-window (list tag-name)))
|
|
1223
|
|
1224 ;; ---------------------------------------------------------------------- ;;
|
|
1225
|
|
1226 (defun hyper-apropos-find-function (fn)
|
|
1227 "Find the function for the symbol on the current line in other
|
|
1228 window. (See also `find-function'.)"
|
|
1229 (interactive
|
|
1230 (let ((fn (hyper-apropos-this-symbol)))
|
|
1231 (or (fboundp fn)
|
|
1232 (setq fn nil))
|
|
1233 (list fn)))
|
|
1234 (if fn
|
776
|
1235 (if-fboundp 'find-function-other-window
|
|
1236 (find-function-other-window fn)
|
|
1237 (error 'unimplemented "`find-func' package unavailable"))))
|
428
|
1238
|
718
|
1239 (defun hyper-apropos-find-variable (fn)
|
|
1240 "Find the variable for the symbol on the current line in other
|
|
1241 window. (See also `find-variable'.)"
|
|
1242 (interactive
|
|
1243 (let ((fn (hyper-apropos-this-symbol)))
|
|
1244 (or (boundp fn)
|
|
1245 (setq fn nil))
|
|
1246 (list fn)))
|
|
1247 (if fn
|
776
|
1248 (if-fboundp 'find-variable-other-window
|
|
1249 (find-variable-other-window fn)
|
|
1250 (error 'unimplemented "`find-func' package unavailable"))))
|
718
|
1251
|
428
|
1252 ;; ---------------------------------------------------------------------- ;;
|
|
1253
|
|
1254 (defun hyper-apropos-disassemble (sym)
|
|
1255 "Disassemble FUN if it is byte-coded. If it's a lambda, prettyprint it."
|
|
1256 (interactive (list (hyper-apropos-this-symbol)))
|
|
1257 (let ((fun sym) (trail nil) macrop)
|
|
1258 (while (and (symbolp fun) (not (memq fun trail)))
|
|
1259 (setq trail (cons fun trail)
|
|
1260 fun (symbol-function fun)))
|
|
1261 (and (symbolp fun)
|
|
1262 (error "Loop detected in function binding of `%s'" fun))
|
|
1263 (setq macrop (and (consp fun)
|
|
1264 (eq 'macro (car fun))))
|
|
1265 (cond ((compiled-function-p (if macrop (cdr fun) fun))
|
|
1266 (disassemble fun)
|
|
1267 (set-buffer "*Disassemble*")
|
|
1268 (goto-char (point-min))
|
|
1269 (forward-sexp 2)
|
|
1270 (insert (format " for function `%S'" sym))
|
|
1271 )
|
|
1272 ((consp fun)
|
|
1273 (with-current-buffer "*Disassemble*"
|
|
1274 (cl-prettyprint (if macrop
|
|
1275 (cons 'defmacro (cons sym (cdr (cdr fun))))
|
|
1276 (cons 'defun (cons sym (cdr fun))))))
|
|
1277 (set-buffer "*Disassemble*")
|
|
1278 (emacs-lisp-mode))
|
|
1279 ((or (vectorp fun) (stringp fun))
|
|
1280 ;; #### - do something fancy here
|
|
1281 (with-output-to-temp-buffer "*Disassemble*"
|
|
1282 (princ (format "%s is a keyboard macro:\n\n\t" sym))
|
|
1283 (prin1 fun)))
|
|
1284 (t
|
|
1285 (error "Sorry, cannot disassemble `%s'" sym)))))
|
|
1286
|
|
1287 ;; ---------------------------------------------------------------------- ;;
|
|
1288
|
|
1289 (defun hyper-apropos-quit ()
|
|
1290 (interactive)
|
|
1291 "Quit Hyper Apropos and restore original window config."
|
|
1292 (let ((buf (get-buffer hyper-apropos-apropos-buf)))
|
|
1293 (and buf (bury-buffer buf)))
|
|
1294 (set-window-configuration hyper-apropos-prev-wconfig))
|
|
1295
|
|
1296 ;; ---------------------------------------------------------------------- ;;
|
|
1297
|
|
1298 ;;;###autoload
|
|
1299 (defun hyper-apropos-popup-menu (event)
|
|
1300 (interactive "e")
|
|
1301 (mouse-set-point event)
|
430
|
1302 (let* ((sym (hyper-apropos-this-symbol))
|
428
|
1303 (notjunk (not (null sym)))
|
|
1304 (command-p (if (commandp sym) t))
|
|
1305 (variable-p (and sym (boundp sym)))
|
|
1306 (customizable-p (and variable-p
|
|
1307 (get sym 'custom-type)
|
|
1308 t))
|
|
1309 (function-p (fboundp sym))
|
|
1310 (apropos-p (eq 'hyper-apropos-mode
|
|
1311 (save-excursion (set-buffer (event-buffer event))
|
|
1312 major-mode)))
|
|
1313 (name (if sym (symbol-name sym) ""))
|
|
1314 (hyper-apropos-menu
|
|
1315 (delete
|
|
1316 nil
|
|
1317 (list (concat "Hyper-Help: " name)
|
|
1318 (vector "Display documentation" 'hyper-apropos-get-doc notjunk)
|
|
1319 (vector "Set variable" 'hyper-apropos-set-variable variable-p)
|
|
1320 (vector "Customize variable" 'hyper-apropos-customize-variable
|
|
1321 customizable-p)
|
|
1322 (vector "Show keys for" 'hyper-apropos-where-is command-p)
|
|
1323 (vector "Invoke command" 'hyper-apropos-invoke-fn command-p)
|
|
1324 (vector "Find function" 'hyper-apropos-find-function function-p)
|
|
1325 (vector "Find tag" 'hyper-apropos-find-tag notjunk)
|
|
1326 (and apropos-p
|
|
1327 ["Add keyword..." hyper-apropos-add-keyword t])
|
|
1328 (and apropos-p
|
|
1329 ["Eliminate keyword..." hyper-apropos-eliminate-keyword t])
|
|
1330 (if apropos-p
|
|
1331 ["Programmers' Apropos" hyper-apropos-toggle-programming-flag
|
|
1332 :style toggle :selected hyper-apropos-programming-apropos]
|
|
1333 ["Programmers' Help" hyper-apropos-toggle-programming-flag
|
|
1334 :style toggle :selected hyper-apropos-programming-apropos])
|
|
1335 (and hyper-apropos-programming-apropos
|
|
1336 (vector "Disassemble function"
|
|
1337 'hyper-apropos-disassemble
|
|
1338 function-p))
|
|
1339 ["Help" describe-mode t]
|
|
1340 ["Quit" hyper-apropos-quit t]
|
|
1341 ))))
|
|
1342 (popup-menu hyper-apropos-menu)))
|
|
1343 ;;;###autoload
|
|
1344 (define-obsolete-function-alias
|
|
1345 'hypropos-popup-menu 'hyper-apropos-popup-menu)
|
|
1346
|
|
1347 (provide 'hyper-apropos)
|
|
1348
|
|
1349 ;; end of hyper-apropos.el
|