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