]> code.delx.au - gnu-emacs/blobdiff - lisp/window.el
Update doc-string of display-buffer-alist.
[gnu-emacs] / lisp / window.el
index aa874b8e50386a7bf81f3f416d1f34c60680d174..a4baf99d956ac5a04e3e5f1ed7683a402aaf9d2c 100644 (file)
@@ -3500,12 +3500,11 @@ buffer display specifiers.")
      (reuse-window nil same nil)
      (pop-up-window (largest . nil) (lru . nil))
      (reuse-window nil other nil))
-    (other-window
-     ;; Avoid selected window.
-     (reuse-window other same visible)
-     (pop-up-window (largest . nil) (lru . nil))
-     (pop-up-frame)
-     (reuse-window other other visible))
+    ;; (other-window
+    ;;  ;; Avoid selected window.
+    ;;  (reuse-window other same visible)
+    ;;  (pop-up-window (largest . nil) (lru . nil))
+    ;;  (reuse-window other other visible))
     (same-frame-other-window
      ;; Avoid other frames and selected window.
      (reuse-window other same nil)
@@ -3523,10 +3522,16 @@ buffer display specifiers.")
 
 (defcustom display-buffer-alist
   '((((regexp . ".*"))
+     ;; Reuse window showing same buffer.
      reuse-window (reuse-window nil same visible)
+     ;; Pop up window.
      pop-up-window
+     ;; Split largest or lru window.
      (pop-up-window (largest . nil) (lru . nil))
-     reuse-window (reuse-window other other nil)
+     (pop-up-window-min-height . 40) ; split-height-threshold / 2
+     (pop-up-window-min-width . 80) ; split-width-threshold / 2
+     ;; Reuse any but selected window on same frame.
+     reuse-window (reuse-window other nil nil)
      (reuse-window-even-sizes . t)))
   "List associating buffer identifiers with display specifiers.
 The car of each element of this list is built from a set of cons
@@ -3787,6 +3792,14 @@ supported:
 
 - t to strongly dedicate the window to the buffer.
 
+A cons cell whose car is `other-window-means-other-frame' and
+whose cdr is non-nil means that you want calls of
+`display-buffer' with the second argument t or the symbol
+`other-window' to display the buffer in another frame.  This
+means, for example, that you prefer functions like
+`find-file-other-window' or `switch-to-buffer-other-window' to
+make a new frame instead of a new window on the selected frame.
+
 Usually, applications are free to override the specifiers of
 `display-buffer-alist' by passing their own specifiers as second
 argument of `display-buffer'.  For every `display-buffer-alist'
@@ -4231,6 +4244,15 @@ using the location specifiers `same-window' or `other-frame'."
        :format "%[No other window%] %v\n" :size 15
        (const :tag "Off" :format "%t" nil)
        (const :tag "Ignore" :format "%t" t)))
+      ;; Other window means other frame.
+      (cons
+       :format "%v"
+       (const :format "" other-window-means-other-frame)
+       (choice
+       :help-echo "Whether other window means same or other frame."
+       :format "%[Same or other frame%] %v\n" :size 15
+       (const :tag "Same frame" :format "%t" nil)
+       (const :tag "Other frame" :format "%t" t)))
       ;; Overriding.
       (cons
        :format "%v\n"
@@ -4915,6 +4937,26 @@ SPECIFIERS must be a list of buffer display specifiers."
          (set-window-parameter window 'window-slot slot))
        (display-buffer-in-window buffer window specifiers)))))
 
+(defun display-buffer-other-window-means-other-frame (buffer-or-name &optional label)
+  "Return non-nil if BUFFER shall be preferably displayed in another frame.
+BUFFER must be a live buffer or the name of a live buffer.
+
+Return nil if BUFFER shall be preferably displayed in another
+window on the selected frame.  Return non-nil if BUFFER shall be
+preferably displayed in a window on any but the selected frame.
+
+Optional argument LABEL is like the same argument of
+`display-buffer'.
+
+The calculation of the return value is exclusively based on the
+user preferences expressed in `display-buffer-alist'."
+  (let* ((buffer (normalize-live-buffer buffer-or-name))
+        (list (display-buffer-normalize-specifiers-3
+               (buffer-name buffer) label))
+        (value (assq 'other-window-means-other-frame
+                     (or (car list) (cdr list)))))
+    (when value (cdr value))))
+
 (defun normalize-buffer-to-display (buffer-or-name)
   "Normalize BUFFER-OR-NAME argument for buffer display functions.
 If BUFFER-OR-NAME is nil, return the curent buffer.  Else, if a
@@ -4928,9 +4970,11 @@ BUFFER-OR-NAME and return that buffer."
            buffer))
     (current-buffer)))
 
