emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/transient 7c67773: More flexible display of transient b


From: Jonas Bernoulli
Subject: [elpa] externals/transient 7c67773: More flexible display of transient buffer
Date: Mon, 27 Sep 2021 08:24:35 -0400 (EDT)

branch: externals/transient
commit 7c67773735dea5a0c41ad8afb69fdafb62c46c7c
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    More flexible display of transient buffer
    
    Display buffer after populating it and set additional display actions
    and window parameters using the display alist instead of hardcoding
    them.  (`set-window-hscroll' should be unnecessary so drop that.)
    
    Use a wrapper function around `fit-window-to-buffer' so that users can
    override it (but do not go as far as to provide a hook).
    
    Continue to call that function explicitly because the `window-height'
    display action is ignored when reusing an existing window, and while
    we don't encourage doing that, we still want to support it.  If an
    existing window is repurposed, then avoid shrinking it.
---
 docs/transient.org  | 47 +++++++++++++++++++++++++++-----------
 docs/transient.texi | 46 ++++++++++++++++++++++++++-----------
 lisp/transient.el   | 66 ++++++++++++++++++++++++++++++++++-------------------
 3 files changed, 110 insertions(+), 49 deletions(-)

diff --git a/docs/transient.org b/docs/transient.org
index 305684e..8e44939 100644
--- a/docs/transient.org
+++ b/docs/transient.org
@@ -8,7 +8,7 @@
 #+TEXINFO_DIR_CATEGORY: Emacs
 #+TEXINFO_DIR_TITLE: Transient: (transient).
 #+TEXINFO_DIR_DESC: Transient Commands
-#+SUBTITLE: for version 0.3.6
+#+SUBTITLE: for version 0.3.6 (v0.3.6-10-gbe119ee4+1)
 
 #+TEXINFO_DEFFN: t
 #+OPTIONS: H:4 num:4 toc:2
@@ -37,7 +37,7 @@ Calling a suffix command usually causes the transient to be 
exited
 but suffix commands can also be configured to not exit the transient.
 
 #+TEXINFO: @noindent
-This manual is for Transient version 0.3.6.
+This manual is for Transient version 0.3.6 (v0.3.6-10-gbe119ee4+1).
 
 #+BEGIN_QUOTE
 Copyright (C) 2018-2021 Jonas Bernoulli <jonas@bernoul.li>
@@ -517,24 +517,45 @@ window, and the key bindings are the same as for 
~scroll-up-command~ and
   buffer.  The transient popup buffer is displayed in a window using
   ~(display-buffer BUFFER transient-display-buffer-action)~.
 
-  The value of this option has the form ~(FUNCTION . ALIST)~, where
-  FUNCTION is a function or a list of functions.  Each such function
-  should accept two arguments: a buffer to display and an alist of the
-  same form as ALIST.  See [[info:elisp#Choosing Window]].
+  The value of this option has the form ~(FUNCTION . ALIST)~,
+  where FUNCTION is a function or a list of functions.  Each such
+  function should accept two arguments: a buffer to display and an
+  alist of the same form as ALIST.  See [[info:elisp#Choosing Window]]
+  for details.
+
+  The value of this option has the form ~(FUNCTION . ALIST)~,
+  where FUNCTION is a function or a list of functions.  Each such
+  function should accept two arguments: a buffer to display and
+  an alist of the same form as ALIST.  See ~display-buffer~ for
+  details.
+
+  The default is:
+
+  (display-buffer-in-side-window
+    (side . bottom)
+    (inhibit-same-window . t)
+    (window-parameters (no-other-window . t)))
 
-  The default is ~(display-buffer-in-side-window (side . bottom))~.
   This displays the window at the bottom of the selected frame.
-  Another useful value is ~(display-buffer-below-selected)~.  This is
-  what ~magit-popup~ used by default.  For more alternatives see
-  [[info:elisp#Display Action Functions]].
+  Another useful FUNCTION is `display-buffer-below-selected', which
+  is what `magit-popup' used by default.  For more alternatives see
+  [[info:elisp#Display Action Functions]] and [[info:elisp#Buffer Display
+  Action Alists]].
+
+  Note that the buffer that was current before the transient buffer
+  is shown should remain the current buffer.  Many suffix commands
+  act on the thing at point, if appropriate, and if the transient
+  buffer became the current buffer, then that would change what is
+  at point.  To that effect ~inhibit-same-window~ ensures that the
+  selected window is not used to show the transient buffer.
 
   It may be possible to display the window in another frame, but
   whether that works in practice depends on the window-manager.
   If the window manager selects the new window (Emacs frame),
-  then it doesn't work.
+  then that unfortunately changes which buffer is current.
 
-  If you change the value of this option, then you might also want
-  to change the value of ~transient-mode-line-format~.
+  If you change the value of this option, then you might also
+  want to change the value of ~transient-mode-line-format~.
 
 - User Option: transient-mode-line-format
 
diff --git a/docs/transient.texi b/docs/transient.texi
index 9134e20..8c873b3 100644
--- a/docs/transient.texi
+++ b/docs/transient.texi
@@ -31,7 +31,7 @@ General Public License for more details.
 @finalout
 @titlepage
 @title Transient User and Developer Manual
-@subtitle for version 0.3.6
+@subtitle for version 0.3.6 (v0.3.6-10-gbe119ee4+1)
 @author Jonas Bernoulli
 @page
 @vskip 0pt plus 1filll
@@ -65,7 +65,7 @@ Calling a suffix command usually causes the transient to be 
exited
 but suffix commands can also be configured to not exit the transient.
 
 @noindent
-This manual is for Transient version 0.3.6.
+This manual is for Transient version 0.3.6 (v0.3.6-10-gbe119ee4+1).
 
 @quotation
 Copyright (C) 2018-2021 Jonas Bernoulli <jonas@@bernoul.li>
@@ -708,24 +708,44 @@ This option specifies the action used to display the 
transient popup
 buffer.  The transient popup buffer is displayed in a window using
 @code{(display-buffer BUFFER transient-display-buffer-action)}.
 
-The value of this option has the form @code{(FUNCTION . ALIST)}, where
-FUNCTION is a function or a list of functions.  Each such function
-should accept two arguments: a buffer to display and an alist of the
-same form as ALIST@.  See @ref{Choosing Window,,,elisp,}.
+The value of this option has the form @code{(FUNCTION . ALIST)},
+where FUNCTION is a function or a list of functions.  Each such
+function should accept two arguments: a buffer to display and an
+alist of the same form as ALIST@.  See @ref{Choosing Window,,,elisp,}
+for details.
+
+The value of this option has the form @code{(FUNCTION . ALIST)},
+where FUNCTION is a function or a list of functions.  Each such
+function should accept two arguments: a buffer to display and
+an alist of the same form as ALIST@.  See @code{display-buffer} for
+details.
+
+The default is:
+
+(display-buffer-in-side-window
+  (side . bottom)
+  (inhibit-same-window . t)
+  (window-parameters (no-other-window . t)))
 
-The default is @code{(display-buffer-in-side-window (side . bottom))}.
 This displays the window at the bottom of the selected frame.
-Another useful value is @code{(display-buffer-below-selected)}.  This is
-what @code{magit-popup} used by default.  For more alternatives see
-@ref{Display Action Functions,,,elisp,}.
+Another useful FUNCTION is `display-buffer-below-selected', which
+is what `magit-popup' used by default.  For more alternatives see
+@ref{Display Action Functions,,,elisp,} and @ref{Buffer Display Action 
Alists,,,elisp,}.
+
+Note that the buffer that was current before the transient buffer
+is shown should remain the current buffer.  Many suffix commands
+act on the thing at point, if appropriate, and if the transient
+buffer became the current buffer, then that would change what is
+at point.  To that effect @code{inhibit-same-window} ensures that the
+selected window is not used to show the transient buffer.
 
 It may be possible to display the window in another frame, but
 whether that works in practice depends on the window-manager.
 If the window manager selects the new window (Emacs frame),
-then it doesn't work.
+then that unfortunately changes which buffer is current.
 
-If you change the value of this option, then you might also want
-to change the value of @code{transient-mode-line-format}.
+If you change the value of this option, then you might also
+want to change the value of @code{transient-mode-line-format}.
 @end defopt
 
 @defopt transient-mode-line-format
diff --git a/lisp/transient.el b/lisp/transient.el
index abae5b7..6b4fc45 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -148,34 +148,46 @@ features are available:
 (defcustom transient-display-buffer-action
   '(display-buffer-in-side-window
     (side . bottom)
-    (inhibit-same-window . t))
+    (dedicated . t)
+    (inhibit-same-window . t)
+    (window-parameters (no-other-window . t)))
   "The action used to display the transient popup buffer.
 
 The transient popup buffer is displayed in a window using
 
-  \(display-buffer buf transient-display-buffer-action)
+  (display-buffer BUFFER transient-display-buffer-action)
 
 The value of this option has the form (FUNCTION . ALIST),
 where FUNCTION is a function or a list of functions.  Each such
-function should accept two arguments: a buffer to display and
-an alist of the same form as ALIST.  See `display-buffer' for
-details.
+function should accept two arguments: a buffer to display and an
+alist of the same form as ALIST.  See info node `(elisp)Choosing
+Window' for details.
 
 The default is:
 
   (display-buffer-in-side-window
     (side . bottom)
-    (inhibit-same-window . t))
+    (dedicated . t)
+    (inhibit-same-window . t)
+    (window-parameters (no-other-window . t)))
 
 This displays the window at the bottom of the selected frame.
-Another useful value is (display-buffer-below-selected).  This
-is what `magit-popup' used by default.  For more alternatives
-see info node `(elisp)Display Action Functions'.
+Another useful FUNCTION is `display-buffer-below-selected', which
+is what `magit-popup' used by default.  For more alternatives see
+info node `(elisp)Display Action Functions' and info node
+`(elisp)Buffer Display Action Alists'.
+
+Note that the buffer that was current before the transient buffer
+is shown should remain the current buffer.  Many suffix commands
+act on the thing at point, if appropriate, and if the transient
+buffer became the current buffer, then that would change what is
+at point.  To that effect `inhibit-same-window' ensures that the
+selected window is not used to show the transient buffer.
 
 It may be possible to display the window in another frame, but
 whether that works in practice depends on the window-manager.
 If the window manager selects the new window (Emacs frame),
-then it doesn't work.
+then that unfortunately changes which buffer is current.
 
 If you change the value of this option, then you might also
 want to change the value of `transient-mode-line-format'."
@@ -1954,8 +1966,10 @@ value.  Otherwise return CHILDREN as is."
 (defun transient--delete-window ()
   (when (window-live-p transient--window)
     (let ((buf (window-buffer transient--window)))
-      (with-demoted-errors "Error while exiting transient: %S"
-        (delete-window transient--window))
+      ;; Only delete the window if it never showed another buffer.
+      (unless (eq (car (window-parameter transient--window 'quit-restore)) 
'other)
+        (with-demoted-errors "Error while exiting transient: %S"
+          (delete-window transient--window)))
       (kill-buffer buf))))
 
 (defun transient--export ()
@@ -2871,17 +2885,11 @@ have a history of their own.")
   (setq transient--showp t)
   (let ((buf (get-buffer-create transient--buffer-name))
         (focus nil))
-    (unless (window-live-p transient--window)
-      (setq transient--window
-            (display-buffer buf transient-display-buffer-action)))
-    (with-selected-window transient--window
+    (with-current-buffer buf
       (when transient-enable-popup-navigation
         (setq focus (or (button-get (point) 'command)
                         (transient--heading-at-point))))
       (erase-buffer)
-      (set-window-hscroll transient--window 0)
-      (set-window-dedicated-p transient--window t)
-      (set-window-parameter transient--window 'no-other-window t)
       (setq window-size-fixed t)
       (when (bound-and-true-p tab-line-format)
         (setq tab-line-format nil))
@@ -2908,14 +2916,26 @@ have a history of their own.")
                  'transient-separator)))
           (insert (propertize "__" 'face face 'display '(space :height (1))))
           (insert (propertize "\n" 'face face 'line-height t))))
-      (let ((window-resize-pixelwise t)
-            (window-size-fixed nil))
-        (fit-window-to-buffer nil nil 1))
       (goto-char (point-min))
       (when transient-force-fixed-pitch
         (transient--force-fixed-pitch))
       (when transient-enable-popup-navigation
-        (transient--goto-button focus)))))
+        (transient--goto-button focus)))
+    (unless (window-live-p transient--window)
+      (setq transient--window
+            (display-buffer buf transient-display-buffer-action)))
+    (when (window-live-p transient--window)
+      (with-selected-window transient--window
+        (magit--fit-window-to-buffer transient--window)))))
+
+(defun magit--fit-window-to-buffer (window)
+  (let ((window-resize-pixelwise t)
+        (window-size-fixed nil))
+    (if (eq (car (window-parameter window 'quit-restore)) 'other)
+        ;; Grow but never shrink window that previously displayed
+        ;; another buffer and is going to display that again.
+        (fit-window-to-buffer window nil (window-height window))
+      (fit-window-to-buffer window nil 1))))
 
 (defun transient--insert-groups ()
   (let ((groups (cl-mapcan (lambda (group)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]