Add arch taglines
[bpt/emacs.git] / lisp / emacs-lisp / helper.el
CommitLineData
1a06eabd 1;;; helper.el --- utility help package supporting help in electric modes
a2535589 2
9750e079
ER
3;; Copyright (C) 1985 Free Software Foundation, Inc.
4
e5167999
ER
5;; Author: K. Shane Hartman
6;; Maintainer: FSF
fd7fa35a 7;; Keywords: help
e5167999 8
a2535589
JA
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
a2535589
JA
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267
EN
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
a2535589 25
55535639
PJ
26;;; Commentary:
27
e5167999 28;;; Code:
a2535589 29
b578f267 30;; hey, here's a helping hand.
a2535589
JA
31
32;; Bind this to a string for <blank> in "... Other keys <blank>".
33;; Helper-help uses this to construct help string when scrolling.
34;; Defaults to "return"
35(defvar Helper-return-blurb nil)
36
37;; Keymap implementation doesn't work too well for non-standard loops.
38;; But define it anyway for those who can use it. Non-standard loops
39;; will probably have to use Helper-help. You can't autoload the
40;; keymap either.
41
42
43(defvar Helper-help-map nil)
44(if Helper-help-map
45 nil
46 (setq Helper-help-map (make-keymap))
47 ;(fillarray Helper-help-map 'undefined)
48 (define-key Helper-help-map "m" 'Helper-describe-mode)
49 (define-key Helper-help-map "b" 'Helper-describe-bindings)
50 (define-key Helper-help-map "c" 'Helper-describe-key-briefly)
51 (define-key Helper-help-map "k" 'Helper-describe-key)
52 ;(define-key Helper-help-map "f" 'Helper-describe-function)
53 ;(define-key Helper-help-map "v" 'Helper-describe-variable)
54 (define-key Helper-help-map "?" 'Helper-help-options)
55 (define-key Helper-help-map (char-to-string help-char) 'Helper-help-options)
56 (fset 'Helper-help-map Helper-help-map))
57
58(defun Helper-help-scroller ()
59 (let ((blurb (or (and (boundp 'Helper-return-blurb)
60 Helper-return-blurb)
61 "return")))
62 (save-window-excursion
63 (goto-char (window-start (selected-window)))
64 (if (get-buffer-window "*Help*")
65 (pop-to-buffer "*Help*")
66 (switch-to-buffer "*Help*"))
67 (goto-char (point-min))
68 (let ((continue t) state)
69 (while continue
70 (setq state (+ (* 2 (if (pos-visible-in-window-p (point-max)) 1 0))
71 (if (pos-visible-in-window-p (point-min)) 1 0)))
72 (message
73 (nth state
74 '("Space forward, Delete back. Other keys %s"
75 "Space scrolls forward. Other keys %s"
76 "Delete scrolls back. Other keys %s"
77 "Type anything to %s"))
78 blurb)
79 (setq continue (read-char))
6cae7b73 80 (cond ((and (memq continue '(?\s ?\C-v)) (< state 2))
a2535589
JA
81 (scroll-up))
82 ((= continue ?\C-l)
83 (recenter))
84 ((and (= continue ?\177) (zerop (% state 2)))
85 (scroll-down))
86 (t (setq continue nil))))))))
87
88(defun Helper-help-options ()
89 "Describe help options."
90 (interactive)
91 (message "c (key briefly), m (mode), k (key), b (bindings)")
92 ;(message "c (key briefly), m (mode), k (key), v (variable), f (function)")
93 (sit-for 4))
94
95(defun Helper-describe-key-briefly (key)
8a1281b5 96 "Briefly describe binding of KEY."
a2535589
JA
97 (interactive "kDescribe key briefly: ")
98 (describe-key-briefly key)
99 (sit-for 4))
100
101(defun Helper-describe-key (key)
8a1281b5 102 "Describe binding of KEY."
a2535589
JA
103 (interactive "kDescribe key: ")
104 (save-window-excursion (describe-key key))
105 (Helper-help-scroller))
106
107(defun Helper-describe-function ()
108 "Describe a function. Name read interactively."
109 (interactive)
110 (save-window-excursion (call-interactively 'describe-function))
111 (Helper-help-scroller))
112
113(defun Helper-describe-variable ()
114 "Describe a variable. Name read interactively."
115 (interactive)
116 (save-window-excursion (call-interactively 'describe-variable))
117 (Helper-help-scroller))
118
119(defun Helper-describe-mode ()
120 "Describe the current mode."
121 (interactive)
122 (let ((name mode-name)
123 (documentation (documentation major-mode)))
124 (save-excursion
125 (set-buffer (get-buffer-create "*Help*"))
36e98846 126 (setq buffer-read-only nil)
a2535589 127 (erase-buffer)
eab4afdc
KH
128 (insert name " Mode\n" documentation)
129 (help-mode)))
a2535589
JA
130 (Helper-help-scroller))
131
f9f9507e 132;;;###autoload
a2535589
JA
133(defun Helper-describe-bindings ()
134 "Describe local key bindings of current mode."
135 (interactive)
136 (message "Making binding list...")
137 (save-window-excursion (describe-bindings))
138 (Helper-help-scroller))
139
f9f9507e 140;;;###autoload
a2535589
JA
141(defun Helper-help ()
142 "Provide help for current mode."
143 (interactive)
144 (let ((continue t) c)
145 (while continue
146 (message "Help (Type ? for further options)")
3c61e534 147 (setq c (read-key-sequence nil))
a2535589
JA
148 (setq c (lookup-key Helper-help-map c))
149 (cond ((eq c 'Helper-help-options)
150 (Helper-help-options))
151 ((commandp c)
152 (call-interactively c)
153 (setq continue nil))
154 (t
155 (ding)
156 (setq continue nil))))))
157
1a06eabd
ER
158(provide 'helper)
159
ab5796a9 160;;; arch-tag: a0984577-d3e9-4124-ae0d-c46fe740f6a9
1a06eabd 161;;; helper.el ends here