Subject: Re: bug#68235: 29.1.90; Switching tabs stops following process output in selected window

From: Juri Linkov <[email-masked]>
Date: Sun, 07 Jan 2024 18:45:33 +0200

>> window-point-insertion-type is nil by default, but I'd definitely want
>> point to follow the output, that means not using the snippet above.
>
> But 'window-point-insertion-type' is buffer-locally t in all sorts of
> compilation buffers and that is the subject of this bug report.  Right?

Thanks, now I see that 'comint-mode', 'compilation-mode' and some
other modes set buffer-local 'window-point-insertion-type' to t.

> And I meant to use the buffer-local value of
> 'window-point-insertion-type' as insertion type for 'wc-point'.

Ah, now I see that 'copy-marker' supports the argument for
'window-point-insertion-type'.

>> But could you explain why such special-casing is not needed for
>> non-selected windows?  How set-window-configuration does the right
>> thing for points in non-selected windows to follow the output?
>> Maybe it's possible to do the same with point in the selected window?
>
> For an unselected window, 'set-window-configuration' uses that window's
> point marker from the saved configuration and that one should follow
> inserted text according to the value of 'window-point-insertion-type' in
> that window's buffer.  For the selected window, that window's buffer's
> point is "usually" unchanged from where it was just before restoring the
> configuration.

Indeed, the difference between selected/non-selected windows is here:

	  /* Save w's value of point in the window configuration.  If w
	     is the selected window, then get the value of point from
	     the buffer; pointm is garbage in the selected window.  */
	  if (EQ (window, selected_window))
	    p->pointm = build_marker (XBUFFER (w->contents),
				      BUF_PT (XBUFFER (w->contents)),
				      BUF_PT_BYTE (XBUFFER (w->contents)));
	  else
	    p->pointm = Fcopy_marker (w->pointm, Qnil);
	  p->old_pointm = Fcopy_marker (w->old_pointm, Qnil);
	  XMARKER (p->pointm)->insertion_type = window_point_insertion_type;
	  XMARKER (p->old_pointm)->insertion_type = window_point_insertion_type;

So the complete fix is just in 1 line:

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 7d491dc2f38..80cf94016b8 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1302,7 +1302,7 @@ tab-bar--tab
       (ws . ,(window-state-get
               (frame-root-window (or frame (selected-frame))) 'writable))
       (wc . ,(current-window-configuration))
-      (wc-point . ,(point-marker))
+      (wc-point . ,(copy-marker (window-point) window-point-insertion-type))
       (wc-bl . ,bl)
       (wc-bbl . ,bbl)
       ,@(when tab-bar-history-mode