From b1b4f0020ed29a99a1bdbd4e1e18a2b2c3783856 Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Tue, 28 Jan 2025 16:59:45 +0100 Subject: [PATCH] New variable 'expose-hidden-buffer' (Bug#75828) * src/frame.c (make_frame): Handle 'expose-hidden-buffer'. (expose-hidden-buffer): New variable to handle hidden buffers. * src/buffer.c (Fother_buffer): Mention that it does not return a hidden buffer. * lisp/frame.el (make-frame): In doc-string describe handling of hidden buffers. * doc/lispref/frames.texi (Creating Frames): Explain handling of hidden buffers in description of 'make-frame'. (cherry picked from commit 7f01dd8906cbc8839ffecc55cfa7ff789f3fa298) --- doc/lispref/frames.texi | 7 +++++++ lisp/frame.el | 8 +++++++- src/buffer.c | 3 ++- src/frame.c | 19 +++++++++++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index c71b977550e..52af34389c5 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi @@ -162,6 +162,13 @@ This function itself does not make the new frame the selected frame. @xref{Input Focus}. The previously selected frame remains selected. On graphical terminals, however, the window system may select the new frame for its own reasons. + +By default this function does not display the current buffer in the new +frame if the buffer is hidden, that is, if its name starts with a space. +In this case it will show another buffer - one that could be returned by +the function @code{other-buffer} (@pxref{Buffer List}) - instead. +However, if the variable @code{expose-hidden-buffer} is non-@code{nil}, +this function will display the current buffer even if it is hidden. @end deffn @defvar before-make-frame-hook diff --git a/lisp/frame.el b/lisp/frame.el index eefa6411961..dc6628b2dd8 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -949,7 +949,13 @@ guess the window-system from the display. On graphical displays, this function does not itself make the new frame the selected frame. However, the window system may select -the new frame according to its own rules." +the new frame according to its own rules. + +By default do not display the current buffer in the new frame if the +buffer is hidden, that is, if the buffer's name starts with a space. +Display another buffer - one that could be returned by `other-buffer' - +instead. However, if `expose-hidden-buffer' is non-nil, display the +current buffer even if it is hidden." (interactive) (let* ((display (cdr (assq 'display parameters))) (w (cond diff --git a/src/buffer.c b/src/buffer.c index 1b9092b107b..ed2f14ea9c0 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1729,7 +1729,8 @@ Buffers not visible in windows are preferred to visible buffers, unless optional second argument VISIBLE-OK is non-nil. Ignore the argument BUFFER unless it denotes a live buffer. If the optional third argument FRAME specifies a live frame, then use that frame's buffer list instead -of the selected frame's buffer list. +of the selected frame's buffer list. Do not return a hidden buffer - a +buffer whose name starts with a space. The buffer is found by scanning the selected or specified frame's buffer list first, followed by the list of all buffers. If no other buffer diff --git a/src/frame.c b/src/frame.c index 29f270e0bc3..473254175a2 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1094,8 +1094,9 @@ make_frame (bool mini_p) { Lisp_Object buf = Fcurrent_buffer (); - /* If current buffer is hidden, try to find another one. */ - if (BUFFER_HIDDEN_P (XBUFFER (buf))) + /* If the current buffer is hidden and shall not be exposed, try to find + another one. */ + if (BUFFER_HIDDEN_P (XBUFFER (buf)) && NILP (expose_hidden_buffer)) buf = other_buffer_safely (buf); /* Use set_window_buffer, not Fset_window_buffer, and don't let @@ -7164,6 +7165,20 @@ making the child frame unresponsive to user actions, the default is to iconify the top level frame instead. */); iconify_child_frame = Qiconify_top_level; + DEFVAR_LISP ("expose-hidden-buffer", expose_hidden_buffer, + doc: /* Non-nil means to make a hidden buffer more visible. +A buffer is considered "hidden" if its name starts with a space. By +default, many functions disregard hidden buffers. In particular, +`make-frame' does not show the current buffer in the new frame's +selected window if that buffer is hidden. Rather, `make-frame' will +show a buffer that is not hidden instead. + +If this variable is non-nil, it will override the default behavior and +allow `make-frame' to show the current buffer even if its hidden. */); + expose_hidden_buffer = Qnil; + DEFSYM (Qexpose_hidden_buffer, "expose-hidden-buffer"); + Fmake_variable_buffer_local (Qexpose_hidden_buffer); + DEFVAR_LISP ("frame-internal-parameters", frame_internal_parameters, doc: /* Frame parameters specific to every frame. */); #ifdef HAVE_X_WINDOWS -- 2.39.5