Mercurial > emacs
annotate lisp/emacs-lisp/helper.el @ 92432:4fe0858e4c31
(nndoc-oe-dbx-type-p): Use mm-string-to-multibyte.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 03 Mar 2008 04:12:46 +0000 |
parents | 4c3c683cdff8 |
children | 606f2d163a64 90a2847062be |
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, |
87567
4c3c683cdff8
* erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
4 ;; 2006, 2007, 2008 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) | |
87567
4c3c683cdff8
* erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
123 (let ((name (format-mode-line mode-name)) |
36 | 124 (documentation (documentation major-mode))) |
87567
4c3c683cdff8
* erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
125 (with-current-buffer (get-buffer-create "*Help*") |
27854
cc746270613e
(Helper-describe-mode): Make buffer writable.
Gerd Moellmann <gerd@gnu.org>
parents:
14169
diff
changeset
|
126 (setq buffer-read-only nil) |
36 | 127 (erase-buffer) |
9853
2018a5a1da69
(Helper-describe-mode): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
128 (insert name " Mode\n" documentation) |
2018a5a1da69
(Helper-describe-mode): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
129 (help-mode))) |
36 | 130 (Helper-help-scroller)) |
131 | |
258 | 132 ;;;###autoload |
36 | 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 | |
258 | 140 ;;;###autoload |
36 | 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)") | |
11758
eb208ec6d216
(Helper-help): Use read-key-sequence.
Richard M. Stallman <rms@gnu.org>
parents:
9853
diff
changeset
|
147 (setq c (read-key-sequence nil)) |
36 | 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 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
158 (provide 'helper) |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
159 |
87567
4c3c683cdff8
* erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
160 ;; arch-tag: a0984577-d3e9-4124-ae0d-c46fe740f6a9 |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
161 ;;; helper.el ends here |