1 ;; helper - utility help package for modes which want to provide help
2 ;; without relinquishing control, e.g. `electric' modes.
4 ;; Copyright (C) 1985 Free Software Foundation, Inc.
5 ;; Principal author K. Shane Hartman
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 1, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 ; hey, here's a helping hand.
26 ;; Bind this to a string for <blank> in "... Other keys <blank>".
27 ;; Helper-help uses this to construct help string when scrolling.
28 ;; Defaults to "return"
29 (defvar Helper-return-blurb nil
)
31 ;; Keymap implementation doesn't work too well for non-standard loops.
32 ;; But define it anyway for those who can use it. Non-standard loops
33 ;; will probably have to use Helper-help. You can't autoload the
37 (defvar Helper-help-map nil
)
40 (setq Helper-help-map
(make-keymap))
41 ;(fillarray Helper-help-map 'undefined)
42 (define-key Helper-help-map
"m" 'Helper-describe-mode
)
43 (define-key Helper-help-map
"b" 'Helper-describe-bindings
)
44 (define-key Helper-help-map
"c" 'Helper-describe-key-briefly
)
45 (define-key Helper-help-map
"k" 'Helper-describe-key
)
46 ;(define-key Helper-help-map "f" 'Helper-describe-function)
47 ;(define-key Helper-help-map "v" 'Helper-describe-variable)
48 (define-key Helper-help-map
"?" 'Helper-help-options
)
49 (define-key Helper-help-map
(char-to-string help-char
) 'Helper-help-options
)
50 (fset 'Helper-help-map Helper-help-map
))
52 (defun Helper-help-scroller ()
53 (let ((blurb (or (and (boundp 'Helper-return-blurb
)
56 (save-window-excursion
57 (goto-char (window-start (selected-window)))
58 (if (get-buffer-window "*Help*")
59 (pop-to-buffer "*Help*")
60 (switch-to-buffer "*Help*"))
61 (goto-char (point-min))
62 (let ((continue t
) state
)
64 (setq state
(+ (* 2 (if (pos-visible-in-window-p (point-max)) 1 0))
65 (if (pos-visible-in-window-p (point-min)) 1 0)))
68 '("Space forward, Delete back. Other keys %s"
69 "Space scrolls forward. Other keys %s"
70 "Delete scrolls back. Other keys %s"
71 "Type anything to %s"))
73 (setq continue
(read-char))
74 (cond ((and (memq continue
'(?\ ?\C-v
)) (< state
2))
78 ((and (= continue ?
\177) (zerop (% state
2)))
80 (t (setq continue nil
))))))))
82 (defun Helper-help-options ()
83 "Describe help options."
85 (message "c (key briefly), m (mode), k (key), b (bindings)")
86 ;(message "c (key briefly), m (mode), k (key), v (variable), f (function)")
89 (defun Helper-describe-key-briefly (key)
90 "Briefly describe binding of KEY."
91 (interactive "kDescribe key briefly: ")
92 (describe-key-briefly key
)
95 (defun Helper-describe-key (key)
96 "Describe binding of KEY."
97 (interactive "kDescribe key: ")
98 (save-window-excursion (describe-key key
))
99 (Helper-help-scroller))
101 (defun Helper-describe-function ()
102 "Describe a function. Name read interactively."
104 (save-window-excursion (call-interactively 'describe-function
))
105 (Helper-help-scroller))
107 (defun Helper-describe-variable ()
108 "Describe a variable. Name read interactively."
110 (save-window-excursion (call-interactively 'describe-variable
))
111 (Helper-help-scroller))
113 (defun Helper-describe-mode ()
114 "Describe the current mode."
116 (let ((name mode-name
)
117 (documentation (documentation major-mode
)))
119 (set-buffer (get-buffer-create "*Help*"))
121 (insert name
" Mode\n" documentation
)))
122 (Helper-help-scroller))
125 (defun Helper-describe-bindings ()
126 "Describe local key bindings of current mode."
128 (message "Making binding list...")
129 (save-window-excursion (describe-bindings))
130 (Helper-help-scroller))
133 (defun Helper-help ()
134 "Provide help for current mode."
136 (let ((continue t
) c
)
138 (message "Help (Type ? for further options)")
139 (setq c
(char-to-string (downcase (read-char))))
140 (setq c
(lookup-key Helper-help-map c
))
141 (cond ((eq c
'Helper-help-options
)
142 (Helper-help-options))
144 (call-interactively c
)
148 (setq continue nil
))))))