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