From 3dab6c155903f964d773605f969e54593917a8ad Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Fri, 14 Jan 2011 11:29:40 +0100 Subject: [PATCH] Sanitize buffer display handling in calendar.el, a first step. * window.el (window-safely-shrinkable-p): Remove. * calendar/calendar.el (calendar-generate-window): Only fit a vertically combined window to its buffer. (calendar-basic-setup): Call pop-to-buffer, preferably making a new window at the bottom of the frame. Remove the split-height-threshold binding around call of calendar-list-holidays, this must be handled separately. --- lisp/ChangeLog | 11 ++++++++ lisp/calendar/calendar.el | 56 +++++++++++++++++---------------------- lisp/window.el | 8 ------ 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0bf2d2cdd21..9a14b52de3e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2011-01-14 Martin Rudalics + + * window.el (window-safely-shrinkable-p): Remove. + + * calendar/calendar.el (calendar-generate-window): Only fit a + vertically combined window to its buffer. + (calendar-basic-setup): Call pop-to-buffer, preferably making a + new window at the bottom of the frame. Remove the + split-height-threshold binding around call of + calendar-list-holidays, this must be handled separately. + 2011-01-13 Martin Rudalics * mail/sendmail.el (sendmail-user-agent-compose): Remove let diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index bf520306bbb..deaf06bcb39 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el @@ -172,6 +172,9 @@ This only affects frames wider than the default value of (integer)) :version "23.2" :group 'calendar) +(make-obsolete-variable + 'calendar-split-width-threshold + "customize `display-buffer-alist' instead." "24.1") (defcustom calendar-week-start-day 0 "The day of the week on which a week in the calendar begins. @@ -1295,12 +1298,7 @@ display the generated calendar." (let ((buff (current-buffer))) (set-buffer (get-buffer-create calendar-buffer)) (calendar-mode) - (let* ((pop-up-windows t) - ;; Not really needed now, but means we use exactly the same - ;; behavior as before in the non-wide case (see below). - (split-height-threshold 1000) - (split-width-threshold calendar-split-width-threshold) - (date (if arg (calendar-read-date t) + (let* ((date (if arg (calendar-read-date t) (calendar-current-date))) (month (calendar-extract-month date)) (year (calendar-extract-year date))) @@ -1333,27 +1331,26 @@ display the generated calendar." ;; ;; Is this a wide frame? If so, split it horizontally. - ;; FIXME: Adapt to new splitting code. - ;; (if (window-sensibly-splittable-p t) (split-window-horizontally)) - (pop-to-buffer calendar-buffer) - ;; Has the window already been split vertically? - (when (and (not (window-dedicated-p)) - (window-full-height-p)) - (let ((win (split-window-vertically))) - ;; In the upper window, show whatever was visible before. - ;; This looks better than using other-buffer. - (switch-to-buffer buff) - ;; Switch to the lower window with the calendar buffer. - (select-window win)))) + ;; Try to make the new window at the bottom of the frame. If + ;; there's real urgent need, we could also try to split the last + ;; full width window on the frame (provided we write a function + ;; to do that) and split it into two side-by-side windows with + ;; the calendar in the right window. Hopefully, users will + ;; eventually start using the rightmost bottom side window for + ;; the calendar. Using (pop-up-window (bottom . 1000)), for + ;; example, in `display-buffer-alist', with (override . t), + ;; should do the job. + (pop-to-buffer calendar-buffer '((pop-up-window (root . below))))) (calendar-generate-window month year) (if (and calendar-view-diary-initially-flag (calendar-date-is-visible-p date)) (diary-view-entries)))) (if calendar-view-holidays-initially-flag (let* ((diary-buffer (get-file-buffer diary-file)) - (diary-window (if diary-buffer (get-buffer-window diary-buffer))) - (split-height-threshold (if diary-window 2 1000))) - ;; FIXME display buffer? + (diary-window (if diary-buffer (get-buffer-window diary-buffer)))) + ;; This used to bind `split-height-threshold'. Since that + ;; variable is no longer supported we have to find a different + ;; solution if needed. (calendar-list-holidays))) (run-hooks 'calendar-initial-window-hook)) @@ -1378,17 +1375,12 @@ Optional integers MON and YR are used instead of today's date." ;; Don't do any window-related stuff if we weren't called from a ;; window displaying the calendar. (when in-calendar-window - ;; The second test used to be window-full-width-p. - ;; Not sure what it was/is for, except perhaps some way of saying - ;; "try not to mess with existing configurations". - ;; If did the wrong thing on wide frames, where we have done a - ;; horizontal split in calendar-basic-setup. - (if (or (one-window-p t) (not (window-safely-shrinkable-p))) - ;; Don't mess with the window size, but ensure that the first - ;; line is fully visible. - (set-window-vscroll nil 0) - ;; Adjust the window to exactly fit the displayed calendar. - (fit-window-to-buffer nil nil calendar-minimum-window-height)) + (if (window-iso-combined-p) + ;; Adjust the window to exactly fit the displayed calendar. + (fit-window-to-buffer nil nil calendar-minimum-window-height) + ;; For a full height window or a window that is horizontally + ;; combined don't fit height to that of its buffer. + (set-window-vscroll nil 0)) (sit-for 0)) (and (bound-and-true-p font-lock-mode) (font-lock-fontify-buffer)) diff --git a/lisp/window.el b/lisp/window.el index 534c2b0f83f..894b38da65a 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5983,14 +5983,6 @@ WINDOW was scrolled." (error (setq delta nil))) delta)))) -(defun window-safely-shrinkable-p (&optional window) - "Return t if WINDOW can be shrunk without shrinking other windows. -WINDOW defaults to the selected window." - (with-selected-window (or window (selected-window)) - (let ((edges (window-edges))) - (or (= (nth 2 edges) (nth 2 (window-edges (previous-window)))) - (= (nth 0 edges) (nth 0 (window-edges (next-window)))))))) - (defun shrink-window-if-larger-than-buffer (&optional window) "Shrink height of WINDOW if its buffer doesn't need so many lines. More precisely, shrink WINDOW vertically to be as small as -- 2.39.5