From: martin rudalics <rudalics@gmx.at>
To: Eli Zaretskii <eliz@gnu.org>
Cc: enometh@meer.net, 39977@debbugs.gnu.org
Subject: bug#39977: 28.0.50; Unhelpful stack trace
Date: Fri, 3 Apr 2020 18:32:18 +0200 [thread overview]
Message-ID: <e0a053fb-7752-3d55-ef8c-d05b44d2fdc3@gmx.at> (raw)
In-Reply-To: <8f21c5ce-49a1-1865-6ea3-fe5120c1cfc5@gmx.at>
[-- Attachment #1: Type: text/plain, Size: 189 bytes --]
> Attached find a patch which should solve the more grave problems caused
> by a function deleting the previously selected frame or window.
Fixing a few more things as attached.
martin
[-- Attachment #2: restore_selected_window.diff --]
[-- Type: text/x-patch, Size: 6145 bytes --]
diff --git a/src/xdisp.c b/src/xdisp.c
index a4de2698ca..82556ca280 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -12149,12 +12149,12 @@ unwind_format_mode_line (Lisp_Object vector)
mode_line_string_face_prop = AREF (vector, 5);
/* Select window before buffer, since it may change the buffer. */
- if (!NILP (old_window))
+ if (WINDOW_LIVE_P (old_window))
{
/* If the operation that we are unwinding had selected a window
on a different frame, reset its frame-selected-window. For a
text terminal, reset its top-frame if necessary. */
- if (!NILP (target_frame_window))
+ if (WINDOW_LIVE_P (target_frame_window))
{
Lisp_Object frame
= WINDOW_FRAME (XWINDOW (target_frame_window));
@@ -12171,7 +12171,7 @@ unwind_format_mode_line (Lisp_Object vector)
/* Restore point of target_frame_window's buffer (Bug#32777).
But do this only after old_window has been reselected to
avoid that the window point of target_frame_window moves. */
- if (!NILP (target_frame_window))
+ if (WINDOW_LIVE_P (target_frame_window))
{
Lisp_Object buffer = AREF (vector, 10);
@@ -12592,23 +12591,68 @@ update_menu_bar (struct frame *f, bool save_match_data, bool hooks_run)
Tab-bars
***********************************************************************/
-#ifdef HAVE_WINDOW_SYSTEM
-
-/* Select `frame' temporarily without running all the code in
- do_switch_frame.
- FIXME: Maybe do_switch_frame should be trimmed down similarly
- when `norecord' is set. */
+/* Restore WINDOW as the selected window and its frame as the selected
+ frame. If WINDOW is dead but the selected frame is live, make the
+ latter's selected window the selected window. If both, WINDOW and
+ the selected frame, are dead, assign selected frame and window from
+ some arbitrary live frame. Abort if no such frame can be found. */
static void
-fast_set_selected_frame (Lisp_Object frame)
+restore_selected_window (Lisp_Object window)
{
- if (!EQ (selected_frame, frame))
+ if (WINDOW_LIVE_P (window))
+ /* If WINDOW is live, make it the selected window and its frame's
+ selected window and set the selected frame to its frame. */
+ {
+ selected_window = window;
+ selected_frame = XWINDOW (window)->frame;
+ FRAME_SELECTED_WINDOW (XFRAME (selected_frame)) = window;
+ }
+ else if (FRAMEP (selected_frame) && FRAME_LIVE_P (XFRAME (selected_frame)))
+ /* If WINDOW is dead but the selected frame is still live, make the
+ latter's selected window the selected one. */
+ selected_window = FRAME_SELECTED_WINDOW (XFRAME (selected_frame));
+ else
+ /* If WINDOW and the selected frame are dead, choose some live,
+ non-child and non-tooltip frame as the new selected frame and
+ make its selected window the selected window. */
{
- selected_frame = frame;
- selected_window = XFRAME (frame)->selected_window;
+ Lisp_Object tail;
+ Lisp_Object frame UNINIT;
+
+ FOR_EACH_FRAME (tail, frame)
+ {
+ struct frame *f = XFRAME (frame);
+
+ if (!FRAME_PARENT_FRAME (f) && !FRAME_TOOLTIP_P (f))
+ {
+ selected_frame = frame;
+ selected_window = FRAME_SELECTED_WINDOW (f);
+
+ return;
+ }
+ }
+
+ /* Abort if we cannot find a live frame. */
+ emacs_abort ();
}
}
-#endif /* HAVE_WINDOW_SYSTEM */
+/* Restore WINDOW, if live, as its frame's selected window. */
+static void
+restore_frame_selected_window (Lisp_Object window)
+{
+ if (WINDOW_LIVE_P (window))
+ /* If WINDOW is live, make it its frame's selected window. If that
+ frame is the selected frame, make WINDOW the selected window as
+ well. */
+ {
+ Lisp_Object frame = XWINDOW (window)->frame;
+
+ FRAME_SELECTED_WINDOW (XFRAME (frame)) = window;
+ if (EQ (frame, selected_frame))
+ selected_window = window;
+ }
+}
/* Update the tab-bar item list for frame F. This has to be done
before we start to fill in any display lines. Called from
@@ -12681,9 +12725,10 @@ update_tab_bar (struct frame *f, bool save_match_data)
XFRAME (selected_frame)->selected_window));
#ifdef HAVE_WINDOW_SYSTEM
Lisp_Object frame;
- record_unwind_protect (fast_set_selected_frame, selected_frame);
+ record_unwind_protect (restore_selected_window, selected_window);
XSETFRAME (frame, f);
- fast_set_selected_frame (frame);
+ selected_frame = frame;
+ selected_window = FRAME_SELECTED_WINDOW (f);
#endif
/* Build desired tab-bar items from keymaps. */
@@ -13625,9 +13670,10 @@ update_tool_bar (struct frame *f, bool save_match_data)
/* Since we only explicitly preserve selected_frame,
check that selected_window would be redundant. */
XFRAME (selected_frame)->selected_window));
- record_unwind_protect (fast_set_selected_frame, selected_frame);
+ record_unwind_protect (restore_selected_window, selected_window);
XSETFRAME (frame, f);
- fast_set_selected_frame (frame);
+ selected_frame = frame;
+ selected_window = FRAME_SELECTED_WINDOW (f);
/* Build desired tool-bar items from keymaps. */
new_tool_bar
@@ -24939,11 +24985,14 @@ redisplay_mode_lines (Lisp_Object window, bool force)
display_mode_lines (struct window *w)
{
Lisp_Object old_selected_window = selected_window;
- Lisp_Object old_selected_frame = selected_frame;
Lisp_Object new_frame = w->frame;
- Lisp_Object old_frame_selected_window = XFRAME (new_frame)->selected_window;
+ ptrdiff_t count = SPECPDL_INDEX ();
int n = 0;
+ record_unwind_protect (restore_selected_window, selected_window);
+ record_unwind_protect
+ (restore_frame_selected_window, XFRAME (new_frame)->selected_window);
+
if (window_wants_mode_line (w))
{
Lisp_Object window;
@@ -25009,9 +25058,8 @@ display_mode_lines (struct window *w)
++n;
}
- XFRAME (new_frame)->selected_window = old_frame_selected_window;
- selected_frame = old_selected_frame;
- selected_window = old_selected_window;
+ unbind_to (count, Qnil);
+
if (n > 0)
w->must_be_updated_p = true;
return n;
next prev parent reply other threads:[~2020-04-03 16:32 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-07 17:43 bug#39977: 28.0.50; Unhelpful stack trace Madhu
2020-03-07 18:50 ` Eli Zaretskii
2020-03-13 9:55 ` Eli Zaretskii
2020-03-13 16:28 ` martin rudalics
2020-03-13 19:43 ` Eli Zaretskii
2020-03-14 8:48 ` martin rudalics
2020-03-14 10:10 ` Eli Zaretskii
2020-03-14 10:37 ` martin rudalics
2020-03-14 18:55 ` martin rudalics
2020-03-14 20:09 ` Eli Zaretskii
2020-03-15 17:49 ` martin rudalics
2020-03-15 18:41 ` Eli Zaretskii
2020-03-16 9:24 ` martin rudalics
2020-03-16 15:33 ` Eli Zaretskii
2020-03-17 9:38 ` martin rudalics
2020-03-17 15:51 ` Eli Zaretskii
2020-03-17 17:31 ` martin rudalics
2020-03-17 17:45 ` Eli Zaretskii
2020-03-17 18:39 ` martin rudalics
2020-03-17 19:41 ` Eli Zaretskii
2020-03-18 9:12 ` martin rudalics
2020-03-18 14:53 ` Eli Zaretskii
2020-03-18 18:48 ` martin rudalics
2020-03-18 19:36 ` Eli Zaretskii
2020-03-19 8:55 ` martin rudalics
2020-03-19 14:33 ` Eli Zaretskii
2020-03-21 9:32 ` martin rudalics
2020-03-21 13:15 ` Eli Zaretskii
2020-03-22 18:20 ` martin rudalics
2020-03-23 14:48 ` Eli Zaretskii
2020-03-24 9:45 ` martin rudalics
2020-03-28 8:23 ` Eli Zaretskii
2020-03-28 18:38 ` martin rudalics
2020-04-03 16:32 ` martin rudalics [this message]
2020-04-10 11:51 ` Madhu
2020-09-30 15:06 ` Lars Ingebrigtsen
2020-09-30 15:31 ` Eli Zaretskii
2020-09-30 17:29 ` martin rudalics
2020-10-01 0:01 ` Lars Ingebrigtsen
2020-10-01 4:37 ` Madhu
2020-03-19 3:48 ` Madhu
2020-03-16 2:42 ` Madhu
2020-03-16 9:25 ` martin rudalics
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=e0a053fb-7752-3d55-ef8c-d05b44d2fdc3@gmx.at \
--to=rudalics@gmx.at \
--cc=39977@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=enometh@meer.net \
/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).