From: martin rudalics <rudalics@gmx.at>
To: pranshu sharma <pranshusharma366@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Add function to rotate/transpose all windows
Date: Thu, 26 Sep 2024 16:10:48 +0200 [thread overview]
Message-ID: <9005cccc-7545-4257-b2c0-885a13d3bde2@gmx.at> (raw)
In-Reply-To: <877cb09ln4.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 759 bytes --]
>>From what I understand, the main problems are happening when destroying
> and recreating the window arragnment. How about adding a function that
> toggles or changes the window arrangment non recursivly, which will deal
> with all the backend details, and the main rotate function can just
> recursivly call that on all windows.
I attach a function 'resurrect-window' that rotate/transpose/flip
functions can call to resurrect the previous windows after having
deleted them. Tested with:
(let ((dead (split-window nil nil t)))
(set-window-buffer dead "*Messages*")
(message "%s" (next-window))
(sit-for 2)
(delete-window dead)
(let ((live (split-window)))
(resurrect-window dead live)
(message "%s" (next-window))))
martin
[-- Attachment #2: resurrect.diff --]
[-- Type: text/x-patch, Size: 5812 bytes --]
diff --git a/src/window.c b/src/window.c
index 34968ac824f..312619737f3 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5368,10 +5368,14 @@ DEFUN ("delete-window-internal", Fdelete_window_internal, Sdelete_window_interna
}
else
{
+ w->del_pointm = marker_position (w->pointm);
+ w->del_start = marker_position (w->start);
+
unshow_buffer (w);
unchain_marker (XMARKER (w->pointm));
unchain_marker (XMARKER (w->old_pointm));
unchain_marker (XMARKER (w->start));
+ wset_old_buffer (w, w->contents);
wset_buffer (w, Qnil);
/* Add WINDOW to table of dead windows so when killing a buffer
WINDOW mentions, all references to that buffer can be removed
@@ -5437,6 +5441,97 @@ DEFUN ("delete-window-internal", Fdelete_window_internal, Sdelete_window_interna
return Qnil;
}
+
+
+DEFUN ("resurrect-window", Fresurrect_window, Sresurrect_window, 2, 2, 0,
+ doc: /* Resurrect dead window DEAD in lieu of live window LIVE.
+DEAD must denote a dead window that was a live window before it was
+deleted. LIVE must denote a live window. Put the window object of DEAD
+in the place of LIVE such that the resulting window inherits LIVE's
+geometric properties and its position within the window tree while all
+other properties including the buffer and its positions, decorations and
+parameters are inherited from DEAD.
+
+DEAD must have been on the same frame as LIVE and its old buffer must be
+still live. If LIVE was selected or its frame's selected window, select
+DEAD or make it its frame's selected window instead. */)
+ (Lisp_Object dead, Lisp_Object live)
+{
+ struct window *l = decode_live_window (live);
+ struct window *d = decode_any_window (dead);
+ Lisp_Object frame = WINDOW_FRAME (l);
+ struct frame *f = XFRAME (frame);
+ Lisp_Object tem;
+ bool selected = EQ (live, selected_window);
+ bool frame_selected = EQ (live, f->selected_window);
+
+ if (!NILP (d->contents))
+ error ("Attempt to resurrect undead window");
+ else if (!BUFFERP (d->old_buffer))
+ error ("Dead window has no old buffer");
+ else if (!BUFFER_LIVE_P (XBUFFER (d->old_buffer)))
+ error ("Dead window's old buffer is dead");
+ else if (!EQ (l->frame, d->frame))
+ error ("Live and dead widows must be on same frame");
+
+ block_input ();
+
+ /* Copy links and geometry of LIVE into DEAD. */
+ memcpy (&d->next, &l->next,
+ offsetof (struct window, contents)
+ - offsetof (struct window, next));
+ memcpy (&d->pixel_left, &l->pixel_left,
+ offsetof (struct window, hscroll)
+ - offsetof (struct window, pixel_left));
+
+ /* Replace LIVE in window tree with DEAD. */
+ if (!NILP (d->next))
+ wset_prev (XWINDOW (d->next), dead);
+
+ if (!NILP (d->prev))
+ wset_next (XWINDOW (d->prev), dead);
+
+ tem = d->parent;
+ if (!NILP (tem) && EQ (XWINDOW (tem)->contents, live))
+ wset_combination (XWINDOW (tem), XWINDOW (tem)->horizontal, dead);
+
+ /* Get DEAD back its old buffer and markers. */
+ wset_buffer (d, d->old_buffer);
+ Fset_marker (d->start, make_fixnum (d->del_start), d->contents);
+ Fset_marker (d->pointm, make_fixnum (d->del_pointm), d->contents);
+
+ /* Deal with LIVE. */
+ wset_next (l, Qnil); /* Don't delete l->next too. */
+ free_window_matrices (l);
+ l->del_pointm = marker_position (l->pointm);
+ l->del_start = marker_position (l->start);
+ unshow_buffer (l);
+ unchain_marker (XMARKER (l->pointm));
+ unchain_marker (XMARKER (l->old_pointm));
+ unchain_marker (XMARKER (l->start));
+ wset_old_buffer (l, l->contents);
+ wset_buffer (l, Qnil);
+ /* Add WINDOW to table of dead windows so when killing a buffer WINDOW
+ mentions, all references to that buffer can be removed and the
+ buffer be collected. */
+ Fputhash (make_fixnum (l->sequence_number),
+ live, window_dead_windows_table);
+
+ /* Selection status. */
+ if (selected)
+ Fselect_window (dead, Qt);
+ else if (frame_selected)
+ fset_selected_window (f, dead);
+
+ /* Tell redisplay. */
+ fset_redisplay (f);
+ Vwindow_list = Qnil;
+ adjust_frame_glyphs (f);
+ unblock_input ();
+ FRAME_WINDOW_CHANGE (f) = true;
+
+ return Qnil;
+}
\f
/***********************************************************************
Resizing Mini-Windows
@@ -7712,6 +7807,9 @@ delete_all_child_windows (Lisp_Object window)
}
else if (BUFFERP (w->contents))
{
+ w->del_pointm = marker_position (w->pointm);
+ w->del_start = marker_position (w->start);
+
unshow_buffer (w);
unchain_marker (XMARKER (w->pointm));
unchain_marker (XMARKER (w->old_pointm));
@@ -7720,6 +7818,7 @@ delete_all_child_windows (Lisp_Object window)
only, we use this slot to save the buffer for the sake of
possible resurrection in Fset_window_configuration. */
wset_combination_limit (w, w->contents);
+ wset_old_buffer (w, w->contents);
wset_buffer (w, Qnil);
/* Add WINDOW to table of dead windows so when killing a buffer
WINDOW mentions, all references to that buffer can be removed
@@ -9146,6 +9245,7 @@ syms_of_window (void)
defsubr (&Sget_buffer_window);
defsubr (&Sdelete_other_windows_internal);
defsubr (&Sdelete_window_internal);
+ defsubr (&Sresurrect_window);
defsubr (&Sresize_mini_window_internal);
defsubr (&Sset_window_buffer);
defsubr (&Srun_window_configuration_change_hook);
diff --git a/src/window.h b/src/window.h
index 335e0a3453e..41ee7f6dc18 100644
--- a/src/window.h
+++ b/src/window.h
@@ -264,6 +264,10 @@ #define WINDOW_H_INCLUDED
int total_cols;
int total_lines;
+ /* Positions of pointm and start when window was deleted. */
+ ptrdiff_t del_pointm;
+ ptrdiff_t del_start;
+
/* Number of columns display within the window is scrolled to the left. */
ptrdiff_t hscroll;
next prev parent reply other threads:[~2024-09-26 14:10 UTC|newest]
Thread overview: 144+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-24 13:45 Add function to rotate/transpose all windows pranshu sharma
2024-09-24 13:53 ` Eli Zaretskii
2024-09-25 8:05 ` martin rudalics
2024-09-25 8:34 ` pranshu sharma
2024-09-25 9:31 ` martin rudalics
2024-09-25 10:50 ` pranshu sharma
2024-09-25 13:53 ` martin rudalics
2024-09-25 15:31 ` pranshu sharma
2024-09-26 14:10 ` martin rudalics [this message]
2024-09-26 14:22 ` Eli Zaretskii
2024-09-27 17:29 ` martin rudalics
2024-09-28 7:52 ` pranshu sharma
2024-09-28 9:26 ` martin rudalics
2024-09-28 10:53 ` pranshu sharma
2024-09-28 14:48 ` martin rudalics
2024-09-29 7:36 ` pranshu sharma
2024-09-29 8:40 ` martin rudalics
2024-09-29 9:23 ` pranshu sharma
2024-09-29 14:48 ` martin rudalics
2024-09-30 6:29 ` pranshu sharma
2024-09-30 8:57 ` martin rudalics
2024-10-01 9:17 ` pranshu sharma
2024-10-02 9:04 ` martin rudalics
2024-10-03 7:06 ` pranshu sharma
2024-10-03 8:17 ` martin rudalics
2024-10-03 10:09 ` pranshu sharma
2024-10-03 14:18 ` martin rudalics
2024-10-04 5:50 ` pranshu sharma
2024-10-04 8:08 ` martin rudalics
2024-10-04 15:10 ` pranshu sharma
2024-10-05 14:43 ` martin rudalics
2024-10-06 2:54 ` pranshu sharma
2024-10-06 15:02 ` martin rudalics
2024-10-06 15:52 ` pranshu sharma
2024-10-07 8:33 ` martin rudalics
2024-10-07 9:42 ` pranshu sharma
2024-10-03 15:12 ` Eli Zaretskii
2024-10-08 18:35 ` Juri Linkov
2024-10-09 6:59 ` pranshu sharma
2024-10-09 16:21 ` Juri Linkov
2024-10-10 11:49 ` pranshu sharma
2024-10-10 16:57 ` Juri Linkov
2024-10-13 5:43 ` pranshu sharma
2024-10-13 8:17 ` martin rudalics
2024-10-14 17:36 ` Juri Linkov
2024-10-15 8:34 ` pranshu sharma
2024-10-15 16:16 ` Juri Linkov
2024-10-18 14:52 ` pranshu sharma
2024-10-18 17:48 ` martin rudalics
2024-10-18 18:37 ` Eli Zaretskii
2024-10-19 1:45 ` pranshu sharma
2024-10-19 6:45 ` Eli Zaretskii
2024-10-19 18:19 ` Juri Linkov
2024-10-19 8:33 ` martin rudalics
2024-10-20 8:19 ` martin rudalics
2024-10-20 14:11 ` Pranshu Sharma
2024-10-20 17:37 ` martin rudalics
2024-10-21 5:54 ` Pranshu Sharma
2024-10-21 8:14 ` martin rudalics
2024-10-21 9:23 ` martin rudalics
2024-10-21 13:37 ` Pranshu Sharma
2024-10-22 18:12 ` martin rudalics
2024-10-24 14:38 ` Pranshu Sharma
2024-10-24 18:39 ` martin rudalics
2024-10-25 14:24 ` Pranshu Sharma
2024-10-25 17:09 ` martin rudalics
2024-10-26 9:14 ` Pranshu Sharma
2024-10-27 8:23 ` martin rudalics
2024-11-02 14:06 ` Pranshu Sharma
2024-11-05 18:01 ` martin rudalics
2024-11-08 9:23 ` Pranshu Sharma
2024-11-08 10:06 ` Pranshu Sharma
2024-11-08 15:52 ` martin rudalics
2024-11-09 2:14 ` Pranshu Sharma
2024-11-09 8:48 ` martin rudalics
2024-11-08 15:52 ` martin rudalics
2024-11-09 2:09 ` Pranshu Sharma
2024-11-09 8:48 ` martin rudalics
2024-11-09 10:55 ` Pranshu Sharma
2024-11-09 18:06 ` martin rudalics
2024-11-10 10:09 ` Pranshu Sharma
2024-11-10 16:36 ` martin rudalics
2024-11-11 14:47 ` Pranshu Sharma
2024-11-11 16:55 ` martin rudalics
2024-11-12 13:50 ` Pranshu Sharma
2024-11-12 17:46 ` martin rudalics
2024-11-16 13:36 ` Pranshu Sharma
2024-11-16 16:54 ` martin rudalics
2024-11-17 2:45 ` Pranshu Sharma
2024-11-17 10:22 ` martin rudalics
2024-11-17 15:03 ` Pranshu Sharma
2024-11-17 16:38 ` martin rudalics
2024-11-18 0:37 ` Pranshu Sharma
2024-11-18 8:55 ` martin rudalics
2024-11-19 9:34 ` Pranshu Sharma
2024-11-19 17:48 ` martin rudalics
2024-11-21 14:04 ` Pranshu Sharma
2024-11-21 17:54 ` martin rudalics
2024-11-24 13:53 ` Pranshu Sharma
2024-11-26 9:49 ` martin rudalics
2024-11-26 14:14 ` Pranshu Sharma
2024-11-27 8:29 ` Pranshu Sharma
2024-11-27 9:18 ` martin rudalics
2024-11-27 14:37 ` Pranshu Sharma
2024-11-27 17:42 ` martin rudalics
2024-11-28 2:43 ` Pranshu Sharma
2024-11-28 9:28 ` martin rudalics
2024-11-28 15:18 ` Pranshu Sharma
2024-11-30 10:07 ` martin rudalics
2024-11-30 17:41 ` Juri Linkov
2024-11-30 19:01 ` martin rudalics
2024-12-01 4:13 ` Pranshu Sharma
2024-12-03 7:30 ` Juri Linkov
2024-12-03 8:25 ` martin rudalics
2024-12-01 6:41 ` Pranshu Sharma
2024-12-01 17:20 ` martin rudalics
2024-12-02 8:06 ` Pranshu Sharma
2024-12-03 8:23 ` martin rudalics
2024-12-04 15:20 ` Pranshu Sharma
2024-12-04 17:56 ` martin rudalics
2024-12-04 19:12 ` Juri Linkov
2024-12-05 14:16 ` Pranshu Sharma
2024-12-05 17:48 ` Juri Linkov
2024-12-06 4:51 ` Pranshu Sharma
2024-12-06 7:29 ` Juri Linkov
2024-12-05 14:23 ` Pranshu Sharma
2024-12-05 15:17 ` Pranshu Sharma
2024-10-14 17:32 ` Juri Linkov
2024-09-28 7:58 ` pranshu sharma
2024-09-28 8:18 ` Eli Zaretskii
2024-09-28 9:40 ` martin rudalics
2024-09-28 11:35 ` Eli Zaretskii
2024-09-28 14:58 ` martin rudalics
2024-09-28 15:28 ` Eli Zaretskii
2024-10-07 8:33 ` martin rudalics
2024-09-28 13:22 ` pranshu sharma
2024-09-28 14:21 ` Eli Zaretskii
2024-09-28 14:49 ` martin rudalics
2024-09-27 10:06 ` pranshu sharma
2024-09-27 17:29 ` martin rudalics
2024-09-24 17:40 ` Petteri Hintsanen
2024-09-24 19:34 ` Charles Choi
2024-09-25 2:00 ` Emanuel Berg
2024-09-25 7:00 ` pranshu sharma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9005cccc-7545-4257-b2c0-885a13d3bde2@gmx.at \
--to=rudalics@gmx.at \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=pranshusharma366@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).