-(defun display-buffer-normalize-specifiers-1 (specifiers)
+(defun display-buffer-normalize-specifiers-1 (specifiers buffer-name label)
   "Subroutine of `display-buffer-normalize-specifiers'.
-SPECIFIERS is the SPECIFIERS argument of `display-buffer'."
+SPECIFIERS is a list of buffer display specfiers.  BUFFER-NAME is
+the name of the buffer that shall be displayed, LABEL the same
+argument of `display-buffer'."
   (let (normalized entry)
     (cond
      ((not specifiers)
@@ -4941,6 +4985,14 @@ SPECIFIERS is the SPECIFIERS argument of `display-buffer'."
        (cond
         ((consp specifier)
          (setq normalized (cons specifier normalized)))
+        ((eq specifier 'other-window)
+         ;; `other-window' must be treated separately.
+         (let* ((other-frame (display-buffer-other-window-means-other-frame
+                              buffer-name label))
+                (entry (assq (if other-frame 'other-frame 'other-window)
+                             display-buffer-macro-specifiers)))
+           (dolist (item (cdr entry))
+             (setq normalized (cons item normalized)))))
         ((symbolp specifier)
          ;; Might be a macro specifier, try to expand it (the cdr is a
          ;; list and we have to reverse it later, so do it one at a
@@ -4950,16 +5002,15 @@ SPECIFIERS is the SPECIFIERS argument of `display-buffer'."
              (setq normalized (cons item normalized)))))))
       ;; Reverse list.
       (nreverse normalized))
-     ((and (not (eq specifiers 'other-window))
-          (setq entry (assq specifiers display-buffer-macro-specifiers)))
+     ((setq entry (assq specifiers display-buffer-macro-specifiers))
       ;; A macro specifier.
       (cdr entry))
-     ((with-no-warnings (memq pop-up-frames '(nil unset)))
-      ;; Pop up a new window.
-      (cdr (assq 'other-window display-buffer-macro-specifiers)))
+     ((or (display-buffer-other-window-means-other-frame buffer-name label)
+         (with-no-warnings (not pop-up-frames)))
+      (cdr (assq 'other-frame display-buffer-macro-specifiers)))
      (t
-      ;; Pop up a new frame.
-      (cdr (assq 'other-frame display-buffer-macro-specifiers))))))
+      ;; In any other case pop up a new window.
+      (cdr (assq 'same-frame-other-window display-buffer-macro-specifiers))))))
 
 (defun display-buffer-normalize-specifiers-2 (&optional buffer-or-name)
   "Subroutine of `display-buffer-normalize-specifiers'.
@@ -4971,8 +5022,13 @@ options."
         specifiers)
     ;; Disable warnings, there are too many obsolete options here.
     (with-no-warnings
+      ;; `even-window-heights', unless nil or unset.
+      (unless (memq even-window-heights '(nil unset))
+       (setq specifiers
+             (cons (cons 'reuse-window-even-sizes t) specifiers)))
+
       ;; `display-buffer-mark-dedicated'
-      (unless (memq display-buffer-mark-dedicated '(nil unset))
+      (when display-buffer-mark-dedicated
        (setq specifiers
              (cons (cons 'dedicate display-buffer-mark-dedicated)
                    specifiers)))
@@ -5004,10 +5060,21 @@ options."
                            (cons 'largest fun) (cons 'lru fun))
                      specifiers))))
 
-      ;; `pop-up-frame' group.  Anything is added here iff
-      ;; `pop-up-frames' is neither nil nor unset (we ignore the problem
-      ;; that callers usually don't care about graphic-only).
-      (unless (memq pop-up-frames '(nil unset))
+      ;; `special-display-p' group.
+      (when special-display-function
+       ;; `special-display-p' returns either t or a list of frame
+       ;; parameters to pass to `special-display-function'.
+       (let ((pars (special-display-p buffer-name)))
+         (when pars
+           (setq specifiers
+                 (cons (list 'fun-with-args special-display-function
+                             (when (listp pars) pars))
+                       specifiers)))))
+
+      ;; `pop-up-frame' group.  Add things if `pop-up-frames' is non-nil
+      ;; (we ignore the problem that callers usually don't care about
+      ;; graphic-only).
+      (when pop-up-frames
        ;; `pop-up-frame-function'.  If `pop-up-frame-function' uses the
        ;; now obsolete `pop-up-frame-alist' it will continue to do so.
        (setq specifiers
@@ -5017,163 +5084,39 @@ options."
        (setq specifiers
              (cons (list 'pop-up-frame pop-up-frames) specifiers)))
 
-      ;; `special-display-regexps'
-      (dolist (entry special-display-regexps)
-       (cond
-        ((stringp entry)
-         ;; Plain string.
-         (when (string-match-p entry buffer-name)
-           (setq specifiers
-                 (cons
-                  (list 'fun-with-args special-display-function
-                        special-display-frame-alist)
-                  specifiers))))
-        ((consp entry)
-         (let ((name (car entry))
-               (rest (cdr entry)))
-           (cond
-            ((not (string-match-p name buffer-name)))
-            ((functionp (car rest))
-             ;; A function.
-             (setq specifiers
-                   (cons (list 'fun-with-args (car rest) (cadr rest))
-                         specifiers)))
-            ((listp rest)
-             ;; A list of parameters.
-             (cond
-              ((assq 'same-window rest)
-               (setq specifiers
-                     (cons (list 'reuse-window 'same) specifiers))
-               (setq specifiers
-                     (cons (list 'reuse-window-dedicated 'weak)
-                           specifiers)))
-              ((assq 'same-frame rest)
-               (setq specifiers
-                     (setq specifiers
-                           (cons (list 'same-frame) specifiers))))
-              (t
-               (setq specifiers
-                     (cons (list 'fun-with-args special-display-function
-                                 special-display-frame-alist)
-                           specifiers))))))))))
-
-      ;; `special-display-buffer-names'
-      (dolist (entry special-display-buffer-names)
-       (cond
-        ((stringp entry)
-         ;; Plain string.
-         (when (string-equal entry buffer-name)
-           (setq specifiers
-                 (cons
-                  (list 'fun-with-args special-display-function
-                        special-display-frame-alist)
-                  specifiers))))
-        ((consp entry)
-         (let ((name (car entry))
-               (rest (cdr entry)))
-           (cond
-            ((not (string-equal name buffer-name)))
-            ((functionp (car rest))
-             ;; A function.
-             (setq specifiers
-                   (cons (list 'fun-with-args (car rest) (cadr rest))
-                         specifiers)))
-            ((listp rest)
-             ;; A list of parameters.
-             (cond
-              ((assq 'same-window rest)
-               (setq specifiers
-                     (cons (list 'reuse-window 'same) specifiers))
-               (setq specifiers
-                     (cons (list 'reuse-window-dedicated 'weak)
-                           specifiers)))
-              ((assq 'same-frame rest)
-               (setq specifiers
-                     (setq specifiers
-                           (cons (list 'same-frame) specifiers))))
-              (t
-               (setq specifiers
-                     (cons (list 'fun-with-args special-display-function
-                                 special-display-frame-alist)
-                           specifiers))))))))))
-
-      ;; `same-window-regexps'
-      (dolist (entry same-window-regexps)
-       (cond
-        ((stringp entry)
-         (when (string-match-p entry buffer-name)
-           (setq specifiers
-                 (cons (list 'reuse-window 'same) specifiers))))
-        ((consp entry)
-         (when (string-match-p (car entry) buffer-name)
-           (setq specifiers
-                 (cons (list 'reuse-window 'same) specifiers))))))
-
-      ;; `same-window-buffer-names'
-      (dolist (entry same-window-buffer-names)
-       (cond
-        ((stringp entry)
-         (when (string-equal entry buffer-name)
-           (setq specifiers
-                 (cons (list 'reuse-window 'same) specifiers))))
-        ((consp entry)
-         (when (string-equal (car entry) buffer-name)
-           (setq specifiers
-                 (cons (list 'reuse-window 'same) specifiers))))))
+      ;; `same-window-p' group.
+      (when (same-window-p buffer-name)
+       ;; Try to reuse the same (selected) window.
+       (setq specifiers
+             (cons (list 'reuse-window 'same nil nil)
+                   specifiers)))
 
-      ;; `pop-up-windows' and `pop-up-frames' nil means means we
+      ;; `pop-up-windows' and `pop-up-frames' both nil means means we
       ;; are supposed to reuse any window (unless we find one showing
       ;; the same buffer already).
-
-      ;; This clause is needed because Emacs 23 options can be used to
-      ;; suppress a certain behavior while `display-buffer-alist' can be
-      ;; only used to enforce some behavior.
-      (when (and (not pop-up-windows) (memq pop-up-frames '(nil unset)))
-       ;; `even-window-heights'
-       (when even-window-heights
-         (setq specifiers
-               (cons (cons 'reuse-window-even-sizes t) specifiers)))
+      (unless (or pop-up-windows pop-up-frames)
        ;; `reuse-window' showing any buffer on same frame.
        (setq specifiers
              (cons (list 'reuse-window nil nil nil)
                    specifiers)))
 
-      ;; `display-buffer-reuse-frames' or `pop-up-frames' set means we
-      ;; are supposed to reuse a window showing the same buffer.
-      (unless (and (memq display-buffer-reuse-frames '(nil unset))
-                  (memq pop-up-frames '(nil unset)))
-       ;; `even-window-heights'
-       (when even-window-heights
-         (setq specifiers
-               (cons (cons 'reuse-window-even-sizes t) specifiers)))
+      ;; `display-buffer-reuse-frames' or `pop-up-frames' non-nil means
+      ;; we are supposed to reuse a window showing the same buffer on
+      ;; another frame.
+      (when (or display-buffer-reuse-frames pop-up-frames)
        ;; `reuse-window' showing same buffer on visible frame.
        (setq specifiers
-             (cons (list 'reuse-window nil 'same 0)
-                   specifiers)))
+             (cons (list 'reuse-window nil 'same 0) specifiers)))
 
-      specifiers)))
+      ;; Prepend "reuse window on same frame if showing the buffer
+      ;; already" specifier.
+      (setq specifiers (cons (list 'reuse-window nil 'same nil)
+                            specifiers))
 
-(defun display-buffer-normalize-specifiers (buffer-name specifiers label)
-  "Return normalized specifiers for a buffer matching BUFFER-NAME or LABEL.
-BUFFER-NAME must be a string specifying a valid buffer name.
-SPECIFIERS and LABEL are the homonymous arguments of
-`display-buffer'.
-
-The method for displaying the buffer specified by BUFFER-NAME or
-LABEL is established by appending the following four lists of
-specifiers:
-
-- The specifiers in `display-buffer-alist' whose buffer
-  identifier matches BUFFER-NAME or LABEL and whose 'override
-  component is set.
-
-- SPECIFIERS.
-
-- The specifiers in `display-buffer-alist' whose buffer
-  identifier matches BUFFER-NAME or LABEL and whose 'override
-  component is not set.
+      specifiers)))
 
-- `display-buffer-default-specifiers'."
+(defun display-buffer-normalize-specifiers-3 (buffer-name label)
+  "Subroutine of `display-buffer-normalize-specifiers'."
   (let (list-1 list-2)
     (dolist (entry display-buffer-alist)
       (when (and (listp entry)
@@ -5189,7 +5132,8 @@ specifiers:
                                   (and (eq type 'label) (eq value label)))
                           (throw 'match t)))))))
        (let* ((raw (cdr entry))
-              (normalized (display-buffer-normalize-specifiers-1 raw)))
+              (normalized
+               (display-buffer-normalize-specifiers-1 raw buffer-name label)))
          (if (assq 'override raw)
              (setq list-1
                    (if list-1
@@ -5200,15 +5144,39 @@ specifiers:
                      (append list-2 normalized)
                    normalized))))))
 
+    (cons list-1 list-2)))
+
+(defun display-buffer-normalize-specifiers (buffer-name specifiers label)
+  "Return normalized specifiers for a buffer matching BUFFER-NAME or LABEL.
+BUFFER-NAME must be a string specifying a valid buffer name.
+SPECIFIERS and LABEL are the homonymous arguments of
+`display-buffer'.
+
+The method for displaying the buffer specified by BUFFER-NAME or
+LABEL is established by appending the following four lists of
+specifiers:
+
+- The specifiers in `display-buffer-alist' whose buffer
+  identifier matches BUFFER-NAME or LABEL and whose 'override
+  component is set.
+
+- SPECIFIERS.
+
+- The specifiers in `display-buffer-alist' whose buffer
+  identifier matches BUFFER-NAME or LABEL and whose 'override
+  component is not set.
+
+- `display-buffer-default-specifiers'."
+  (let* ((list (display-buffer-normalize-specifiers-3 buffer-name label)))
     (append
      ;; Overriding user specifiers.
-     list-1
+     (car list)
      ;; Application specifiers.
-     (display-buffer-normalize-specifiers-1 specifiers)
+     (display-buffer-normalize-specifiers-1 specifiers buffer-name label)
      ;; Emacs 23 compatibility specifiers.
      (display-buffer-normalize-specifiers-2 buffer-name)
      ;; Non-overriding user specifiers.
-     list-2
+     (cdr list)
      ;; Default specifiers.
      display-buffer-default-specifiers)))
 
@@ -5628,8 +5596,8 @@ This function returns non-nil if `display-buffer' or
 `pop-to-buffer' would show a buffer named BUFFER-NAME in the
 selected rather than \(as usual\) some other window.  See
 `same-window-buffer-names' and `same-window-regexps'."
-  (let ((buffer-names (with-no-warnings special-display-buffer-names))
-       (regexps (with-no-warnings special-display-regexps)))
+  (let ((buffer-names (with-no-warnings same-window-buffer-names))
+       (regexps (with-no-warnings same-window-regexps)))
     (cond
      ((not (stringp buffer-name)))
      ;; The elements of `same-window-buffer-names' can be buffer
@@ -5937,32 +5905,28 @@ frame.  The default value calls `make-frame' with the argument
  'pop-up-frame-function
  "use 2nd arg of `display-buffer' instead." "24.1")
 
-(defcustom pop-up-frames 'unset ; nil
+(defcustom pop-up-frames nil
   "Whether `display-buffer' should make a separate frame.
 If nil, never make a separate frame.
 If the value is `graphic-only', make a separate frame
 on graphic displays only.
-If this is the symbol unset, the option was not set and is
-ignored.
 Any other non-nil value means always make a separate frame."
   :type '(choice
-         (const :tag "Unset" unset)
          (const :tag "Never" nil)
          (const :tag "On graphic displays only" graphic-only)
          (const :tag "Always" t))
-  :version "24.1"
   :group 'windows
   :group 'frames)
 (make-obsolete-variable
  'pop-up-frames
  "use 2nd arg of `display-buffer' instead." "24.1")
 
-(defcustom display-buffer-reuse-frames 'unset ; nil
+(defcustom display-buffer-reuse-frames nil
   "Set and non-nil means `display-buffer' should reuse frames.
 If the buffer in question is already displayed in a frame, raise
 that frame."
   :type 'boolean
-  :version "24.1"
+  :version "21.1"
   :group 'windows
   :group 'frames)
 (make-obsolete-variable
@@ -6033,20 +5997,20 @@ is nil, `display-buffer' cannot split windows horizontally."
  'split-width-threshold
  "use 2nd arg of `display-buffer' instead." "24.1")
 
-(defcustom even-window-heights t
-  "If non-nil `display-buffer' will try to even window heights.
+(defcustom even-window-heights 'unset ; t
+  "If set and non-nil `display-buffer' will try to even window heights.
 Otherwise `display-buffer' will leave the window configuration
 alone.  Heights are evened only when `display-buffer' reuses a
 window that appears above or below the selected window."
   :type 'boolean
-  :version "23.1"
+  :version "24.1"
   :group 'windows)
 (make-obsolete-variable
  'even-window-heights
  "use 2nd arg of `display-buffer' instead." "24.1")
 
-(defvar display-buffer-mark-dedicated 'unset ; nil
-  "Set and non-nil means `display-buffer' marks the windows it creates as dedicated.
+(defvar display-buffer-mark-dedicated nil
+  "Non-nil means `display-buffer' marks the windows it creates as dedicated.
 The actual non-nil value of this variable will be copied to the
 `window-dedicated-p' flag.")
 (make-obsolete-variable
@@ -6223,7 +6187,7 @@ value of `display-buffer-alist'."
      nil
      (list
       'pop-up-frame
-      (unless (memq pop-up-frames '(nil unset))
+      (when pop-up-frames
        (list 'pop-up-frame pop-up-frames))
       (when pop-up-frame-function
        (cons 'pop-up-frame-function pop-up-frame-function))
@@ -6359,17 +6323,16 @@ value of `display-buffer-alist'."
      (list
       'reuse-window
       (list 'reuse-window nil 'same
-           (unless (and (memq display-buffer-reuse-frames '(nil unset))
-                        (memq pop-up-frames '(nil unset)))
+           (when (or display-buffer-reuse-frames pop-up-frames)
              ;; "0" (all visible and iconified frames) is hardcoded in
              ;; Emacs 23.
                0))
-      (when even-window-heights
+      (unless (memq even-window-heights '(nil unset))
        (cons 'reuse-window-even-sizes t)))
      no-custom)
 
     ;; `display-buffer-mark-dedicated'
-    (unless (memq display-buffer-mark-dedicated '(nil unset))
+    (when display-buffer-mark-dedicated
       (display-buffer-alist-add
        nil
        (list