Fix latent side-effects of respecting field boundaries in text conversion

* src/textconv.c (textconv_query, get_extracted_text)
(get_surrounding_text): Restore selected window in addition to
excursion.
(locate_and_save_position_in_field): Restore excursion lest the
current buffer differ from the selected window's contents, to
prevent redisplay from clobbering the current buffer when called
while the current buffer is at variance with the selected
window's contents, as seen with dired-other-window.
This commit is contained in:
Po Lu 2024-06-25 11:37:09 +08:00
parent e4046f33ab
commit 1b4c562721

View file

@ -153,6 +153,15 @@ select_window (Lisp_Object window, Lisp_Object norecord)
Fselect_window (window, norecord);
}
/* Restore the selected window WINDOW. */
static void
restore_selected_window (Lisp_Object window)
{
/* FIXME: not sure what to do if WINDOW has been deleted. */
select_window (window, Qt);
}
/* Perform the text conversion operation specified in QUERY and return
the results.
@ -188,6 +197,7 @@ textconv_query (struct frame *f, struct textconv_callback_struct *query,
selected window. */
count = SPECPDL_INDEX ();
record_unwind_protect_excursion ();
record_unwind_protect (restore_selected_window, selected_window);
/* Inhibit quitting. */
specbind (Qinhibit_quit, Qt);
@ -586,15 +596,6 @@ detect_conversion_events (void)
return false;
}
/* Restore the selected window WINDOW. */
static void
restore_selected_window (Lisp_Object window)
{
/* FIXME: not sure what to do if WINDOW has been deleted. */
select_window (window, Qt);
}
/* Commit the given text in the composing region. If there is no
composing region, then insert the text after frame F's selected
window's last point instead, unless the mark is active. Finally,
@ -1138,6 +1139,10 @@ locate_and_save_position_in_field (struct frame *f, struct window *w,
/* Set the current buffer to W's. */
count = SPECPDL_INDEX ();
/* The current buffer must be saved, not merely the selected
window. */
record_unwind_protect_excursion ();
record_unwind_protect (restore_selected_window, selected_window);
XSETWINDOW (window, w);
select_window (window, Qt);
@ -2097,6 +2102,7 @@ get_extracted_text (struct frame *f, ptrdiff_t n,
selected window. */
count = SPECPDL_INDEX ();
record_unwind_protect_excursion ();
record_unwind_protect (restore_selected_window, selected_window);
/* Inhibit quitting. */
specbind (Qinhibit_quit, Qt);
@ -2219,6 +2225,7 @@ get_surrounding_text (struct frame *f, ptrdiff_t left,
selected window. */
count = SPECPDL_INDEX ();
record_unwind_protect_excursion ();
record_unwind_protect (restore_selected_window, selected_window);
/* Inhibit quitting. */
specbind (Qinhibit_quit, Qt);