-(defun ispell-adjusted-window-height (&optional window)
- "Like `window-height', adjusted to correct for the effect of tall mode-lines.
-The value returned is actually the nominal number of text-lines in the
-window plus 1. On a terminal, this is the same value returned by
-`window-height', but if the window has a mode-line is taller than a normal
-text line, the returned value may be smaller than that from
-`window-height'."
- (cond ((fboundp 'window-text-height)
- (1+ (window-text-height window)))
- ((or (and (fboundp 'display-graphic-p) (display-graphic-p))
- (and (featurep 'xemacs) window-system))
- (1- (window-height window)))
- (t
- (window-height window))))
-
-(defun ispell-overlay-window (height)
- "Create a window covering the top HEIGHT lines of the current window.
-Ensure that the line above point is still visible but otherwise avoid
-scrolling the current window. Leave the new window selected."
- (save-excursion
- (let ((oldot (save-excursion (vertical-motion -1) (point)))
- (top (save-excursion (move-to-window-line height) (point))))
- ;; If line above old point (line starting at oldot) would be
- ;; hidden by new window, scroll it to just below new win
- ;; otherwise set top line of other win so it doesn't scroll.
- (if (< oldot top) (setq top oldot))
- ;; if frame is unsplittable, temporarily disable that...
- (if (cdr (assq 'unsplittable (frame-parameters (selected-frame))))
- (let ((frame (selected-frame)))
- (modify-frame-parameters frame '((unsplittable . nil)))
- (split-window nil height)
- (modify-frame-parameters frame '((unsplittable . t))))
- (split-window nil height))
- (let ((deficit (- height (ispell-adjusted-window-height))))
- (when (> deficit 0)
- ;; Number of lines the window is still too short. We ensure that
- ;; there are at least (1- HEIGHT) lines visible in the window.
- (enlarge-window deficit)
- (goto-char top)
- (vertical-motion deficit)
- (setq top (min (point) oldot))))
- (set-window-start (next-window) top))))
-
+(defun ispell-display-buffer (buffer)
+ "Show BUFFER in new window above selected one.
+Also position fit window to BUFFER and select it."
+ (let* ((unsplittable
+ (cdr (assq 'unsplittable (frame-parameters (selected-frame)))))
+ (window
+ (or (get-buffer-window buffer)
+ (and unsplittable
+ ;; If frame is unsplittable, temporarily disable that...
+ (let ((frame (selected-frame)))
+ (modify-frame-parameters frame '((unsplittable . nil)))
+ (prog1
+ (condition-case nil
+ (split-window
+ nil (- ispell-choices-win-default-height) 'above)
+ (error nil))
+ (modify-frame-parameters frame '((unsplittable . t))))))
+ (and (not unsplittable)
+ (condition-case nil
+ (split-window
+ nil (- ispell-choices-win-default-height) 'above)
+ (error nil)))
+ (display-buffer buffer))))
+ (if (not window)
+ (error "Couldn't make window for *Choices*")
+ (select-window window)
+ (set-window-buffer window buffer)
+ (set-window-point window (point-min))
+ (fit-window-to-buffer window nil nil nil nil t))))