Mercurial > emacs
annotate lisp/emacs-lisp/helper.el @ 86113:8a486bfde38f
(gnus-uu-default-view-rules): Fix typos in docstring.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 15 Nov 2007 16:51:57 +0000 |
parents | 935157c0b596 |
children | 78ee6fae0e41 4c3c683cdff8 f55f9811f5d7 |
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, |
75346 | 4 ;; 2006, 2007 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 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
9 |
36 | 10 ;; This file is part of GNU Emacs. |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
78217
935157c0b596
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
36 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
36 | 26 |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
27854
diff
changeset
|
27 ;;; Commentary: |
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
27854
diff
changeset
|
28 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
29 ;;; Code: |
36 | 30 |
14169 | 31 ;; hey, here's a helping hand. |
36 | 32 |
33 ;; Bind this to a string for <blank> in "... Other keys <blank>". | |
34 ;; Helper-help uses this to construct help string when scrolling. | |
35 ;; Defaults to "return" | |
36 (defvar Helper-return-blurb nil) | |
37 | |
38 ;; Keymap implementation doesn't work too well for non-standard loops. | |
39 ;; But define it anyway for those who can use it. Non-standard loops | |
40 ;; will probably have to use Helper-help. You can't autoload the | |
41 ;; keymap either. | |
42 | |
43 | |
44 (defvar Helper-help-map nil) | |
45 (if Helper-help-map | |
46 nil | |
47 (setq Helper-help-map (make-keymap)) | |
48 ;(fillarray Helper-help-map 'undefined) | |
49 (define-key Helper-help-map "m" 'Helper-describe-mode) | |
50 (define-key Helper-help-map "b" 'Helper-describe-bindings) | |
51 (define-key Helper-help-map "c" 'Helper-describe-key-briefly) | |
52 (define-key Helper-help-map "k" 'Helper-describe-key) | |
53 ;(define-key Helper-help-map "f" 'Helper-describe-function) | |
54 ;(define-key Helper-help-map "v" 'Helper-describe-variable) | |
55 (define-key Helper-help-map "?" 'Helper-help-options) | |
56 (define-key Helper-help-map (char-to-string help-char) 'Helper-help-options) | |
57 (fset 'Helper-help-map Helper-help-map)) | |
58 | |
59 (defun Helper-help-scroller () | |
60 (let ((blurb (or (and (boundp 'Helper-return-blurb) | |
61 Helper-return-blurb) | |
62 "return"))) | |
63 (save-window-excursion | |
64 (goto-char (window-start (selected-window))) | |
65 (if (get-buffer-window "*Help*") | |
66 (pop-to-buffer "*Help*") | |
67 (switch-to-buffer "*Help*")) | |
68 (goto-char (point-min)) | |
69 (let ((continue t) state) | |
70 (while continue | |
71 (setq state (+ (* 2 (if (pos-visible-in-window-p (point-max)) 1 0)) | |
72 (if (pos-visible-in-window-p (point-min)) 1 0))) | |
73 (message | |
74 (nth state | |
75 '("Space forward, Delete back. Other keys %s" | |
76 "Space scrolls forward. Other keys %s" | |
77 "Delete scrolls back. Other keys %s" | |
78 "Type anything to %s")) | |
79 blurb) | |
71743
ce0614025964
* emacs-lisp/helper.el (Helper-help-scroller): Don't signal error
Chong Yidong <cyd@stupidchicken.com>
parents:
68648
diff
changeset
|
80 (setq continue (read-event)) |
49843
e77b1b1735f4
(Helper-help-scroller): Fix character constant.
Juanma Barranquero <lekktu@gmail.com>
parents:
38412
diff
changeset
|
81 (cond ((and (memq continue '(?\s ?\C-v)) (< state 2)) |
36 | 82 (scroll-up)) |
83 ((= continue ?\C-l) | |
84 (recenter)) | |
85 ((and (= continue ?\177) (zerop (% state 2))) | |
86 (scroll-down)) | |
87 (t (setq continue nil)))))))) | |
88 | |
89 (defun Helper-help-options () | |
90 "Describe help options." | |
91 (interactive) | |
92 (message "c (key briefly), m (mode), k (key), b (bindings)") | |
93 ;(message "c (key briefly), m (mode), k (key), v (variable), f (function)") | |
94 (sit-for 4)) | |
95 | |
96 (defun Helper-describe-key-briefly (key) | |
208 | 97 "Briefly describe binding of KEY." |
36 | 98 (interactive "kDescribe key briefly: ") |
99 (describe-key-briefly key) | |
100 (sit-for 4)) | |
101 | |
102 (defun Helper-describe-key (key) | |
208 | 103 "Describe binding of KEY." |
36 | 104 (interactive "kDescribe key: ") |
105 (save-window-excursion (describe-key key)) | |
106 (Helper-help-scroller)) | |
107 | |
108 (defun Helper-describe-function () | |
109 "Describe a function. Name read interactively." | |
110 (interactive) | |
111 (save-window-excursion (call-interactively 'describe-function)) | |
112 (Helper-help-scroller)) | |
113 | |
114 (defun Helper-describe-variable () | |
115 "Describe a variable. Name read interactively." | |
116 (interactive) | |
117 (save-window-excursion (call-interactively 'describe-variable)) | |
118 (Helper-help-scroller)) | |
119 | |
120 (defun Helper-describe-mode () | |
121 "Describe the current mode." | |
122 (interactive) | |
123 (let ((name mode-name) | |
124 (documentation (documentation major-mode))) | |
125 (save-excursion | |
126 (set-buffer (get-buffer-create "*Help*")) | |
27854
cc746270613e
(Helper-describe-mode): Make buffer writable.
Gerd Moellmann <gerd@gnu.org>
parents:
14169
diff
changeset
|
127 (setq buffer-read-only nil) |
36 | 128 (erase-buffer) |
9853
2018a5a1da69
(Helper-describe-mode): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
129 (insert name " Mode\n" documentation) |
2018a5a1da69
(Helper-describe-mode): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
130 (help-mode))) |
36 | 131 (Helper-help-scroller)) |
132 | |
258 | 133 ;;;###autoload |
36 | 134 (defun Helper-describe-bindings () |
135 "Describe local key bindings of current mode." | |
136 (interactive) | |
137 (message "Making binding list...") | |
138 (save-window-excursion (describe-bindings)) | |
139 (Helper-help-scroller)) | |
140 | |
258 | 141 ;;;###autoload |
36 | 142 (defun Helper-help () |
143 "Provide help for current mode." | |
144 (interactive) | |
145 (let ((continue t) c) | |
146 (while continue | |
147 (message "Help (Type ? for further options)") | |
11758
eb208ec6d216
(Helper-help): Use read-key-sequence.
Richard M. Stallman <rms@gnu.org>
parents:
9853
diff
changeset
|
148 (setq c (read-key-sequence nil)) |
36 | 149 (setq c (lookup-key Helper-help-map c)) |
150 (cond ((eq c 'Helper-help-options) | |
151 (Helper-help-options)) | |
152 ((commandp c) | |
153 (call-interactively c) | |
154 (setq continue nil)) | |
155 (t | |
156 (ding) | |
157 (setq continue nil)))))) | |
158 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
159 (provide 'helper) |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
160 |
52401 | 161 ;;; arch-tag: a0984577-d3e9-4124-ae0d-c46fe740f6a9 |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
162 ;;; helper.el ends here |