Simplify and improve qe_check_buffer_file

* pass `QEmacsState` to key grab functions
* clear `grab_key_opaque` when freeing windows, buffers, mode_data
* add checks on window and buffer pointers in key grab functions
* this should fix a crash bug when deleting unsynched buffers from bufed
* fix `reload_buffer` to update buffer `file_size` and `mtime` fields
* check buffer file before invoking commands that modify the buffer
* check buffer file after command that changes the current window
  or the current window's buffer
This commit is contained in:
Charlie Gordon 2026-06-23 16:24:02 +02:00
commit 6fb16e1cc2
8 changed files with 88 additions and 71 deletions

View file

@ -309,7 +309,6 @@ static void bufed_select(EditState *s, int temp)
do_delete_window(s, 1);
if (e) {
qs->active_window = e;
qe_check_buffer_file(e->b, CBF_CHECK);
}
}
} else {

View file

@ -1458,7 +1458,6 @@ static void dired_select(EditState *s, int mode)
if (e) {
#if 1
s->qs->active_window = e;
qe_check_buffer_file(e->b, CBF_CHECK);
if (mode == 1) {
/* XXX: should keep BF_PREVIEW flag and set pager-mode */
e->b->flags &= ~BF_PREVIEW;
@ -1544,7 +1543,6 @@ static void dired_parent(EditState *s, int collapse)
EditState *e = find_window(s, KEY_LEFT, NULL);
if (e && (e->flags & WF_FILELIST)) {
s->qs->active_window = e;
qe_check_buffer_file(e->b, CBF_CHECK);
return;
}
}

View file

@ -1368,7 +1368,7 @@ static void shell_display_hook(EditState *e)
}
}
static void shell_key(void *opaque, int key)
static void shell_key(QEmacsState *qs, void *opaque, int key)
{
ShellState *s = opaque;
char buf[10];
@ -1379,8 +1379,8 @@ static void shell_key(void *opaque, int key)
return;
if (key == KEY_CTRL('o') && s->last_key_grabbed == KEY_CTRL(' ')) {
qe_ungrab_keys(s->base.qs);
qe_unget_key(s->base.qs, key);
qe_ungrab_keys(qs);
qe_unget_key(qs, key);
s->last_key_grabbed = key;
return;
}
@ -2878,7 +2878,6 @@ static EditBuffer *try_show_buffer(EditState **sp, const char *bufname)
e = eb_find_window(b, NULL);
if (e) {
qs->active_window = *sp = e;
qe_check_buffer_file(e->b, CBF_CHECK);
} else {
switch_to_buffer(s, b);
}