top: allow re-ordering of saved line input upon recall

The original implementation of input line recall keeps
strings in the order established when initially added.
With this commit, that has been changed so any matched
string moves to the top of the saved input line stack.

[ well technically not the top since that's occupied ]
[ by an 'empty' string which serves multiple masters ]

Thus, the most frequently referenced strings over time
will percolate up and remain the most easily recalled.
But just in case anybody prefers the strict historical
ordering, a #define can restore the original behavior.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 2efe275512

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2013-02-22 00:00:00 -06:00 committed by Jaromir Capik
parent 5c3fffcf28
commit 5ee1286625
2 changed files with 21 additions and 1 deletions

View File

@ -1161,7 +1161,23 @@ static char *ioline (const char *prompt) {
// weed out duplicates, including empty strings (top-of-stack)...
for (i = 0, plin = anchor; ; i++) {
if (!STRCMP(plin->str, buf)) return buf;
#ifdef RECALL_FIXED
if (!STRCMP(plin->str, buf)) // if matched, retain original order
return buf;
#else
if (!STRCMP(plin->str, buf)) { // if matched, rearrange stack order
if (i > 1) { // but not null str or if already #2
if (plin->bkw) // splice around this matched string
plin->bkw->fwd = plin->fwd; // if older exists link to newer
plin->fwd->bkw = plin->bkw; // newer linked to older or NULL
anchor->bkw->fwd = plin; // stick matched on top of former #2
plin->bkw = anchor->bkw; // keep empty string at top-of-stack
plin->fwd = anchor; // then prepare to be the 2nd banana
anchor->bkw = plin; // by sliding us in below the anchor
}
return buf;
}
#endif
if (!plin->bkw) break; // let i equal total stacked strings
plin = plin->bkw; // ( with plin representing bottom )
}

View File

@ -45,6 +45,7 @@
//#define PRETEND4CPUS /* pretend we're smp with 4 ticsers (sic) */
//#define PRETENDNOCAP /* use a terminal without essential caps */
//#define RCFILE_NOERR /* rcfile errs silently default, vs. fatal */
//#define RECALL_FIXED /* don't reorder saved strings if recalled */
//#define RMAN_IGNORED /* don't consider auto right margin glitch */
//#define SCROLLVAR_NO /* disable intra-column horizontal scroll */
//#define STRINGCASENO /* case insenstive compare/locate versions */
@ -597,6 +598,9 @@ typedef struct WIN_t {
#if defined(ATEOJ_RPTHSH) && defined(OFF_HST_HASH)
# error 'ATEOJ_RPTHSH' conflicts with 'OFF_HST_HASH'
#endif
#if defined(RECALL_FIXED) && defined(TERMIOS_ONLY)
# error 'RECALL_FIXED' conflicts with 'TERMIOS_ONLY'
#endif
#if (LRGBUFSIZ < SCREENMAX)
# error 'LRGBUFSIZ' must NOT be less than 'SCREENMAX'
#endif