history: remember the commands that were executed during this session

Signed-off-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
This commit is contained in:
Marco Diego Aurélio Mesquita 2017-09-05 23:10:54 -03:00 committed by Benno Schulenberg
parent 4aec1649f5
commit c8363a0d0b
4 changed files with 30 additions and 7 deletions

View File

@ -1081,7 +1081,7 @@ void do_insertfile(void)
#endif #endif
MINSERTFILE, given, MINSERTFILE, given,
#ifndef DISABLE_HISTORIES #ifndef DISABLE_HISTORIES
NULL, execute ? &execute_history : NULL,
#endif #endif
edit_refresh, msg, edit_refresh, msg,
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
@ -1144,6 +1144,7 @@ void do_insertfile(void)
#endif #endif
/* Save the command's output in the current buffer. */ /* Save the command's output in the current buffer. */
execute_command(answer); execute_command(answer);
update_history(&execute_history, answer);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
/* If this is a new buffer, put the cursor at the top. */ /* If this is a new buffer, put the cursor at the top. */

View File

@ -216,6 +216,12 @@ filestruct *replaceage = NULL;
/* The top of the replace string history list. */ /* The top of the replace string history list. */
filestruct *replacebot = NULL; filestruct *replacebot = NULL;
/* The bottom of the replace string history list. */ /* The bottom of the replace string history list. */
filestruct *execute_history = NULL;
/* The list of commands that have been run with ^R ^X. */
filestruct *executetop = NULL;
/* The top of the execute history list. */
filestruct *executebot = NULL;
/* The bottom of the execute history list. */
poshiststruct *position_history = NULL; poshiststruct *position_history = NULL;
/* The cursor position history list. */ /* The cursor position history list. */
#endif #endif
@ -1266,17 +1272,17 @@ void shortcut_init(void)
add_to_sclist(MWHEREIS, "^T", 0, do_gotolinecolumn_void, 0); add_to_sclist(MWHEREIS, "^T", 0, do_gotolinecolumn_void, 0);
add_to_sclist(MGOTOLINE, "^T", 0, gototext_void, 0); add_to_sclist(MGOTOLINE, "^T", 0, gototext_void, 0);
#ifndef DISABLE_HISTORIES #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|MEXTCMD, "^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, "^N", 0, get_history_newer_void, 0);
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
if (using_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|MEXTCMD, "\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\x93", KEY_DOWN, get_history_newer_void, 0);
} else } else
#endif #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|MEXTCMD, "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, "Down", KEY_DOWN, get_history_newer_void, 0);
} }
#endif #endif
#ifdef ENABLE_BROWSER #ifdef ENABLE_BROWSER

View File

@ -165,6 +165,9 @@ extern filestruct *searchbot;
extern filestruct *replace_history; extern filestruct *replace_history;
extern filestruct *replaceage; extern filestruct *replaceage;
extern filestruct *replacebot; extern filestruct *replacebot;
extern filestruct *execute_history;
extern filestruct *executetop;
extern filestruct *executebot;
extern poshiststruct *position_history; extern poshiststruct *position_history;
#endif #endif

View File

@ -1107,6 +1107,11 @@ void history_init(void)
replace_history->data = mallocstrcpy(NULL, ""); replace_history->data = mallocstrcpy(NULL, "");
replaceage = replace_history; replaceage = replace_history;
replacebot = replace_history; replacebot = replace_history;
execute_history = make_new_node(NULL);
execute_history->data = mallocstrcpy(NULL, "");
executetop = execute_history;
executebot = execute_history;
} }
/* Set the current position in the history list h to the bottom. */ /* Set the current position in the history list h to the bottom. */
@ -1116,6 +1121,8 @@ void history_reset(const filestruct *h)
search_history = searchbot; search_history = searchbot;
else if (h == replace_history) else if (h == replace_history)
replace_history = replacebot; replace_history = replacebot;
else if (h == execute_history)
execute_history = executebot;
} }
/* Return the first node containing the first len characters of the /* Return the first node containing the first len characters of the
@ -1148,6 +1155,9 @@ void update_history(filestruct **h, const char *s)
} else if (*h == replace_history) { } else if (*h == replace_history) {
hage = &replaceage; hage = &replaceage;
hbot = &replacebot; hbot = &replacebot;
} else if (*h == execute_history) {
hage = &executetop;
hbot = &executebot;
} }
assert(hage != NULL && hbot != NULL); assert(hage != NULL && hbot != NULL);
@ -1248,6 +1258,9 @@ char *get_history_completion(filestruct **h, char *s, size_t len)
} else if (*h == replace_history) { } else if (*h == replace_history) {
hage = replaceage; hage = replaceage;
hbot = replacebot; hbot = replacebot;
} else if (*h == execute_history) {
hage = executetop;
hbot = executebot;
} }
assert(hage != NULL && hbot != NULL); assert(hage != NULL && hbot != NULL);