1 ;;; helper.el --- utility help package supporting help in electric modes
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
4 ;; Principal author K. Shane Hartman
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 1, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 ; hey, here's a helping hand.
25 ;; Bind this to a string for <blank> in "... Other keys <blank>".
26 ;; Helper-help uses this to construct help string when scrolling.
27 ;; Defaults to "return"
28 (defvar Helper-return-blurb nil
)
30 ;; Keymap implementation doesn't work too well for non-standard loops.
31 ;; But define it anyway for those who can use it. Non-standard loops
32 ;; will probably have to use Helper-help. You can't autoload the
36 (defvar Helper-help-map nil
)
39 (setq Helper-help-map
(make-keymap))
40 ;(fillarray Helper-help-map 'undefined)
41 (define-key Helper-help-map
"m" 'Helper-describe-mode
)
42 (define-key Helper-help-map
"b" 'Helper-describe-bindings
)
43 (define-key Helper-help-map
"c" 'Helper-describe-key-briefly
)
44 (define-key Helper-help-map
"k" 'Helper-describe-key
)
45 ;(define-key Helper-help-map "f" 'Helper-describe-function)
46 ;(define-key Helper-help-map "v" 'Helper-describe-variable)
47 (define-key Helper-help-map
"?" 'Helper-help-options
)
48 (define-key Helper-help-map
(char-to-string help-char
) 'Helper-help-options
)
49 (fset 'Helper-help-map Helper-help-map
))
51 (defun Helper-help-scroller ()
52 (let ((blurb (or (and (boundp 'Helper-return-blurb
)
55 (save-window-excursion
56 (goto-char (window-start (selected-window)))
57 (if (get-buffer-window "*Help*")
58 (pop-to-buffer "*Help*")
59 (switch-to-buffer "*Help*"))
60 (goto-char (point-min))
61 (let ((continue t
) state
)
63 (setq state
(+ (* 2 (if (pos-visible-in-window-p (point-max)) 1 0))
64 (if (pos-visible-in-window-p (point-min)) 1 0)))
67 '("Space forward, Delete back. Other keys %s"
68 "Space scrolls forward. Other keys %s"
69 "Delete scrolls back. Other keys %s"
70 "Type anything to %s"))
72 (setq continue
(read-char))
73 (cond ((and (memq continue
'(?\ ?\C-v
)) (< state
2))
77 ((and (= continue ?
\177) (zerop (% state
2)))
79 (t (setq continue nil
))))))))
81 (defun Helper-help-options ()
82 "Describe help options."
84 (message "c (key briefly), m (mode), k (key), b (bindings)")
85 ;(message "c (key briefly), m (mode), k (key), v (variable), f (function)")
88 (defun Helper-describe-key-briefly (key)
89 "Briefly describe binding of KEY."
90 (interactive "kDescribe key briefly: ")
91 (describe-key-briefly key
)
94 (defun Helper-describe-key (key)
95 "Describe binding of KEY."
96 (interactive "kDescribe key: ")
97 (save-window-excursion (describe-key key
))
98 (Helper-help-scroller))
100 (defun Helper-describe-function ()
101 "Describe a function. Name read interactively."
103 (save-window-excursion (call-interactively 'describe-function
))
104 (Helper-help-scroller))
106 (defun Helper-describe-variable ()
107 "Describe a variable. Name read interactively."
109 (save-window-excursion (call-interactively 'describe-variable
))
110 (Helper-help-scroller))
112 (defun Helper-describe-mode ()
113 "Describe the current mode."
115 (let ((name mode-name
)
116 (documentation (documentation major-mode
)))
118 (set-buffer (get-buffer-create "*Help*"))
120 (insert name
" Mode\n" documentation
)))
121 (Helper-help-scroller))
124 (defun Helper-describe-bindings ()
125 "Describe local key bindings of current mode."
127 (message "Making binding list...")
128 (save-window-excursion (describe-bindings))
129 (Helper-help-scroller))
132 (defun Helper-help ()
133 "Provide help for current mode."
135 (let ((continue t
) c
)
137 (message "Help (Type ? for further options)")
138 (setq c
(char-to-string (downcase (read-char))))
139 (setq c
(lookup-key Helper-help-map c
))
140 (cond ((eq c
'Helper-help-options
)
141 (Helper-help-options))
143 (call-interactively c
)
147 (setq continue nil
))))))
151 ;;; helper.el ends here