Subject: bug#30314: Define aliases for window display actions

From: Juri Linkov <[email-masked]>
Date: Mon, 05 Feb 2018 00:30:29 +0200

> Instead of duplicating the same list of actions in many places
> like in bug#30016:
>
>         (pop-to-buffer buf `((display-buffer--maybe-same-window
>                               display-buffer-reuse-window
>                               display-buffer--maybe-pop-up-frame-or-window
>                               display-buffer-at-bottom)
> 	                     ,(if temp-buffer-resize-mode
> 		                  '(window-height . resize-temp-buffer-window)
> 	                        '(window-height . fit-window-to-buffer))
> 	                     ,(when temp-buffer-resize-mode
> 	                        '(preserve-size . (nil . t)))))
>
> I propose to introduce the concept of display action aliases to group
> several actions under one name and use just this short name where needed.

I realized that aliases can be implemented simply by defining a new
composite action function:

diff --git a/lisp/files.el b/lisp/files.el
index 414eb3f..22d8247 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3315,15 +3315,7 @@ hack-local-variables-confirm
 
       ;; Display the buffer and read a choice.
       (save-window-excursion
-	(pop-to-buffer buf `((display-buffer--maybe-same-window
-                              display-buffer-reuse-window
-                              display-buffer--maybe-pop-up-frame-or-window
-                              display-buffer-at-bottom)
-	                     ,(if temp-buffer-resize-mode
-		                  '(window-height . resize-temp-buffer-window)
-	                        '(window-height . fit-window-to-buffer))
-	                     ,(when temp-buffer-resize-mode
-	                        '(preserve-size . (nil . t)))))
+	(pop-to-buffer buf '(display-buffer-composite-at-bottom))
 	(let* ((exit-chars '(?y ?n ?\s ?\C-g ?\C-v))
 	       (prompt (format "Please type %s%s: "
 			       (if offer-save "y, n, or !" "y or n")
@@ -6929,15 +6921,7 @@ save-buffers-kill-emacs
            (or (not active)
                (with-displayed-buffer-window
                 (get-buffer-create "*Process List*")
-                `((display-buffer--maybe-same-window
-                   display-buffer-reuse-window
-                   display-buffer--maybe-pop-up-frame-or-window
-                   display-buffer-at-bottom)
-	          ,(if temp-buffer-resize-mode
-		       '(window-height . resize-temp-buffer-window)
-	             '(window-height . fit-window-to-buffer))
-	          ,(when temp-buffer-resize-mode
-	             '(preserve-size . (nil . t))))
+                '(display-buffer-composite-at-bottom)
                 #'(lambda (window _value)
                     (with-selected-window window
                       (unwind-protect
diff --git a/lisp/window.el b/lisp/window.el
index abd1a68..d9a0bc8 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7360,6 +7360,20 @@ display-buffer-below-selected
 	     (window--display-buffer
 	      buffer window 'reuse alist display-buffer-mark-dedicated)))))
 
+(defun display-buffer-composite-at-bottom (buffer alist)
+  (let ((alist (append alist `(,(if temp-buffer-resize-mode
+		                    '(window-height . resize-temp-buffer-window)
+	                          '(window-height . fit-window-to-buffer))
+	                       ,(when temp-buffer-resize-mode
+	                          '(preserve-size . (nil . t)))))))
+    (or (display-buffer--maybe-same-window buffer alist)
+        (display-buffer-reuse-window buffer alist)
+        (and (if (eq pop-up-frames 'graphic-only)
+	         (display-graphic-p)
+	       pop-up-frames)
+	     (display-buffer-pop-up-frame buffer alist))
+        (display-buffer-at-bottom buffer alist))))
+
 (defun display-buffer-at-bottom (buffer alist)
   "Try displaying BUFFER in a window at the bottom of the selected frame.
 This either reuses such a window provided it shows BUFFER