From d9a024ea1278f6ad556bfc2f74feb425ba7ce437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Tue, 5 Sep 2017 23:10:54 -0300 Subject: [PATCH 2/5] Enable history for executed commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Diego Aurélio Mesquita --- src/files.c | 3 ++- src/global.c | 18 ++++++++++++------ src/proto.h | 3 +++ src/search.c | 13 +++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/files.c b/src/files.c index d4a9a934..6b9f42d9 100644 --- a/src/files.c +++ b/src/files.c @@ -1090,7 +1090,7 @@ void do_insertfile(void) #endif MINSERTFILE, given, #ifndef DISABLE_HISTORIES - NULL, + execute ? &execute_history : NULL, #endif edit_refresh, buf, #ifndef DISABLE_OPERATINGDIR @@ -1158,6 +1158,7 @@ void do_insertfile(void) if (*answer != '\0') { execute_command(answer); last_command = mallocstrcpy(last_command, answer); + update_history(&execute_history, answer); } else { execute_command(last_command); } diff --git a/src/global.c b/src/global.c index 88983530..ac9f7eab 100644 --- a/src/global.c +++ b/src/global.c @@ -208,6 +208,12 @@ filestruct *searchage = NULL; /* The top of the search string history list. */ filestruct *searchbot = NULL; /* The bottom of the search string history list. */ +filestruct *execute_history = NULL; + /* The execute string history list. */ +filestruct *executeage = NULL; + /* The top of the execute string history list. */ +filestruct *executebot = NULL; + /* The bottom of the execute string history list. */ filestruct *replace_history = NULL; /* The replace string history list. */ filestruct *replaceage = NULL; @@ -1264,17 +1270,17 @@ void shortcut_init(void) add_to_sclist(MWHEREIS, "^T", 0, do_gotolinecolumn_void, 0); add_to_sclist(MGOTOLINE, "^T", 0, gototext_void, 0); #ifndef DISABLE_HISTORIES - add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^P", 0, get_history_older_void, 0); - add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^N", 0, get_history_newer_void, 0); + add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "^P", 0, get_history_older_void, 0); + add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "^N", 0, get_history_newer_void, 0); #ifdef ENABLE_UTF8 if (using_utf8()) { - add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "\xE2\x86\x91", KEY_UP, get_history_older_void, 0); - add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "\xE2\x86\x93", KEY_DOWN, get_history_newer_void, 0); + add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "\xE2\x86\x91", KEY_UP, get_history_older_void, 0); + add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "\xE2\x86\x93", KEY_DOWN, get_history_newer_void, 0); } else #endif { - add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Up", KEY_UP, get_history_older_void, 0); - add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Down", KEY_DOWN, get_history_newer_void, 0); + add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "Up", KEY_UP, get_history_older_void, 0); + add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "Down", KEY_DOWN, get_history_newer_void, 0); } #endif #ifdef ENABLE_BROWSER diff --git a/src/proto.h b/src/proto.h index 4abc453b..bdffa312 100644 --- a/src/proto.h +++ b/src/proto.h @@ -160,6 +160,9 @@ extern subnfunc *uncutfunc; extern filestruct *search_history; extern filestruct *searchage; extern filestruct *searchbot; +extern filestruct *execute_history; +extern filestruct *executeage; +extern filestruct *executebot; extern filestruct *replace_history; extern filestruct *replaceage; extern filestruct *replacebot; diff --git a/src/search.c b/src/search.c index 92d90223..c2aa46db 100644 --- a/src/search.c +++ b/src/search.c @@ -1103,6 +1103,11 @@ void history_init(void) searchage = search_history; searchbot = search_history; + execute_history = make_new_node(NULL); + execute_history->data = mallocstrcpy(NULL, ""); + executeage = execute_history; + executebot = execute_history; + replace_history = make_new_node(NULL); replace_history->data = mallocstrcpy(NULL, ""); replaceage = replace_history; @@ -1114,6 +1119,8 @@ void history_reset(const filestruct *h) { if (h == search_history) search_history = searchbot; + else if (h == execute_history) + execute_history = executebot; else if (h == replace_history) replace_history = replacebot; } @@ -1145,6 +1152,9 @@ void update_history(filestruct **h, const char *s) if (*h == search_history) { hage = &searchage; hbot = &searchbot; + } else if (*h == execute_history) { + hage = &executeage; + hbot = &executebot; } else if (*h == replace_history) { hage = &replaceage; hbot = &replacebot; @@ -1245,6 +1255,9 @@ char *get_history_completion(filestruct **h, char *s, size_t len) if (*h == search_history) { hage = searchage; hbot = searchbot; + } else if (*h == execute_history) { + hage = executeage; + hbot = executebot; } else if (*h == replace_history) { hage = replaceage; hbot = replacebot; -- 2.11.0