Subject: Re: bug#48674: Frames and minibuffer bug

From: martin rudalics <[email-masked]>
Date: Sat, 29 May 2021 11:20:58 +0200

> I think the following patch, along the above lines, solves the bug
 > completely.  Could you review it for me, please?

It fixes the bug and the potential use case I mentioned earlier.  But
for this part

   /* If the new frame's selected window is the mini-window, select
      some other window if we don't have an active minibuffer there.  */
   if (MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (f)))
       && !live_minibuffer_p (XWINDOW (FRAME_SELECTED_WINDOW (f))->contents))
     Fselect_window (Fframe_first_window (selected_frame), Qnil);

I would first have to understand why such a minibuffer window should be
OT1H its frame's selected window and OTOH not be active when switching
back to that frame.  As a user I can always do

(select-window (minibuffer-window))

regardless of whether a minibuffer is active.  Switching away from that
window's frame and back to it is problematic in Emacs 27 - no window has
the active cursor.  You apparently fixed this by selecting the frame's
first window when switching back.  Right?

One reason why I ask is because with emacs -Q and the present patch

(setq default-frame-alist '((minibuffer . nil)))

followed by C-x 5 2 and

(select-window (minibuffer-window))

in the new frame violates the assertion on line 548 of window.c

       /* Fselect_frame called us back so we've done all the work already.  */
       eassert (EQ (window, selected_window));

with the backtrace below.

Basically, I would try to avoid that a non-selected frame's selected
window is an inactive minibuffer window.  But I'm not sure how difficult
it is to achieve that.

martin

#0  0x00000000005ac2a7 in terminate_due_to_signal (sig=6, backtrace_limit=2147483647) at ../../src/emacs.c:400
#1  0x00000000006593a5 in die (msg=0x792187 "EQ (window, selected_window)", file=0x791f12 "../../src/window.c", line=548) at ../../src/alloc.c:7451
#2  0x00000000004c8185 in select_window (window=XIL(0x11109dd), norecord=XIL(0), inhibit_point_swap=false) at ../../src/window.c:548
#3  0x00000000004c8315 in Fselect_window (window=XIL(0x11109dd), norecord=XIL(0)) at ../../src/window.c:625
#4  0x000000000069110e in eval_sub (form=XIL(0x1102163)) at ../../src/eval.c:2517
#5  0x000000000068af94 in Fprogn (body=XIL(0)) at ../../src/eval.c:471
#6  0x0000000000690cfc in eval_sub (form=XIL(0x1102123)) at ../../src/eval.c:2467
#7  0x0000000000690661 in Feval (form=XIL(0x1102123), lexical=XIL(0x30)) at ../../src/eval.c:2343
#8  0x0000000000692dc5 in funcall_subr (subr=0xc61600 <Seval>, numargs=2, args=0x7fffffffce80) at ../../src/eval.c:3116
#9  0x000000000069285e in Ffuncall (nargs=3, args=0x7fffffffce78) at ../../src/eval.c:3039
#10 0x00000000006ec8e5 in exec_byte_code (bytestr=XIL(0x7ffff3e1e10c), vector=XIL(0x7ffff3e1ccd5), maxdepth=make_fixnum(18), args_template=make_fixnum(257), nargs=1, args=0x7fffffffd380) at ../../src/bytecode.c:632
#11 0x0000000000693026 in fetch_and_exec_byte_code (fun=XIL(0x7ffff3e1cca5), syms_left=make_fixnum(257), nargs=1, args=0x7fffffffd378) at ../../src/eval.c:3163
#12 0x00000000006934ac in funcall_lambda (fun=XIL(0x7ffff3e1cca5), nargs=1, arg_vector=0x7fffffffd378) at ../../src/eval.c:3244
#13 0x00000000006928b2 in Ffuncall (nargs=2, args=0x7fffffffd370) at ../../src/eval.c:3043
#14 0x00000000006ec8e5 in exec_byte_code (bytestr=XIL(0x7ffff3e1e38c), vector=XIL(0x7ffff3e1cc45), maxdepth=make_fixnum(4), args_template=make_fixnum(257), nargs=1, args=0x7fffffffd978) at ../../src/bytecode.c:632
#15 0x0000000000693026 in fetch_and_exec_byte_code (fun=XIL(0x7ffff3e1cc0d), syms_left=make_fixnum(257), nargs=1, args=0x7fffffffd970) at ../../src/eval.c:3163
#16 0x00000000006934ac in funcall_lambda (fun=XIL(0x7ffff3e1cc0d), nargs=1, arg_vector=0x7fffffffd970) at ../../src/eval.c:3244
#17 0x00000000006928b2 in Ffuncall (nargs=2, args=0x7fffffffd968) at ../../src/eval.c:3043
#18 0x000000000068656e in Ffuncall_interactively (nargs=2, args=0x7fffffffd968) at ../../src/callint.c:260
#19 0x0000000000692c98 in funcall_subr (subr=0xc60e40 <Sfuncall_interactively>, numargs=2, args=0x7fffffffd968) at ../../src/eval.c:3094
#20 0x000000000069285e in Ffuncall (nargs=3, args=0x7fffffffd960) at ../../src/eval.c:3039
#21 0x0000000000688bf4 in Fcall_interactively (function=XIL(0x7ffff3134918), record_flag=XIL(0), keys=XIL(0x7ffff4375585)) at ../../src/callint.c:791
#22 0x0000000000692df1 in funcall_subr (subr=0xc60e80 <Scall_interactively>, numargs=3, args=0x7fffffffdd40) at ../../src/eval.c:3119
#23 0x000000000069285e in Ffuncall (nargs=4, args=0x7fffffffdd38) at ../../src/eval.c:3039
#24 0x00000000006ec8e5 in exec_byte_code (bytestr=XIL(0x7ffff3db0ccc), vector=XIL(0x7ffff3db0935), maxdepth=make_fixnum(13), args_template=make_fixnum(1025), nargs=1, args=0x7fffffffe2b0) at ../../src/bytecode.c:632
#25 0x0000000000693026 in fetch_and_exec_byte_code (fun=XIL(0x7ffff3db0905), syms_left=make_fixnum(1025), nargs=1, args=0x7fffffffe2a8) at ../../src/eval.c:3163
#26 0x00000000006934ac in funcall_lambda (fun=XIL(0x7ffff3db0905), nargs=1, arg_vector=0x7fffffffe2a8) at ../../src/eval.c:3244
#27 0x00000000006928b2 in Ffuncall (nargs=2, args=0x7fffffffe2a0) at ../../src/eval.c:3043
#28 0x000000000069217b in call1 (fn=XIL(0x43e0), arg1=XIL(0x7ffff3134918)) at ../../src/eval.c:2899
#29 0x00000000005b4838 in command_loop_1 () at ../../src/keyboard.c:1466
#30 0x000000000068e3bd in internal_condition_case (bfun=0x5b3fdf <command_loop_1>, handlers=XIL(0x90), hfun=0x5b35ee <cmd_error>) at ../../src/eval.c:1478
#31 0x00000000005b3bc4 in command_loop_2 (ignore=XIL(0)) at ../../src/keyboard.c:1094
#32 0x000000000068d59a in internal_catch (tag=XIL(0xe100), func=0x5b3b97 <command_loop_2>, arg=XIL(0)) at ../../src/eval.c:1198
#33 0x00000000005b3b62 in command_loop () at ../../src/keyboard.c:1073
#34 0x00000000005b30d5 in recursive_edit_1 () at ../../src/keyboard.c:720
#35 0x00000000005b32cd in Frecursive_edit () at ../../src/keyboard.c:789
#36 0x00000000005af1a4 in main (argc=2, argv=0x7fffffffe7c8) at ../../src/emacs.c:2298

Lisp Backtrace:
"select-window" (0xffffcaa0)
"progn" (0xffffcc50)
"eval" (0xffffce80)
"elisp--eval-last-sexp" (0xffffd378)
"eval-last-sexp" (0xffffd970)
"funcall-interactively" (0xffffd968)
"call-interactively" (0xffffdd40)
"command-execute" (0xffffe2a8)
(gdb)