0

I saved a buffer name in a variable WORKING_BUFFER.

I want to perform, interactively, some operation on that WORKING_BUFFER even if it isn't visible/selected.

I tried:

(with-selected-window (get-buffer-window WORKING_BUFFER))

but I get

Wrong type argument: window-live-p, nil

if the buffer WORKING_BUFFER is not currently displayed.

How can I force the use of the WORKING_BUFFER buffer window (ho can I "call" it?), interactively and restore, once finished, the previous windows settings (the windows displayed on the frame before the operation)? (for the second part I guess save-window-excursion)

Edit. I'll try to better explain the purpose of my request.

I create scripts to assist users in performing various operations on the WORKING_BUFFER. Occasionally, I use log buffers to provide users with explanations of the purpose of certain operations. In some cases, I include clickable text within these log buffers that allow users to execute functions that manipulate the WORKING_BUFFER "interactively" (mostly "query-replace*"). Additionally, there may be instances where I need the log buffers to occupy the entire frame, thus rendering the WORKING_BUFFER invisible.

May be something like;

(save-window-excursion
  (with-current-buffer WORKING_BUFFER
    ;; perform interactive operations on WORKING_BUFFER here
    ))

but WORKING_BUFFER should be visible and selected while the interactive operations are performed.

Gabriele Nicolardi
  • 1,199
  • 8
  • 17
  • 1
    IIUC, you want to save the window configuration, pop up a window displaying the buffer, do whatever you want to do, maybe save the buffer and finally restore the window configuration. Since the interactive part is a priori unknown, you'll have to do the before and after pieces separately and invoke them explicitly. Is that satisfactory or are you looking for something else? If something else, what exactly? – NickD Apr 24 '23 at 02:42
  • `save-window-excursion` sounds perfect except that you don't know beforehand what `body` you are going to execute, since you are going to be doing it interactively. Maybe `recursive-edit` can be used? – NickD Apr 24 '23 at 02:46
  • @NickD I need to pop up a window displaying the buffer, ask user to make some replacements (`query-replace*`) and restore window-configuration and selected window. – Gabriele Nicolardi Apr 24 '23 at 07:58
  • Gabrielle: Is that different in any practical sense to the following? If there is no window currently displaying buffer B then (1) remember that fact, and (2) display B in the current window. When the user indicates that they have finished with B then, if (1) applied, bury buffer B to restore what was previously in its window. – phils Apr 24 '23 at 10:33
  • In other words, unless you are going to be doing more with window configurations than "maybe display a buffer, and later on hide it again" I can't see any reason for you to explicitly deal with window configurations at all. – phils Apr 24 '23 at 10:35
  • @phils honestly I'm exploring all the possibilities. I opened this issue to understand if there are already any best practices for these cases. – Gabriele Nicolardi Apr 24 '23 at 12:24

0 Answers0