aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-10-21 22:23:48 +0000
committerRichard M. Stallman1995-10-21 22:23:48 +0000
commitf98e758c2fda69b27a61d0d782fe21c6934c4585 (patch)
tree98d35f350db17007905daa748d086de50fdba144
parentf135afd3138ceac21ae9b710e3c680434f196009 (diff)
downloademacs-f98e758c2fda69b27a61d0d782fe21c6934c4585.tar.gz
emacs-f98e758c2fda69b27a61d0d782fe21c6934c4585.zip
Fix key bindings.
(electric-help-mode): Use mouse-leave-buffer-hook. (electric-help-retain): Remove mouse-leave-buffer-hook. (with-electric-help): New argument minheight. (electric-help-execute-extended): New function. (electric-help-ctrl-x-prefix): New function. (electric-help-command-loop): Make messages more consistent. Include strategic sit-for 0, so that pos-visible-in-window-p will return the right thing. Make 2nd arg of Electric-command-loop return 'noprompt if we are in isearch-mode. Eval to-be-executed at the very end. (ehelp-map): Electrify apropos too.
-rw-r--r--lisp/ehelp.el83
1 files changed, 67 insertions, 16 deletions
diff --git a/lisp/ehelp.el b/lisp/ehelp.el
index fda84b7a357..756583bfe27 100644
--- a/lisp/ehelp.el
+++ b/lisp/ehelp.el
@@ -45,8 +45,20 @@
45(if electric-help-map 45(if electric-help-map
46 () 46 ()
47 (let ((map (make-keymap))) 47 (let ((map (make-keymap)))
48 ;; allow all non-self-inserting keys - search, scroll, etc 48 ;; allow all non-self-inserting keys - search, scroll, etc, but
49 ;; let M-x and C-x exit ehelp mode and retain buffer:
49 (suppress-keymap map) 50 (suppress-keymap map)
51 (define-key map "\C-u" 'electric-help-undefined)
52 (define-key map [?\C-0] 'electric-help-undefined)
53 (define-key map [?\C-1] 'electric-help-undefined)
54 (define-key map [?\C-2] 'electric-help-undefined)
55 (define-key map [?\C-3] 'electric-help-undefined)
56 (define-key map [?\C-4] 'electric-help-undefined)
57 (define-key map [?\C-5] 'electric-help-undefined)
58 (define-key map [?\C-6] 'electric-help-undefined)
59 (define-key map [?\C-7] 'electric-help-undefined)
60 (define-key map [?\C-8] 'electric-help-undefined)
61 (define-key map [?\C-9] 'electric-help-undefined)
50 (define-key map (char-to-string help-char) 'electric-help-help) 62 (define-key map (char-to-string help-char) 'electric-help-help)
51 (define-key map "?" 'electric-help-help) 63 (define-key map "?" 'electric-help-help)
52 (define-key map " " 'scroll-up) 64 (define-key map " " 'scroll-up)
@@ -60,9 +72,11 @@
60 ;;a better key than this? 72 ;;a better key than this?
61 (define-key map "r" 'electric-help-retain) 73 (define-key map "r" 'electric-help-retain)
62 (define-key map "R" 'electric-help-retain) 74 (define-key map "R" 'electric-help-retain)
75 (define-key map "\ex" 'electric-help-execute-extended)
76 (define-key map "\C-x" 'electric-help-ctrl-x-prefix)
63 77
64 (setq electric-help-map map))) 78 (setq electric-help-map map)))
65 79
66(defun electric-help-mode () 80(defun electric-help-mode ()
67 "`with-electric-help' temporarily places its buffer in this mode. 81 "`with-electric-help' temporarily places its buffer in this mode.
68\(On exit from `with-electric-help', the buffer is put in `default-major-mode'.)" 82\(On exit from `with-electric-help', the buffer is put in `default-major-mode'.)"
@@ -71,6 +85,7 @@
71 (setq major-mode 'help) 85 (setq major-mode 'help)
72 (setq mode-line-buffer-identification '(" Help: %b")) 86 (setq mode-line-buffer-identification '(" Help: %b"))
73 (use-local-map electric-help-map) 87 (use-local-map electric-help-map)
88 (setq mouse-leave-buffer-hook '(electric-help-retain))
74 ;; this is done below in with-electric-help 89 ;; this is done below in with-electric-help
75 ;(run-hooks 'electric-help-mode-hook) 90 ;(run-hooks 'electric-help-mode-hook)
76 ) 91 )
@@ -78,10 +93,11 @@
78;;;###autoload 93;;;###autoload
79(defun with-electric-help (thunk &optional buffer noerase) 94(defun with-electric-help (thunk &optional buffer noerase)
80 "Pop up an \"electric\" help buffer. 95 "Pop up an \"electric\" help buffer.
81Arguments are THUNK &optional BUFFER NOERASE. BUFFER defaults to `*Help*'. 96The arguments are THUNK &optional BUFFER NOERASE MINHEIGHT.
82THUNK is a function of no arguments which is called to initialize 97THUNK is a function of no arguments which is called to initialize the
83the contents of BUFFER. BUFFER will be erased before THUNK is called unless 98contents of BUFFER. BUFFER defaults to `*Help*'. BUFFER will be
84NOERASE is non-nil. THUNK will be called with `standard-output' bound to 99erased before THUNK is called unless NOERASE is non-nil. THUNK will
100be called while BUFFER is current and with `standard-output' bound to
85the buffer specified by BUFFER. 101the buffer specified by BUFFER.
86 102
87If THUNK returns nil, we display BUFFER starting at the top, and 103If THUNK returns nil, we display BUFFER starting at the top, and
@@ -89,14 +105,21 @@ shrink the window to fit. If THUNK returns non-nil, we don't do those things.
89 105
90After THUNK has been called, this function \"electrically\" pops up a window 106After THUNK has been called, this function \"electrically\" pops up a window
91in which BUFFER is displayed and allows the user to scroll through that buffer 107in which BUFFER is displayed and allows the user to scroll through that buffer
92in electric-help-mode. 108in electric-help-mode. The window's height will be at least MINHEIGHT if
109this value is non-nil.
110
111If THUNK returns nil, we display BUFFER starting at the top, and
112shrink the window to fit. If THUNK returns non-nil, we don't do those
113things.
114
93When the user exits (with `electric-help-exit', or otherwise) the help 115When the user exits (with `electric-help-exit', or otherwise) the help
94buffer's window disappears (i.e., we use `save-window-excursion') 116buffer's window disappears (i.e., we use `save-window-excursion')
95BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit." 117BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit."
96 (setq buffer (get-buffer-create (or buffer "*Help*"))) 118 (setq buffer (get-buffer-create (or buffer "*Help*")))
97 (let ((one (one-window-p t)) 119 (let ((one (one-window-p t))
98 (config (current-window-configuration)) 120 (config (current-window-configuration))
99 (bury nil)) 121 (bury nil)
122 (to-be-executed nil))
100 (unwind-protect 123 (unwind-protect
101 (save-excursion 124 (save-excursion
102 (if one (goto-char (window-start (selected-window)))) 125 (if one (goto-char (window-start (selected-window))))
@@ -104,8 +127,9 @@ BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit."
104 (pop-to-buffer buffer)) 127 (pop-to-buffer buffer))
105 (save-excursion 128 (save-excursion
106 (set-buffer buffer) 129 (set-buffer buffer)
130 (if (and minheight (< (window-height) minheight))
131 (enlarge-window (- minheight (window-height))))
107 (electric-help-mode) 132 (electric-help-mode)
108 (setq buffer-read-only nil)
109 (or noerase (erase-buffer))) 133 (or noerase (erase-buffer)))
110 (let ((standard-output buffer)) 134 (let ((standard-output buffer))
111 (if (not (funcall thunk)) 135 (if (not (funcall thunk))
@@ -133,7 +157,8 @@ BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit."
133 ;; so that when we say "Press space to bury" we mean it 157 ;; so that when we say "Press space to bury" we mean it
134 (replace-buffer-in-windows buffer) 158 (replace-buffer-in-windows buffer)
135 ;; must do this outside of save-window-excursion 159 ;; must do this outside of save-window-excursion
136 (bury-buffer buffer)))))) 160 (bury-buffer buffer)))
161 (eval to-be-executed))))
137 162
138(defun electric-help-command-loop () 163(defun electric-help-command-loop ()
139 (catch 'exit 164 (catch 'exit
@@ -155,9 +180,13 @@ BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit."
155 (Electric-command-loop 180 (Electric-command-loop
156 'exit 181 'exit
157 (function (lambda () 182 (function (lambda ()
183 (sit-for 0) ;necessary if last command was end-of-buffer or
184 ;beginning-of-buffer - otherwise pos-visible-in-window-p
185 ;will yield a wrong result.
158 (let ((min (pos-visible-in-window-p (point-min))) 186 (let ((min (pos-visible-in-window-p (point-min)))
159 (max (pos-visible-in-window-p (point-max)))) 187 (max (pos-visible-in-window-p (point-max))))
160 (cond ((and min max) 188 (cond (isearch-mode 'noprompt)
189 ((and min max)
161 (cond (standard "Press q to exit, r to retain ") 190 (cond (standard "Press q to exit, r to retain ")
162 (neither) 191 (neither)
163 (t (setq neither (substitute-command-keys "Press \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) 192 (t (setq neither (substitute-command-keys "Press \\[electric-help-exit] to exit, \\[electric-help-retain] to retain ")))))
@@ -166,11 +195,11 @@ BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit."
166 (up) 195 (up)
167 (t (setq up (substitute-command-keys "Press \\[scroll-up] to scroll, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) 196 (t (setq up (substitute-command-keys "Press \\[scroll-up] to scroll, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain ")))))
168 (max 197 (max
169 (cond (standard "Press DEL to scroll back, q to exit ") 198 (cond (standard "Press DEL to scroll back, q to exit, r to retain ")
170 (down) 199 (down)
171 (t (setq down (substitute-command-keys "Press \\[scroll-down] to scroll back, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) 200 (t (setq down (substitute-command-keys "Press \\[scroll-down] to scroll back, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain ")))))
172 (t 201 (t
173 (cond (standard "Press SPC to scroll, DEL to scroll back, q to exit ") 202 (cond (standard "Press SPC to scroll, DEL to scroll back, q to exit, r to retain ")
174 (both) 203 (both)
175 (t (setq both (substitute-command-keys "Press \\[scroll-up] to scroll, \\[scroll-down] to scroll back, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))))))) 204 (t (setq both (substitute-command-keys "Press \\[scroll-up] to scroll, \\[scroll-down] to scroll back, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain ")))))))))
176 t)))) 205 t))))
@@ -194,15 +223,20 @@ BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit."
194\(The *Help* buffer will not be selected, but \\[switch-to-buffer-other-window] RET 223\(The *Help* buffer will not be selected, but \\[switch-to-buffer-other-window] RET
195will select it.)" 224will select it.)"
196 (interactive) 225 (interactive)
197 (throw 'exit '(retain))) 226 ;; Make sure that we don't throw twice, even if two events cause
227 ;; calling this function:
228 (if mouse-leave-buffer-hook
229 (progn
230 (setq mouse-leave-buffer-hook nil)
231 (throw 'exit '(retain)))))
198 232
199 233
200(defun electric-help-undefined () 234(defun electric-help-undefined ()
201 (interactive) 235 (interactive)
202 (error "%s is undefined -- Press %s to exit" 236 (error "%s is undefined -- Press %s to exit"
203 (mapconcat 'single-key-description (this-command-keys) " ") 237 (mapconcat 'single-key-description (this-command-keys) " ")
204 (if (eq (key-binding "Q") 'electric-help-exit) 238 (if (eq (key-binding "q") 'electric-help-exit)
205 "Q" 239 "q"
206 (substitute-command-keys "\\[electric-help-exit]")))) 240 (substitute-command-keys "\\[electric-help-exit]"))))
207 241
208 242
@@ -271,6 +305,22 @@ will select it.)"
271 (with-electric-help 'ignore name t)))) 305 (with-electric-help 'ignore name t))))
272 306
273 307
308
309;; This is to be bound to M-x in ehelp mode. Retains ehelp buffer and then
310;; continues with execute-extended-command.
311(defun electric-help-execute-extended (prefixarg)
312 (interactive "p")
313 (setq to-be-executed '(execute-extended-command nil))
314 (electric-help-retain))
315
316;; This is to be buond to C-x in ehelp mode. Retains ehelp buffer and then
317;; continues with ctrl-x prefix.
318(defun electric-help-ctrl-x-prefix (prefixarg)
319 (interactive "p")
320 (setq to-be-executed '(progn (message nil) (setq unread-command-char ?\C-x)))
321 (electric-help-retain))
322
323
274(defun electric-describe-key () 324(defun electric-describe-key ()
275 (interactive) 325 (interactive)
276 (electric-helpify 'describe-key)) 326 (electric-helpify 'describe-key))
@@ -321,6 +371,7 @@ will select it.)"
321(if ehelp-map 371(if ehelp-map
322 nil 372 nil
323 (let ((map (copy-keymap help-map))) 373 (let ((map (copy-keymap help-map)))
374 (substitute-key-definition 'apropos 'electric-apropos map)
324 (substitute-key-definition 'command-apropos 'electric-command-apropos map) 375 (substitute-key-definition 'command-apropos 'electric-command-apropos map)
325 (substitute-key-definition 'describe-key 'electric-describe-key map) 376 (substitute-key-definition 'describe-key 'electric-describe-key map)
326 (substitute-key-definition 'describe-mode 'electric-describe-mode map) 377 (substitute-key-definition 'describe-mode 'electric-describe-mode map)