annotate lisp/electric/helper.el @ 131:869e1851236b xemacs-20-1p4

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