diff options
| author | Martin Rudalics | 2012-09-05 11:22:20 +0200 |
|---|---|---|
| committer | Martin Rudalics | 2012-09-05 11:22:20 +0200 |
| commit | ef6544601a7305acb1690e3a790bb00f5366c674 (patch) | |
| tree | 1a88f3dc18131a2eacde4b76062af06a4c578e5a | |
| parent | f75d7a913dd0fae7a739d12f704fca024c065c3e (diff) | |
| download | emacs-ef6544601a7305acb1690e3a790bb00f5366c674.tar.gz emacs-ef6544601a7305acb1690e3a790bb00f5366c674.zip | |
Provide support for fitting frames to buffers.
* help.el (temp-buffer-max-height): New default value.
(temp-buffer-resize-frames): New option.
(resize-temp-buffer-window): Optionally resize frame.
* window.el (fit-frame-to-buffer-bottom-margin): New option.
(fit-frame-to-buffer): New function.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/help.el | 35 | ||||
| -rw-r--r-- | lisp/window.el | 82 |
4 files changed, 126 insertions, 5 deletions
| @@ -645,6 +645,11 @@ now accept a third argument to avoid choosing the selected window. | |||
| 645 | 645 | ||
| 646 | *** New macro with-temp-buffer-window. | 646 | *** New macro with-temp-buffer-window. |
| 647 | 647 | ||
| 648 | *** New option temp-buffer-resize-frames. | ||
| 649 | |||
| 650 | *** New function fit-frame-to-buffer and new option | ||
| 651 | fit-frame-to-buffer-bottom-margin. | ||
| 652 | |||
| 648 | *** New display action function display-buffer-below-selected. | 653 | *** New display action function display-buffer-below-selected. |
| 649 | 654 | ||
| 650 | *** New display action alist `inhibit-switch-frame', if non-nil, tells | 655 | *** New display action alist `inhibit-switch-frame', if non-nil, tells |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 817175ebfeb..23cb32e1464 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2012-09-05 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * help.el (temp-buffer-max-height): New default value. | ||
| 4 | (temp-buffer-resize-frames): New option. | ||
| 5 | (resize-temp-buffer-window): Optionally resize frame. | ||
| 6 | |||
| 7 | * window.el (fit-frame-to-buffer-bottom-margin): New option. | ||
| 8 | (fit-frame-to-buffer): New function. | ||
| 9 | |||
| 1 | 2012-09-05 Glenn Morris <rgm@gnu.org> | 10 | 2012-09-05 Glenn Morris <rgm@gnu.org> |
| 2 | 11 | ||
| 3 | * emulation/cua-rect.el (cua--init-rectangles): | 12 | * emulation/cua-rect.el (cua--init-rectangles): |
diff --git a/lisp/help.el b/lisp/help.el index 9740f8996c1..cacbf185963 100644 --- a/lisp/help.el +++ b/lisp/help.el | |||
| @@ -962,7 +962,11 @@ is currently activated with completion." | |||
| 962 | result)) | 962 | result)) |
| 963 | 963 | ||
| 964 | ;;; Automatic resizing of temporary buffers. | 964 | ;;; Automatic resizing of temporary buffers. |
| 965 | (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2)) | 965 | (defcustom temp-buffer-max-height |
| 966 | (lambda (buffer) | ||
| 967 | (if (eq (selected-window) (frame-root-window)) | ||
| 968 | (/ (x-display-pixel-height) (frame-char-height) 2) | ||
| 969 | (/ (- (frame-height) 2) 2))) | ||
| 966 | "Maximum height of a window displaying a temporary buffer. | 970 | "Maximum height of a window displaying a temporary buffer. |
| 967 | This is effective only when Temp Buffer Resize mode is enabled. | 971 | This is effective only when Temp Buffer Resize mode is enabled. |
| 968 | The value is the maximum height (in lines) which | 972 | The value is the maximum height (in lines) which |
| @@ -973,7 +977,16 @@ buffer, and should return a positive integer. At the time the | |||
| 973 | function is called, the window to be resized is selected." | 977 | function is called, the window to be resized is selected." |
| 974 | :type '(choice integer function) | 978 | :type '(choice integer function) |
| 975 | :group 'help | 979 | :group 'help |
| 976 | :version "20.4") | 980 | :version "24.2") |
| 981 | |||
| 982 | (defcustom temp-buffer-resize-frames nil | ||
| 983 | "Non-nil means `temp-buffer-resize-mode' can resize frames. | ||
| 984 | A frame can be resized if and only if its root window is a live | ||
| 985 | window. The height of the root window is subject to the values of | ||
| 986 | `temp-buffer-max-height' and `window-min-height'." | ||
| 987 | :type 'boolean | ||
| 988 | :version "24.2" | ||
| 989 | :group 'help) | ||
| 977 | 990 | ||
| 978 | (define-minor-mode temp-buffer-resize-mode | 991 | (define-minor-mode temp-buffer-resize-mode |
| 979 | "Toggle auto-resizing temporary buffer windows (Temp Buffer Resize Mode). | 992 | "Toggle auto-resizing temporary buffer windows (Temp Buffer Resize Mode). |
| @@ -1008,9 +1021,21 @@ view." | |||
| 1008 | (with-selected-window window | 1021 | (with-selected-window window |
| 1009 | (funcall temp-buffer-max-height (window-buffer))) | 1022 | (funcall temp-buffer-max-height (window-buffer))) |
| 1010 | temp-buffer-max-height))) | 1023 | temp-buffer-max-height))) |
| 1011 | (when (and (pos-visible-in-window-p (point-min) window) | 1024 | (cond |
| 1012 | (window-combined-p window)) | 1025 | ((and (pos-visible-in-window-p (point-min) window) |
| 1013 | (fit-window-to-buffer window height)))) | 1026 | (window-combined-p window)) |
| 1027 | (fit-window-to-buffer window height)) | ||
| 1028 | ((and temp-buffer-resize-frames | ||
| 1029 | (eq window (frame-root-window window)) | ||
| 1030 | (memq (car (window-parameter window 'quit-restore)) | ||
| 1031 | ;; If 'same is too strong, we might additionally check | ||
| 1032 | ;; whether the second element is 'frame. | ||
| 1033 | '(same frame))) | ||
| 1034 | (let ((frame (window-frame window))) | ||
| 1035 | (fit-frame-to-buffer | ||
| 1036 | frame (+ (frame-height frame) | ||
| 1037 | (- (window-total-size window)) | ||
| 1038 | height))))))) | ||
| 1014 | 1039 | ||
| 1015 | ;;; Help windows. | 1040 | ;;; Help windows. |
| 1016 | (defcustom help-window-select 'other | 1041 | (defcustom help-window-select 'other |
diff --git a/lisp/window.el b/lisp/window.el index f73c85e991b..66b86f45e77 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -5918,6 +5918,88 @@ WINDOW was scrolled." | |||
| 5918 | (error (setq delta nil))) | 5918 | (error (setq delta nil))) |
| 5919 | delta)))) | 5919 | delta)))) |
| 5920 | 5920 | ||
| 5921 | (defcustom fit-frame-to-buffer-bottom-margin 4 | ||
| 5922 | "Bottom margin for `fit-frame-to-buffer'. | ||
| 5923 | This is the number of lines `fit-frame-to-buffer' leaves free at the | ||
| 5924 | bottom of the display in order to not obscure the system task bar." | ||
| 5925 | :type 'integer | ||
| 5926 | :version "24.2" | ||
| 5927 | :group 'windows) | ||
| 5928 | |||
| 5929 | (defun fit-frame-to-buffer (&optional frame max-height min-height) | ||
| 5930 | "Adjust height of FRAME to display its buffer's contents exactly. | ||
| 5931 | FRAME can be any live frame and defaults to the selected one. | ||
| 5932 | |||
| 5933 | Optional argument MAX-HEIGHT specifies the maximum height of | ||
| 5934 | FRAME and defaults to the height of the display below the current | ||
| 5935 | top line of FRAME minus FIT-FRAME-TO-BUFFER-BOTTOM-MARGIN. | ||
| 5936 | Optional argument MIN-HEIGHT specifies the minimum height of | ||
| 5937 | FRAME." | ||
| 5938 | (interactive) | ||
| 5939 | (setq frame (window-normalize-frame frame)) | ||
| 5940 | (let* ((root (frame-root-window frame)) | ||
| 5941 | (frame-min-height | ||
| 5942 | (+ (- (frame-height frame) (window-total-size root)) | ||
| 5943 | window-min-height)) | ||
| 5944 | (frame-top (frame-parameter frame 'top)) | ||
| 5945 | (top (if (consp frame-top) | ||
| 5946 | (funcall (car frame-top) (cadr frame-top)) | ||
| 5947 | frame-top)) | ||
| 5948 | (frame-max-height | ||
| 5949 | (- (/ (- (x-display-pixel-height frame) top) | ||
| 5950 | (frame-char-height frame)) | ||
| 5951 | fit-frame-to-buffer-bottom-margin)) | ||
| 5952 | (compensate 0) | ||
| 5953 | delta) | ||
| 5954 | (when (and (window-live-p root) (not (window-size-fixed-p root))) | ||
| 5955 | (with-selected-window root | ||
| 5956 | (cond | ||
| 5957 | ((not max-height) | ||
| 5958 | (setq max-height frame-max-height)) | ||
| 5959 | ((numberp max-height) | ||
| 5960 | (setq max-height (min max-height frame-max-height))) | ||
| 5961 | (t | ||
| 5962 | (error "%s is an invalid maximum height" max-height))) | ||
| 5963 | (cond | ||
| 5964 | ((not min-height) | ||
| 5965 | (setq min-height frame-min-height)) | ||
| 5966 | ((numberp min-height) | ||
| 5967 | (setq min-height (min min-height frame-min-height))) | ||
| 5968 | (t | ||
| 5969 | (error "%s is an invalid minimum height" min-height))) | ||
| 5970 | ;; When tool-bar-mode is enabled and we have just created a new | ||
| 5971 | ;; frame, reserve lines for toolbar resizing. This is needed | ||
| 5972 | ;; because for reasons unknown to me Emacs (1) reserves one line | ||
| 5973 | ;; for the toolbar when making the initial frame and toolbars | ||
| 5974 | ;; are enabled, and (2) later adds the remaining lines needed. | ||
| 5975 | ;; Our code runs IN BETWEEN (1) and (2). YMMV when you're on a | ||
| 5976 | ;; system that behaves differently. | ||
| 5977 | (let ((quit-restore (window-parameter root 'quit-restore)) | ||
| 5978 | (lines (tool-bar-lines-needed frame))) | ||
| 5979 | (when (and quit-restore (eq (car quit-restore) 'frame) | ||
| 5980 | (not (zerop lines))) | ||
| 5981 | (setq compensate (1- lines)))) | ||
| 5982 | (message "%s" compensate) | ||
| 5983 | (setq delta | ||
| 5984 | ;; Always count a final newline - we don't do any | ||
| 5985 | ;; post-processing, so let's play safe. | ||
| 5986 | (+ (count-screen-lines nil nil t) | ||
| 5987 | (- (window-body-size)) | ||
| 5988 | compensate))) | ||
| 5989 | ;; Move away from final newline. | ||
| 5990 | (when (and (eobp) (bolp) (not (bobp))) | ||
| 5991 | (set-window-point root (line-beginning-position 0))) | ||
| 5992 | (set-window-start root (point-min)) | ||
| 5993 | (set-window-vscroll root 0) | ||
| 5994 | (condition-case nil | ||
| 5995 | (set-frame-height | ||
| 5996 | frame | ||
| 5997 | (min (max (+ (frame-height frame) delta) | ||
| 5998 | min-height) | ||
| 5999 | max-height)) | ||
| 6000 | (error (setq delta nil)))) | ||
| 6001 | delta)) | ||
| 6002 | |||
| 5921 | (defun window-safely-shrinkable-p (&optional window) | 6003 | (defun window-safely-shrinkable-p (&optional window) |
| 5922 | "Return t if WINDOW can be shrunk without shrinking other windows. | 6004 | "Return t if WINDOW can be shrunk without shrinking other windows. |
| 5923 | WINDOW defaults to the selected window." | 6005 | WINDOW defaults to the selected window." |