Mercurial > emacs
comparison lisp/help.el @ 23747:fb3963445995
Add resizing of temporary buffers.
(temp-buffer-window-resize-mode): New command and variable.
(temp-buffer-window-max-height): New variable.
(resize-temp-buffer-window): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 22 Nov 1998 17:26:16 +0000 |
parents | 8c57752f8e9c |
children | ea095fa15fb9 |
comparison
equal
deleted
inserted
replaced
23746:06f68bc4b777 | 23747:fb3963445995 |
---|---|
1142 (message "No cross references in the buffer.") | 1142 (message "No cross references in the buffer.") |
1143 (setq pos t)) | 1143 (setq pos t)) |
1144 (t ; be circular | 1144 (t ; be circular |
1145 (goto-char (point-max))))))) | 1145 (goto-char (point-max))))))) |
1146 | 1146 |
1147 | |
1148 ;;; Automatic resizing of temporary buffers. | |
1149 | |
1150 (defcustom temp-buffer-window-resize-mode nil | |
1151 "Non-nil means resize windows displaying temporary buffers. | |
1152 The window will be resized in order to fit its contents, subject to the | |
1153 constraints that it will not be higher than `temp-buffer-window-max-height' | |
1154 nor smaller than `window-min-height'. | |
1155 This applies to `help', `apropos' and `completion' buffers and possibly others. | |
1156 | |
1157 This variable must be modified via \\[customize] in order to have an effect." | |
1158 :get (lambda (symbol) | |
1159 (and (memq 'resize-temp-buffer-window temp-buffer-show-hook) t)) | |
1160 :set (lambda (symbol value) | |
1161 (temp-buffer-window-resize-mode (if value 1 -1))) | |
1162 :initialize 'custom-initialize-default | |
1163 :type 'boolean | |
1164 :group 'help | |
1165 :version "20.4") | |
1166 | |
1167 (defcustom temp-buffer-window-max-height (lambda (buffer) (/ (- (frame-height) 2) 2)) | |
1168 "*Maximum height of a window displaying a temporary buffer. | |
1169 This is the maximum height (in text lines) which `resize-temp-buffer-window' | |
1170 will give to a window displaying a temporary buffer. | |
1171 It can also be a function which will be called with the object corresponding | |
1172 to the buffer to be displayed as argument and should return an integer | |
1173 positive number." | |
1174 :type '(choice integer function) | |
1175 :group 'help | |
1176 :version "20.4") | |
1177 | |
1178 (defun temp-buffer-window-resize-mode (arg) | |
1179 "Toggle the variable `temp-buffer-window-resize-mode'. | |
1180 With prefix argument ARG, turn the resizing of windows displaying temporary | |
1181 buffers on if ARG is positive or off otherwise. | |
1182 See the documentation of the variable `temp-buffer-window-resize-mode' for | |
1183 more information." | |
1184 (interactive "P") | |
1185 (let ((turn-it-on | |
1186 (if (null arg) | |
1187 (not (memq 'resize-temp-buffer-window temp-buffer-show-hook)) | |
1188 (> (prefix-numeric-value arg) 0)))) | |
1189 (if turn-it-on | |
1190 (progn | |
1191 ;; `help-mode-maybe' may add a `back' button and thus increase the | |
1192 ;; text size, so `resize-temp-buffer-window' must be run *after* it. | |
1193 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append) | |
1194 (setq temp-buffer-window-resize-mode t)) | |
1195 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window) | |
1196 (setq temp-buffer-window-resize-mode nil)))) | |
1197 | |
1198 (defun resize-temp-buffer-window () | |
1199 "Resize the current window to fit its contents. | |
1200 Will not make it higher than `temp-buffer-window-max-height' nor smaller than | |
1201 `window-min-height'. Do nothing if it is the only window on its frame, if it | |
1202 is not as wide as the frame or if some of the window's contents are scrolled | |
1203 out of view." | |
1204 (unless (or (one-window-p 'nomini) | |
1205 (not (pos-visible-in-window-p (point-min))) | |
1206 (/= (frame-width) (window-width))) | |
1207 (let* ((max-height (if (functionp temp-buffer-window-max-height) | |
1208 (funcall temp-buffer-window-max-height (current-buffer)) | |
1209 temp-buffer-window-max-height)) | |
1210 (win-height (1- (window-height))) | |
1211 (min-height (1- window-min-height)) | |
1212 (text-height (window-buffer-height(selected-window))) | |
1213 (new-height (max (min text-height max-height) min-height))) | |
1214 (enlarge-window (- new-height win-height))))) | |
1215 | |
1147 ;;; help.el ends here | 1216 ;;; help.el ends here |