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