]> code.delx.au - gnu-emacs/blobdiff - lisp/window.el
Merge from emacs-24; up to 2014-07-27T09:41:59Z!ttn@gnu.org
[gnu-emacs] / lisp / window.el
index a7dcd9a6612676cbe46d39fb4a64694e5d6805ac..91a0e159a8442e2f2be936d98a555eb4130fe484 100644 (file)
@@ -108,7 +108,7 @@ Return the buffer."
       ;; Return the buffer.
       buffer)))
 
-(defun temp-buffer-window-show (&optional buffer action)
+(defun temp-buffer-window-show (buffer &optional action)
   "Show temporary buffer BUFFER in a window.
 Return the window showing BUFFER.  Pass ACTION as action argument
 to `display-buffer'."
@@ -743,6 +743,15 @@ number of slots on that side."
      (integer :tag "Number" :value 3 :size 5)))
   :group 'windows)
 
+(defun window--side-window-p (window)
+  "Return non-nil if WINDOW is a side window or the parent of one."
+  (or (window-parameter window 'window-side)
+      (and (window-child window)
+          (or (window-parameter
+               (window-child window) 'window-side)
+              (window-parameter
+               (window-last-child window) 'window-side)))))
+
 (defun window--major-non-side-window (&optional frame)
   "Return the major non-side window of frame FRAME.
 The optional argument FRAME must be a live frame and defaults to
@@ -1155,8 +1164,17 @@ dumping to it."
 WINDOW must be a valid window and defaults to the selected one.
 
 If HORIZONTAL is omitted or nil, return the total height of
-WINDOW, in lines, like `window-total-height'.  Otherwise return
-the total width, in columns, like `window-total-width'.
+WINDOW, in lines.  If WINDOW is live, its total height includes,
+in addition to the height of WINDOW's text, the heights of
+WINDOW's mode and header line and a bottom divider, if any.
+
+If HORIZONTAL is non-nil, return the total width of WINDOW, in
+columns.  If WINDOW is live, its total width includes, in
+addition to the width of WINDOW's text, the widths of WINDOW's
+fringes, margins, scroll bars and its right divider, if any.
+
+If WINDOW is internal, return the respective size of the screen
+areas spanned by its children.
 
 Optional argument ROUND is handled as for `window-total-height'
 and `window-total-width'."
@@ -1297,7 +1315,7 @@ of WINDOW."
                   (* (ceiling pixel-width char-size) char-size))
                 (if (window--size-ignore-p window ignore)
                     0
-                  (window-min-pixel-width)))
+                  (window-min-pixel-width window)))
              (max
               (ceiling pixel-width char-size)
               (if (window--size-ignore-p window ignore)
@@ -1318,7 +1336,7 @@ of WINDOW."
                   (* (ceiling pixel-height char-size) char-size))
                 (if (window--size-ignore-p window ignore)
                     0
-                  (window-min-pixel-height)))
+                  (window-min-pixel-height window)))
              (max (ceiling pixel-height char-size)
                   (if (window--size-ignore-p window ignore)
                       0
@@ -1727,9 +1745,6 @@ doc-string of `window-resizable'."
 (defalias 'window-height 'window-total-height)
 (defalias 'window-width 'window-body-width)
 
-;; Eventually the following two should work pixelwise.
-
-;; See discussion in bug#4543.
 (defun window-full-height-p (&optional window)
   "Return t if WINDOW is as high as its containing frame.
 More precisely, return t if and only if the total height of
@@ -1737,8 +1752,10 @@ WINDOW equals the total height of the root window of WINDOW's
 frame.  WINDOW must be a valid window and defaults to the
 selected one."
   (setq window (window-normalize-window window))
-  (= (window-pixel-height window)
-     (window-pixel-height (frame-root-window window))))
+  (if (window-minibuffer-p window)
+      (eq window (frame-root-window (window-frame window)))
+    (= (window-pixel-height window)
+       (window-pixel-height (frame-root-window window)))))
 
 (defun window-full-width-p (&optional window)
   "Return t if WINDOW is as wide as its containing frame.
@@ -1762,28 +1779,26 @@ optional argument PIXELWISE is passed to the functions."
     (window-body-height window pixelwise)))
 
 (defun window-current-scroll-bars (&optional window)
-  "Return the current scroll bar settings for WINDOW.
+  "Return the current scroll bar types for WINDOW.
 WINDOW must be a live window and defaults to the selected one.
 
 The return value is a cons cell (VERTICAL . HORIZONTAL) where
 VERTICAL specifies the current location of the vertical scroll
-bars (`left', `right', or nil), and HORIZONTAL specifies the
-current location of the horizontal scroll bars (`top', `bottom',
-or nil).
+bar (`left', `right' or nil), and HORIZONTAL specifies the
+current location of the horizontal scroll bar (`bottom' or nil).
 
 Unlike `window-scroll-bars', this function reports the scroll bar
 type actually used, once frame defaults and `scroll-bar-mode' are
 taken into account."
   (setq window (window-normalize-window window t))
-  (let ((vert (nth 2 (window-scroll-bars window)))
-       (hor nil))
-    (when (or (eq vert t) (eq hor t))
-      (let ((fcsb (frame-current-scroll-bars (window-frame window))))
-       (if (eq vert t)
-           (setq vert (car fcsb)))
-       (if (eq hor t)
-           (setq hor (cdr fcsb)))))
-    (cons vert hor)))
+  (let ((vertical (nth 2 (window-scroll-bars window)))
+       (horizontal (nth 5 (window-scroll-bars window)))
+       (inherited (frame-current-scroll-bars (window-frame window))))
+    (when (eq vertical t)
+      (setq vertical (car inherited)))
+    (when (eq horizontal t)
+      (setq horizontal (cdr inherited)))
+    (cons vertical (and horizontal 'bottom))))
 
 (defun walk-windows (fun &optional minibuf all-frames)
   "Cycle through all live windows, calling FUN for each one.
@@ -2286,7 +2301,7 @@ Optional argument HORIZONTAL non-nil means assign new total
 window widths from pixel widths."
   (setq frame (window-normalize-frame frame))
   (let* ((char-size (frame-char-size frame horizontal))
-        (root (frame-root-window))
+        (root (frame-root-window frame))
         (root-size (window-size root horizontal t))
         ;; We have to care about the minibuffer window only if it
         ;; appears together with the root window on this frame.
@@ -3008,12 +3023,12 @@ routines."
 If necessary and possible, make sure that every window on frame
 FRAME has its minimum height.  Optional argument HORIZONTAL
 non-nil means to make sure that every window on frame FRAME has
-its minimum width.  The minimumm height/width of a window is the
+its minimum width.  The minimum height/width of a window is the
 respective value returned by `window-min-size' for that window.
 
 Return t if all windows were resized appropriately.  Return nil
 if at least one window could not be resized as requested, which
-may happen when the FRAME is not large enough to accomodate it."
+may happen when the FRAME is not large enough to accommodate it."
   (let ((value t))
     (walk-window-tree
      (lambda (window)
@@ -4369,12 +4384,7 @@ frame.  The selected window is not changed by this function."
        ;; side window, throw an error unless `window-combination-resize'
        ;; equals 'side.
        ((and (not (eq window-combination-resize 'side))
-            (or (window-parameter window 'window-side)
-                (and (window-child window)
-                     (or (window-parameter
-                          (window-child window) 'window-side)
-                         (window-parameter
-                          (window-last-child window) 'window-side)))))
+            (window--side-window-p window))
        (error "Cannot split side window or parent of side window"))
        ;; If `window-combination-resize' is 'side and window has a side
        ;; window sibling, bind `window-combination-limit' to t.
@@ -5121,7 +5131,7 @@ value can be also stored on disk and read back in a new session."
                (let ((scroll-bars (cdr (assq 'scroll-bars state))))
                  (set-window-scroll-bars
                   window (car scroll-bars) (nth 2 scroll-bars)
-                  (nth 3 scroll-bars)))
+                  (or (nth 3 scroll-bars) 0) (nth 5 scroll-bars)))
                (set-window-vscroll window (cdr (assq 'vscroll state)))
                ;; Adjust vertically.
                (if (memq window-size-fixed '(t height))
@@ -5789,7 +5799,7 @@ hold:
   wide as `split-width-threshold'.
 - When WINDOW is split evenly, the emanating windows are at least
   `window-min-width' or two (whichever is larger) columns wide."
-  (when (window-live-p window)
+  (when (and (window-live-p window) (not (window--side-window-p window)))
     (with-current-buffer (window-buffer window)
       (if horizontal
          ;; A window can be split horizontally when its width is not
@@ -6440,7 +6450,10 @@ again with `display-buffer-pop-up-window'."
 This either splits the selected window or reuses the window below
 the selected one."
   (let (window)
-    (or (and (not (frame-parameter nil 'unsplittable))
+    (or (and (setq window (window-in-direction 'below))
+            (eq buffer (window-buffer window))
+            (window--display-buffer buffer window 'reuse alist))
+       (and (not (frame-parameter nil 'unsplittable))
             (let ((split-height-threshold 0)
                   split-width-threshold)
               (setq window (window--try-to-split-window (selected-window) alist)))
@@ -6453,13 +6466,26 @@ the selected one."
 
 (defun display-buffer-at-bottom (buffer alist)
   "Try displaying BUFFER in a window at the bottom of the selected frame.
-This either splits the window at the bottom of the frame or the
-frame's root window, or reuses an existing window at the bottom
-of the selected frame."
-  (let (bottom-window window)
+This either reuses such a window provided it shows BUFFER
+already, splits a window at the bottom of the frame or the
+frame's root window, or reuses some window at the bottom of the
+selected frame."
+  (let (bottom-window bottom-window-shows-buffer window)
     (walk-window-tree
-     (lambda (window) (setq bottom-window window)) nil nil 'nomini)
-    (or (and (not (frame-parameter nil 'unsplittable))
+     (lambda (window)
+       (cond
+       ((window-in-direction 'below window))
+       ((and (not bottom-window-shows-buffer)
+             (eq buffer (window-buffer window)))
+        (setq bottom-window-shows-buffer t)
+        (setq bottom-window window))
+       ((not bottom-window)
+        (setq bottom-window window)))
+       nil nil 'nomini))
+    (or (and bottom-window-shows-buffer
+            (window--display-buffer
+             buffer bottom-window 'reuse alist display-buffer-mark-dedicated))
+     (and (not (frame-parameter nil 'unsplittable))
             (let (split-width-threshold)
               (setq window (window--try-to-split-window bottom-window alist)))
             (window--display-buffer
@@ -7147,7 +7173,7 @@ FRAME."
             (height
              (+ (cdr value)
                 (window-bottom-divider-width)
-                (nth 3 (window-scroll-bars)))))
+                (window-scroll-bar-height))))
        ;; Don't change height or width when the window's size is fixed
        ;; in either direction or ONLY forbids it.
        (cond
@@ -7231,7 +7257,7 @@ and header line and a bottom divider, if any.
 
 If WINDOW is part of a horizontal combination and the value of
 the option `fit-window-to-buffer-horizontally' is non-nil, adjust
-WINDOW's height.  The new width of WINDOW is calculated from the
+WINDOW's width.  The new width of WINDOW is calculated from the
 maximum length of its buffer's lines that follow the current
 start position of WINDOW.  The optional argument MAX-WIDTH
 specifies a maximum width and defaults to the width of WINDOW's
@@ -7306,7 +7332,7 @@ accessible position."
          ;; height.  Its width remains fixed.
          (setq height (+ (cdr (window-text-pixel-size
                                nil nil t nil (frame-pixel-height) t))
-                         (nth 3 (window-scroll-bars window))
+                         (window-scroll-bar-height window)
                          (window-bottom-divider-width)))
          ;; Round height.
          (unless pixelwise
@@ -7348,10 +7374,10 @@ accessible position."
                             max-width))
                    (+ total-width (window-max-delta
                                    nil t nil nil nil nil pixelwise))))
-                ;; When fitting vertically, assume that WINDOW's start
-                ;; position remains unaltered.  WINDOW can't get wider
-                ;; than its frame's pixel width, its height remains
-                ;; unaltered.
+                ;; When fitting horizontally, assume that WINDOW's
+                ;; start position remains unaltered.  WINDOW can't get
+                ;; wider than its frame's pixel width, its height
+                ;; remains unaltered.
                 (width (+ (car (window-text-pixel-size
                                 nil (window-start) (point-max)
                                 (frame-pixel-width)
@@ -7360,7 +7386,7 @@ accessible position."
                                 ;; overshoots when the first line below
                                 ;; the bottom is wider than the window.
                                 (* body-height
-                                   (if pixelwise char-height 1))))
+                                   (if pixelwise 1 char-height))))
                           (window-right-divider-width))))
            (unless pixelwise
              (setq width (/ (+ width char-width -1) char-width)))