Mercurial > emacs
annotate lisp/emacs-lisp/helper.el @ 112442:76fa839f455e
* Makefile.in (MAKEINFO): Now controlled by `configure'.
(MAKEINFO_OPTS): New variable. Use it where appropriate.
(ENVADD): New variable to control texi2dvi and texi2pdf.
author | Werner Lemberg <wl@gnu.org> |
---|---|
date | Sun, 23 Jan 2011 11:22:21 +0100 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; helper.el --- utility help package supporting help in electric modes |
36 | 2 |
74466 | 3 ;; Copyright (C) 1985, 2001, 2002, 2003, 2004, 2005, |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
4 ;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
845 | 5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
6 ;; Author: K. Shane Hartman |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
7 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
8 ;; Keywords: help |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
9 ;; Package: emacs |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
10 |
36 | 11 ;; This file is part of GNU Emacs. |
12 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87567
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
36 | 14 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87567
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87567
diff
changeset
|
16 ;; (at your option) any later version. |
36 | 17 |
18 ;; GNU Emacs 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 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87567
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
36 | 25 |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
27854
diff
changeset
|
26 ;;; Commentary: |
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
27854
diff
changeset
|
27 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
28 ;;; Code: |
36 | 29 |
14169 | 30 ;; hey, here's a helping hand. |
36 | 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) | |
71743
ce0614025964
* emacs-lisp/helper.el (Helper-help-scroller): Don't signal error
Chong Yidong <cyd@stupidchicken.com>
parents:
68648
diff
changeset
|
79 (setq continue (read-event)) |
49843
e77b1b1735f4
(Helper-help-scroller): Fix character constant.
Juanma Barranquero <lekktu@gmail.com>
parents:
38412
diff
changeset
|
80 (cond ((and (memq continue '(?\s ?\C-v)) (< state 2)) |
36 | 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) | |
208 | 96 "Briefly describe binding of KEY." |
36 | 97 (interactive "kDescribe key briefly: ") |
98 (describe-key-briefly key) | |
99 (sit-for 4)) | |
100 | |
101 (defun Helper-describe-key (key) | |
208 | 102 "Describe binding of KEY." |
36 | 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) | |
87567
4c3c683cdff8
* erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
122 (let ((name (format-mode-line mode-name)) |
36 | 123 (documentation (documentation major-mode))) |
87567
4c3c683cdff8
* erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
124 (with-current-buffer (get-buffer-create "*Help*") |
27854
cc746270613e
(Helper-describe-mode): Make buffer writable.
Gerd Moellmann <gerd@gnu.org>
parents:
14169
diff
changeset
|
125 (setq buffer-read-only nil) |
36 | 126 (erase-buffer) |
9853
2018a5a1da69
(Helper-describe-mode): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
127 (insert name " Mode\n" documentation) |
2018a5a1da69
(Helper-describe-mode): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
128 (help-mode))) |
36 | 129 (Helper-help-scroller)) |
130 | |
258 | 131 ;;;###autoload |
36 | 132 (defun Helper-describe-bindings () |
133 "Describe local key bindings of current mode." | |
134 (interactive) | |
135 (message "Making binding list...") | |
136 (save-window-excursion (describe-bindings)) | |
137 (Helper-help-scroller)) | |
138 | |
258 | 139 ;;;###autoload |
36 | 140 (defun Helper-help () |
141 "Provide help for current mode." | |
142 (interactive) | |
143 (let ((continue t) c) | |
144 (while continue | |
145 (message "Help (Type ? for further options)") | |
11758
eb208ec6d216
(Helper-help): Use read-key-sequence.
Richard M. Stallman <rms@gnu.org>
parents:
9853
diff
changeset
|
146 (setq c (read-key-sequence nil)) |
36 | 147 (setq c (lookup-key Helper-help-map c)) |
148 (cond ((eq c 'Helper-help-options) | |
149 (Helper-help-options)) | |
150 ((commandp c) | |
151 (call-interactively c) | |
152 (setq continue nil)) | |
153 (t | |
154 (ding) | |
155 (setq continue nil)))))) | |
156 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
157 (provide 'helper) |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
158 |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
159 ;;; helper.el ends here |