comparison lisp/ehelp.el @ 31792:bad7093b5361

(electric-help): New defgroup. (electric-help-shrink-window): New user-option. (with-electric-help): Use it.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 20 Sep 2000 20:39:20 +0000
parents 30b7f4899d66
children 5432010ffe02
comparison
equal deleted inserted replaced
31791:0ac4efb76ef6 31792:bad7093b5361
41 (require 'electric) 41 (require 'electric)
42 (defvar electric-help-map () 42 (defvar electric-help-map ()
43 "Keymap defining commands available in `electric-help-mode'.") 43 "Keymap defining commands available in `electric-help-mode'.")
44 44
45 (defvar electric-help-form-to-execute nil) 45 (defvar electric-help-form-to-execute nil)
46
47 (defgroup electric-help ()
48 "Electric help facility."
49 :version "21.1"
50 :group 'help)
51
52 (defcustom electric-help-shrink-window t
53 "If set, adjust help window sizes to buffer sizes when displaying help."
54 :type 'boolean
55 :group 'electric-help)
46 56
47 (put 'electric-help-undefined 'suppress-keymap t) 57 (put 'electric-help-undefined 'suppress-keymap t)
48 (if electric-help-map 58 (if electric-help-map
49 () 59 ()
50 (let ((map (make-keymap))) 60 (let ((map (make-keymap)))
111 in which BUFFER is displayed and allows the user to scroll through that buffer 121 in which BUFFER is displayed and allows the user to scroll through that buffer
112 in electric-help-mode. The window's height will be at least MINHEIGHT if 122 in electric-help-mode. The window's height will be at least MINHEIGHT if
113 this value is non-nil. 123 this value is non-nil.
114 124
115 If THUNK returns nil, we display BUFFER starting at the top, and 125 If THUNK returns nil, we display BUFFER starting at the top, and
116 shrink the window to fit. If THUNK returns non-nil, we don't do those 126 shrink the window to fit if `electric-help-shrink-window' is non-nil.
117 things. 127 If THUNK returns non-nil, we don't do those things.
118 128
119 When the user exits (with `electric-help-exit', or otherwise) the help 129 When the user exits (with `electric-help-exit', or otherwise) the help
120 buffer's window disappears (i.e., we use `save-window-excursion') 130 buffer's window disappears (i.e., we use `save-window-excursion')
121 BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit." 131 BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit."
122 (setq buffer (get-buffer-create (or buffer "*Help*"))) 132 (setq buffer (get-buffer-create (or buffer "*Help*")))
124 (config (current-window-configuration)) 134 (config (current-window-configuration))
125 (bury nil) 135 (bury nil)
126 (electric-help-form-to-execute nil)) 136 (electric-help-form-to-execute nil))
127 (unwind-protect 137 (unwind-protect
128 (save-excursion 138 (save-excursion
129 (if one (goto-char (window-start (selected-window)))) 139 (when one
140 (goto-char (window-start (selected-window))))
130 (let ((pop-up-windows t)) 141 (let ((pop-up-windows t))
131 (pop-to-buffer buffer)) 142 (pop-to-buffer buffer))
132 (save-excursion 143 (save-excursion
133 (set-buffer buffer) 144 (set-buffer buffer)
134 (if (and minheight (< (window-height) minheight)) 145 (when (and minheight (< (window-height) minheight))
135 (enlarge-window (- minheight (window-height)))) 146 (enlarge-window (- minheight (window-height))))
136 (electric-help-mode) 147 (electric-help-mode)
137 (setq buffer-read-only nil) 148 (setq buffer-read-only nil)
138 (or noerase 149 (unless noerase
139 (erase-buffer))) 150 (erase-buffer)))
140 (let ((standard-output buffer)) 151 (let ((standard-output buffer))
141 (if (not (funcall thunk)) 152 (unless (funcall thunk)
142 (progn 153 (set-buffer buffer)
143 (set-buffer buffer) 154 (set-buffer-modified-p nil)
144 (set-buffer-modified-p nil) 155 (goto-char (point-min))
145 (goto-char (point-min)) 156 (when (and one electric-help-shrink-window)
146 (if one (shrink-window-if-larger-than-buffer (selected-window)))))) 157 (shrink-window-if-larger-than-buffer))))
147 (set-buffer buffer) 158 (set-buffer buffer)
148 (run-hooks 'electric-help-mode-hook) 159 (run-hooks 'electric-help-mode-hook)
149 (setq buffer-read-only t) 160 (setq buffer-read-only t)
150 (if (eq (car-safe (electric-help-command-loop)) 161 (if (eq (car-safe (electric-help-command-loop)) 'retain)
151 'retain)
152 (setq config (current-window-configuration)) 162 (setq config (current-window-configuration))
153 (setq bury t)) 163 (setq bury t))
154 ;; Remove the hook. 164 ;; Remove the hook.
155 (if (memq 'electric-help-retain mouse-leave-buffer-hook) 165 (when (memq 'electric-help-retain mouse-leave-buffer-hook)
156 (remove-hook 'mouse-leave-buffer-hook 'electric-help-retain))) 166 (remove-hook 'mouse-leave-buffer-hook 'electric-help-retain)))
157 (message "") 167 (message "")
158 (set-buffer buffer) 168 (set-buffer buffer)
159 (setq buffer-read-only nil) 169 (setq buffer-read-only nil)
170
171 ;; We should really get a usable *Help* buffer when retaining
172 ;; the electric one with `r'. The problem is that a simple
173 ;; call to help-mode won't cut it; at least RET is vound wrong
174 ;; afterwards. It's also not clear that `help-mode' is always
175 ;; the right thing, maybe we should add an optional parameter.
160 (condition-case () 176 (condition-case ()
161 (funcall (or default-major-mode 'fundamental-mode)) 177 (funcall (or default-major-mode 'fundamental-mode))
162 (error nil)) 178 (error nil))
179
163 (set-window-configuration config) 180 (set-window-configuration config)
164 (if bury 181 (when bury
165 (progn 182 ;;>> Perhaps this shouldn't be done.
166 ;;>> Perhaps this shouldn't be done. 183 ;; so that when we say "Press space to bury" we mean it
167 ;; so that when we say "Press space to bury" we mean it 184 (replace-buffer-in-windows buffer)
168 (replace-buffer-in-windows buffer) 185 ;; must do this outside of save-window-excursion
169 ;; must do this outside of save-window-excursion 186 (bury-buffer buffer))
170 (bury-buffer buffer)))
171 (eval electric-help-form-to-execute)))) 187 (eval electric-help-form-to-execute))))
172 188
173 (defun electric-help-command-loop () 189 (defun electric-help-command-loop ()
174 (catch 'exit 190 (catch 'exit
175 (if (pos-visible-in-window-p (point-max)) 191 (if (pos-visible-in-window-p (point-max))