comparison lisp/prim/help.el @ 114:8619ce7e4c50 r20-1b9

Import from CVS: tag r20-1b9
author cvs
date Mon, 13 Aug 2007 09:21:54 +0200
parents fe104dbd9147
children 9f59509498e1
comparison
equal deleted inserted replaced
113:2ec2fe4a4c89 114:8619ce7e4c50
179 (define-key help-mode-map "q" 'help-mode-quit) 179 (define-key help-mode-map "q" 'help-mode-quit)
180 180
181 (defun help-mode-quit () 181 (defun help-mode-quit ()
182 "Exits from help mode, possibly restoring the previous window configuration." 182 "Exits from help mode, possibly restoring the previous window configuration."
183 (interactive) 183 (interactive)
184 (cond ((local-variable-p 'help-window-config (current-buffer)) 184 (cond ((frame-property (selected-frame) 'help-window-config)
185 (let ((config help-window-config)) 185 (set-window-configuration
186 (kill-local-variable 'help-window-config) 186 (frame-property (selected-frame) 'help-window-config))
187 (bury-buffer) 187 (set-frame-property (selected-frame) 'help-window-config nil))
188 (set-window-configuration config)))
189 ((one-window-p) 188 ((one-window-p)
190 (bury-buffer)) 189 (bury-buffer))
191 (t 190 (t
192 (delete-window)))) 191 (delete-window))))
193 192
343 (defvar help-selects-help-window t 342 (defvar help-selects-help-window t
344 "*If nil, use the \"old Emacs\" behavior for Help buffers. 343 "*If nil, use the \"old Emacs\" behavior for Help buffers.
345 This just displays the buffer in another window, rather than selecting 344 This just displays the buffer in another window, rather than selecting
346 the window.") 345 the window.")
347 346
348 (defvar help-window-config nil) 347 (defvar help-window-max-height .5
349 348 "*Proportion of frame to use for help windows.")
350 ;; Use this function for displaying help when C-h something is pressed 349 ;; Use this function for displaying help when C-h something is pressed
351 ;; or in similar situations. Do *not* use it when you are displaying 350 ;; or in similar situations. Do *not* use it when you are displaying
352 ;; a help message and then prompting for input in the minibuffer -- 351 ;; a help message and then prompting for input in the minibuffer --
353 ;; this macro usually selects the help buffer, which is not what you 352 ;; this macro usually selects the help buffer, which is not what you
354 ;; want in those situations. 353 ;; want in those situations.
355 354
356 ;;; ### Should really be a macro (as suggested above) to eliminate the 355 ;;; ### Should really be a macro (as suggested above) to eliminate the
357 ;;; requirement of caller to code a lambda form in THUNK -- mrb 356 ;;; requirement of caller to code a lambda form in THUNK -- mrb
358 (defun with-displaying-help-buffer (thunk) 357 (defun with-displaying-help-buffer (thunk)
359 (let ((winconfig (current-window-configuration)) 358 (let ((winconfig (current-window-configuration))
360 (was-one-window (one-window-p))) 359 (was-one-window (one-window-p))
360 (help-not-visible
361 (not (and (windows-of-buffer "*Help*") ;shortcut
362 (member (selected-frame)
363 (mapcar 'window-frame
364 (windows-of-buffer "*Help*")))))))
361 (prog1 (with-output-to-temp-buffer "*Help*" 365 (prog1 (with-output-to-temp-buffer "*Help*"
362 (prog1 (funcall thunk) 366 (prog1 (funcall thunk)
363 (save-excursion 367 (save-excursion
364 (set-buffer standard-output) 368 (set-buffer standard-output)
365 (help-mode)))) 369 (help-mode))))
366 (let ((helpwin (get-buffer-window "*Help*"))) 370 (let ((helpwin (get-buffer-window "*Help*")))
367 (if helpwin 371 (if helpwin
368 (progn 372 (progn
369 (save-excursion 373 (save-excursion
370 (set-buffer (window-buffer helpwin)) 374 (set-buffer (window-buffer helpwin))
371 (set (make-local-variable 'help-window-config) winconfig)) 375 ;;If the *Help* buffer is already displayed on this
376 ;; frame, don't override the previous configuration
377 (if help-not-visible
378 (set-frame-property (selected-frame)
379 'help-window-config winconfig)))
372 (if help-selects-help-window 380 (if help-selects-help-window
373 (select-window helpwin)) 381 (select-window helpwin))
374 (cond ((eq helpwin (selected-window)) 382 (cond ((eq helpwin (selected-window))
375 (message 383 (message
376 (substitute-command-keys "Type \\[help-mode-quit] to remove help window, \\[scroll-up] to scroll the help."))) 384 (substitute-command-keys "Type \\[help-mode-quit] to remove help window, \\[scroll-up] to scroll the help.")))
379 (substitute-command-keys "Type \\[delete-other-windows] to remove help window, \\[scroll-other-window] to scroll the help."))) 387 (substitute-command-keys "Type \\[delete-other-windows] to remove help window, \\[scroll-other-window] to scroll the help.")))
380 (t 388 (t
381 (message 389 (message
382 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the help.")))) 390 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the help."))))
383 (when temp-buffer-shrink-to-fit 391 (when temp-buffer-shrink-to-fit
392 (let* ((help-window-size (round (* help-window-max-height
393 (frame-height (window-frame helpwin)))))
394 (size (window-displayed-height helpwin)))
395 (if (< size help-window-size)
396 (enlarge-window (- help-window-size size) nil helpwin)))
384 (shrink-window-if-larger-than-buffer helpwin)))))))) 397 (shrink-window-if-larger-than-buffer helpwin))))))))
385 398
386 (defun describe-key (key) 399 (defun describe-key (key)
387 "Display documentation of the function invoked by KEY. 400 "Display documentation of the function invoked by KEY.
388 KEY is a string, or vector of events. 401 KEY is a string, or vector of events.