From e86b552a4828738070fc98becea8de818e9f74a6 Mon Sep 17 00:00:00 2001 From: Jiri Tyr Date: Sun, 15 Mar 2026 12:51:11 +0000 Subject: [PATCH 1/2] Improving block file change detection Signed-off-by: Jiri Tyr --- src/editor/edit.c | 11 ++++++++++- src/editor/editcmd.c | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index 360c347476..758181327e 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -1789,10 +1789,19 @@ edit_user_menu (WEdit *edit, const char *menu_file, int selected_entry) const gboolean status_after_ok = mc_stat (block_file_vpath, &status_after) == 0; // was block file created or modified by menu command? + // Use nanosecond-precision mtime when available, because scripts that only + // rearrange bytes (e.g. word-wrap replacing spaces with newlines) produce + // the same file size and may finish within the same second. modified = (!status_before_ok && status_after_ok) || (status_before_ok && status_after_ok && status_after.st_size != 0 && (status_after.st_size != status_before.st_size - || status_after.st_mtime != status_before.st_mtime)); +#ifdef HAVE_STRUCT_STAT_ST_MTIM + || status_after.st_mtim.tv_sec != status_before.st_mtim.tv_sec + || status_after.st_mtim.tv_nsec != status_before.st_mtim.tv_nsec +#else + || status_after.st_mtime != status_before.st_mtime +#endif + )); } if (modified) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index a1cc34e877..c71cae46c6 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1939,6 +1939,19 @@ edit_block_process_cmd (WEdit *edit, int macro_number) { char *fname; char *macros_fname = NULL; + off_t start_mark, end_mark; + + // Save the selected block to the block file so that macro scripts + // referencing %b can read it. Without this, the block file does not + // exist when the script runs and %b points to a nonexistent file. + if (eval_marks (edit, &start_mark, &end_mark)) + { + char *tmp; + + tmp = mc_config_get_full_path (EDIT_HOME_BLOCK_FILE); + edit_save_block (edit, tmp, start_mark, end_mark); + g_free (tmp); + } fname = g_strdup_printf ("%s.%i.sh", EDIT_HOME_MACRO_FILE, macro_number); macros_fname = g_build_filename (mc_config_get_data_path (), fname, (char *) NULL); From 0fc04c86aad905f508c25a1a54d86fbcec4414e8 Mon Sep 17 00:00:00 2001 From: Jiri Tyr Date: Thu, 2 Apr 2026 14:58:32 +0100 Subject: [PATCH 2/2] Moving the save before macro execution to be applied to all menu operations Signed-off-by: Jiri Tyr --- src/editor/edit.c | 9 +++++++++ src/editor/editcmd.c | 13 ------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index 758181327e..eedf988348 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -1780,6 +1780,15 @@ edit_user_menu (WEdit *edit, const char *menu_file, int selected_entry) block_file = mc_config_get_full_path (EDIT_HOME_BLOCK_FILE); block_file_vpath = vfs_path_from_str (block_file); + /* Save the selected block to the block file before running the command. + This makes %b available to macro scripts that process the selection. */ + { + off_t start_mark, end_mark; + + if (eval_marks (edit, &start_mark, &end_mark)) + edit_save_block (edit, block_file, start_mark, end_mark); + } + const gboolean status_before_ok = mc_stat (block_file_vpath, &status_before) == 0; // run menu command. It can or can not create or modify block_file diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index c71cae46c6..a1cc34e877 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1939,19 +1939,6 @@ edit_block_process_cmd (WEdit *edit, int macro_number) { char *fname; char *macros_fname = NULL; - off_t start_mark, end_mark; - - // Save the selected block to the block file so that macro scripts - // referencing %b can read it. Without this, the block file does not - // exist when the script runs and %b points to a nonexistent file. - if (eval_marks (edit, &start_mark, &end_mark)) - { - char *tmp; - - tmp = mc_config_get_full_path (EDIT_HOME_BLOCK_FILE); - edit_save_block (edit, tmp, start_mark, end_mark); - g_free (tmp); - } fname = g_strdup_printf ("%s.%i.sh", EDIT_HOME_MACRO_FILE, macro_number); macros_fname = g_build_filename (mc_config_get_data_path (), fname, (char *) NULL);