Subject: Re: bug#33458: 27.0.50; dired loses position when reverted from outside place

From: martin rudalics <[email-masked]>
Date: Sun, 23 Dec 2018 20:06:51 +0100

> No.  But we can provide a function like 'buffers-in-dead-windows' that
 > takes a configuration (or a list of configurations) as argument and
 > returns a list of dead windows that whould show that buffer if they
 > were restored.

I called it 'buffer-windows-from-configuration'.  Please have a look.

martin
diff --git a/src/window.c b/src/window.c
index 8297022..f6804d7 100644
--- a/src/window.c
+++ b/src/window.c
@@ -7076,6 +7076,40 @@ struct saved_window
 }

+DEFUN ("buffer-windows-from-configuration", Fbuffer_windows_from_configuration,
+       Sbuffer_windows_from_configuration, 2, 2, 0,
+       doc: /* Return list of windows showing BUFFER in CONFIGURATION.
+The return value is a list of triples <window, start, point> for each
+window showing BUFFER in CONFIGURATION.  Window is the window showing
+buffer, start its start position and point its window point.  */)
+     (Lisp_Object buffer, Lisp_Object configuration)
+{
+  register struct save_window_data *data;
+  struct Lisp_Vector *saved_windows;
+  Lisp_Object value = Qnil;
+  struct saved_window *p;
+  ptrdiff_t k;
+
+  CHECK_BUFFER (buffer);
+
+  if (!BUFFER_LIVE_P (XBUFFER (buffer)))
+    error ("Not a live buffer");
+
+  CHECK_WINDOW_CONFIGURATION (configuration);
+
+  data = (struct save_window_data *) XVECTOR (configuration);
+  saved_windows = XVECTOR (data->saved_windows);
+
+  for (k = 0; k < saved_windows->header.size; k++)
+    {
+      p = SAVED_WINDOW_N (saved_windows, k);
+      if (BUFFERP (p->buffer) && EQ (p->buffer, buffer))
+	value = Fcons (list3 (p->window, p->start, p->pointm), value);
+    }
+
+  return value;
+}
+
 /* If WINDOW is an internal window, recursively delete all child windows
    reachable via the next and contents slots of WINDOW.  Otherwise setup
    WINDOW to not show any buffer.  */
@@ -8270,6 +8304,7 @@ this value for parameters without read syntax (like windows or frames).
   defsubr (&Swindow_configuration_p);
   defsubr (&Swindow_configuration_frame);
   defsubr (&Sset_window_configuration);
+  defsubr (&Sbuffer_windows_from_configuration);
   defsubr (&Scurrent_window_configuration);
   defsubr (&Sset_window_margins);
   defsubr (&Swindow_margins);