]> code.delx.au - gnu-emacs/blobdiff - lisp/window.el
Prevent bar cursor overwriting next glyph (bug#16856)
[gnu-emacs] / lisp / window.el
index d9ac0e6d240cded4619ad249baea3a740f0ef2a1..a0bdfeb672a454b2547c7f090a5763286fc8816c 100644 (file)
@@ -6746,6 +6746,71 @@ that frame."
        (unless (cdr (assq 'inhibit-switch-frame alist))
          (window--maybe-raise-frame (window-frame window)))))))
 
+(defun display-buffer-reuse-mode-window (buffer alist)
+  "Return a window based on the mode of the buffer it displays.
+Display BUFFER in the returned window.  Return nil if no usable
+window is found.
+
+If ALIST contains a `mode' entry, its value is a major mode (a
+symbol) or a list of modes.  A window is a candidate if it
+displays a buffer that derives from one of the given modes.  When
+ALIST contains no `mode' entry, the current major mode of BUFFER
+is used.
+
+The behaviour is also controlled by entries for
+`inhibit-same-window', `reusable-frames' and
+`inhibit-switch-frame' as is done in the function
+`display-buffer-reuse-window'."
+  (let* ((alist-entry (assq 'reusable-frames alist))
+         (alist-mode-entry (assq 'mode alist))
+        (frames (cond (alist-entry (cdr alist-entry))
+                      ((if (eq pop-up-frames 'graphic-only)
+                           (display-graphic-p)
+                         pop-up-frames)
+                       0)
+                      (display-buffer-reuse-frames 0)
+                      (t (last-nonminibuffer-frame))))
+         (inhibit-same-window-p (cdr (assq 'inhibit-same-window alist)))
+        (windows (window-list-1 nil 'nomini frames))
+         (buffer-mode (with-current-buffer buffer major-mode))
+         (allowed-modes (if alist-mode-entry
+                            (cdr alist-mode-entry)
+                          buffer-mode))
+         (curwin (selected-window))
+         (curframe (selected-frame)))
+    (unless (listp allowed-modes)
+      (setq allowed-modes (list allowed-modes)))
+    (let (same-mode-same-frame
+          same-mode-other-frame
+          derived-mode-same-frame
+          derived-mode-other-frame)
+      (dolist (window windows)
+        (let (mode? frame?)
+          (with-current-buffer (window-buffer window)
+            (setq mode?
+                  (cond ((memq major-mode allowed-modes)
+                         'same)
+                        ((derived-mode-p allowed-modes)
+                         'derived))))
+          (when (and mode?
+                     (not (and inhibit-same-window-p
+                               (eq window curwin))))
+            (if (eq curframe (window-frame window))
+                (if (eq mode? 'same)
+                    (push window same-mode-same-frame)
+                  (push window derived-mode-same-frame))
+              (if (eq mode? 'same)
+                  (push window same-mode-other-frame)
+                (push window derived-mode-other-frame))))))
+      (let ((window (car (nconc same-mode-same-frame
+                                same-mode-other-frame
+                                derived-mode-same-frame
+                                derived-mode-other-frame))))
+        (when (window-live-p window)
+          (prog1 (window--display-buffer buffer window 'reuse alist)
+            (unless (cdr (assq 'inhibit-switch-frame alist))
+              (window--maybe-raise-frame (window-frame window)))))))))
+
 (defun display-buffer--special-action (buffer)
   "Return special display action for BUFFER, if any.
 If `special-display-p' returns non-nil for BUFFER, return an
@@ -7082,7 +7147,7 @@ buffer with the name BUFFER-OR-NAME and return that buffer."
            buffer))
     (other-buffer)))
 
-(defcustom switch-to-buffer-preserve-window-point nil
+(defcustom switch-to-buffer-preserve-window-point t
   "If non-nil, `switch-to-buffer' tries to preserve `window-point'.
 If this is nil, `switch-to-buffer' displays the buffer at that
 buffer's `point'.  If this is `already-displayed', it tries to
@@ -7100,7 +7165,7 @@ the selected window or never appeared in it before, or if
          (const :tag "If already displayed elsewhere" already-displayed)
          (const :tag "Always" t))
   :group 'windows
-  :version "24.3")
+  :version "25.2")
 
 (defcustom switch-to-buffer-in-dedicated-window nil
   "Allow switching to buffer in strongly dedicated windows.
@@ -8543,16 +8608,17 @@ displaying that processes's buffer."
 
 (defun window--adjust-process-windows ()
   "Update process window sizes to match the current window configuration."
-  (dolist (procwin (window--process-window-list))
-    (let ((process (car procwin)))
-      (with-demoted-errors "Error adjusting window size: %S"
-        (with-current-buffer (process-buffer process)
-          (let ((size (funcall
-                       (or (process-get process 'adjust-window-size-function)
-                           window-adjust-process-window-size-function)
-                       process (cdr procwin))))
-            (when size
-              (set-process-window-size process (cdr size) (car size)))))))))
+  (when (fboundp 'process-list)
+    (dolist (procwin (window--process-window-list))
+      (let ((process (car procwin)))
+        (with-demoted-errors "Error adjusting window size: %S"
+          (with-current-buffer (process-buffer process)
+            (let ((size (funcall
+                         (or (process-get process 'adjust-window-size-function)
+                             window-adjust-process-window-size-function)
+                         process (cdr procwin))))
+              (when size
+                (set-process-window-size process (cdr size) (car size))))))))))
 
 (add-hook 'window-configuration-change-hook 'window--adjust-process-windows)