GNU bug report logs - #30314
Define aliases for window display actions

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Wed, 31 Jan 2018 21:58:01 UTC

Severity: wishlist

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 30314 in the body.
You can then email your comments to 30314 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#30314; Package emacs. (Wed, 31 Jan 2018 21:58:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 31 Jan 2018 21:58:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Define aliases for window display actions
Date: Wed, 31 Jan 2018 23:52:55 +0200
Severity: wishlist

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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30314; Package emacs. (Sun, 04 Feb 2018 22:32:01 GMT) Full text and rfc822 format available.

Message #8 received at 30314 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 30314 <at> debbugs.gnu.org
Subject: Re: bug#30314: Define aliases for window display actions
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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30314; Package emacs. (Tue, 06 Feb 2018 21:44:02 GMT) Full text and rfc822 format available.

Message #11 received at 30314 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 30314 <at> debbugs.gnu.org
Subject: Re: bug#30314: Define aliases for window display actions
Date: Tue, 06 Feb 2018 23:42:10 +0200
[Message part 1 (text/plain, inline)]
> +        (and (if (eq pop-up-frames 'graphic-only)
> +	         (display-graphic-p)
> +	       pop-up-frames)
> +	     (display-buffer-pop-up-frame buffer alist))

Nah, this can't be right.  Better to create new functions for this:

[display-buffer--maybe.patch (text/x-diff, inline)]
diff --git a/lisp/files.el b/lisp/files.el
index 414eb3f..4b67b02 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--maybe-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--maybe-at-bottom)
                 #'(lambda (window _value)
                     (with-selected-window window
                       (unwind-protect
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 4d14b26..5d91242 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1823,12 +1823,7 @@ minibuffer-completion-help
              ;; window, mark it as softly-dedicated, so bury-buffer in
              ;; minibuffer-hide-completions will know whether to
              ;; delete the window or not.
-             (display-buffer-mark-dedicated 'soft)
-             ;; Disable `pop-up-windows' temporarily to allow
-             ;; `display-buffer--maybe-pop-up-frame-or-window'
-             ;; in the display actions below to pop up a frame
-             ;; if `pop-up-frames' is non-nil, but not to pop up a window.
-             (pop-up-windows nil))
+             (display-buffer-mark-dedicated 'soft))
         (with-displayed-buffer-window
           "*Completions*"
           ;; This is a copy of `display-buffer-fallback-action'
@@ -1836,7 +1831,7 @@ minibuffer-completion-help
           ;; with `display-buffer-at-bottom'.
           `((display-buffer--maybe-same-window
              display-buffer-reuse-window
-             display-buffer--maybe-pop-up-frame-or-window
+             display-buffer--maybe-pop-up-frame
              ;; Use `display-buffer-below-selected' for inline completions,
              ;; but not in the minibuffer (e.g. in `eval-expression')
              ;; for which `display-buffer-at-bottom' is used.
diff --git a/lisp/window.el b/lisp/window.el
index abd1a68..8c5e441 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7289,12 +7289,23 @@ display-buffer--maybe-pop-up-frame-or-window
 
 If that cannot be done, and `pop-up-windows' is non-nil, try
 again with `display-buffer-pop-up-window'."
-  (or (and (if (eq pop-up-frames 'graphic-only)
-	       (display-graphic-p)
-	     pop-up-frames)
-	   (display-buffer-pop-up-frame buffer alist))
-      (and pop-up-windows
-	   (display-buffer-pop-up-window buffer alist))))
+  (or (display-buffer--maybe-pop-up-frame buffer alist)
+      (display-buffer--maybe-pop-up-window buffer alist)))
+
+(defun display-buffer--maybe-pop-up-frame (buffer alist)
+  "Try displaying BUFFER based on `pop-up-frames'.
+If `pop-up-frames' is non-nil (and not `graphic-only' on a
+text-only terminal), try with `display-buffer-pop-up-frame'."
+  (and (if (eq pop-up-frames 'graphic-only)
+	   (display-graphic-p)
+	 pop-up-frames)
+       (display-buffer-pop-up-frame buffer alist)))
+
+(defun display-buffer--maybe-pop-up-window (buffer alist)
+  "Try displaying BUFFER based on `pop-up-windows'.
+If `pop-up-windows' is non-nil, try with `display-buffer-pop-up-window'."
+  (and pop-up-windows
+       (display-buffer-pop-up-window buffer alist)))
 
 (defun display-buffer-in-child-frame (buffer alist)
   "Display BUFFER in a child frame.
@@ -7360,6 +7371,17 @@ display-buffer-below-selected
 	     (window--display-buffer
 	      buffer window 'reuse alist display-buffer-mark-dedicated)))))
 
+(defun display-buffer--maybe-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)
+        (display-buffer--maybe-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
@@ -7376,8 +7398,8 @@ display-buffer-at-bottom
 	 (setq bottom-window-shows-buffer t)
 	 (setq bottom-window window))
 	((not bottom-window)
-	 (setq bottom-window window)))
-       nil nil 'nomini))
+	 (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))

Reply sent to Juri Linkov <juri <at> linkov.net>:
You have taken responsibility. (Sat, 10 Feb 2018 21:57:01 GMT) Full text and rfc822 format available.

Notification sent to Juri Linkov <juri <at> linkov.net>:
bug acknowledged by developer. (Sat, 10 Feb 2018 21:57:01 GMT) Full text and rfc822 format available.

Message #16 received at 30314-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 30314-done <at> debbugs.gnu.org
Subject: Re: bug#30314: Define aliases for window display actions
Date: Sat, 10 Feb 2018 23:55:45 +0200
> Better to create new functions for this:

Pushed to master, and closed.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 11 Mar 2018 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 99 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.