zsh-workers
 help / color / mirror / code / Atom feed
* Proposed history improvements
@ 2001-05-09 22:45 Wayne Davison
  2001-05-10  3:36 ` Zefram
  0 siblings, 1 reply; 8+ messages in thread
From: Wayne Davison @ 2001-05-09 22:45 UTC (permalink / raw)
  To: Zsh Workers

Back in the 3.0.x series I started a tradition of releasing a history
patch too close to the release date to be included.  Here's my attempt
to continue this tradition. :-)  Let me know if you think something
like this should be included in the upcoming release or not.

What I've done is (1) to slightly change the way HIST_IGNORE_SPACE,
HIST_NO_FUNCTIONS, and HIST_NO_STORE works, and (2) to add the option
HIST_DEPRECATE_SPACE.

1. I have gotten in the habit of prefixing certain commands with a space
that I don't want cluttering up my history.  However, I have always been
annoyed when I mistype something and I have to retype or cut & paste to
try the command again.  My change makes an ignored command stick around
just until the next command is typed.  This allows me to use Ctrl-P or
!!$ or whatever for the next command, at which point the ignored command
vanishes from the internal history (and was never written to the history
file).  You can type space-return to clear the previous command, if
you're feeling paranoid.  What do folks think of this idea?  Do you
think something like this should require a separate option?

2. I thought it would be cool if I could hint to the history system
about which lines I consider more important.  With HIST_DEPRECATE_SPACE
set, lines that start with a space are considered to be local only
(never being written to the history file) and are expired before other
unique commands are removed (but after dups if HIST_EXPIRE_DUPS_FIRST is
set).  If you also have the HIST_IGNORE_SPACE option set, you'll need to
type a second space to trigger that treatment.  While these two options
are similar, you can have lots of deprecated history lines hanging
around in the local history, but only one last-typed-but-soon-to-be-lost
ignored line.

Also note that the space-prefixed-alias idiom continues to work, and has
the same rules as stated above for marking an entry as ignored or as
deprecated (depending on what options are set).

Comments?  Any better ideas?  I've appended a patch for the latest CVS
verion, but (of course) have not checked it in (nor created any doc
changes yet).

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hashtable.c
@@ -1480,15 +1480,21 @@
     HashNode oldnode = addhashnode2(ht, nam, nodeptr);
     Histent he = (Histent)nodeptr;
     if (oldnode && oldnode != (HashNode)nodeptr) {
-	if (he->flags & HIST_MAKEUNIQUE
+	if (he->flags & (HIST_MAKEUNIQUE | HIST_TMPSTORE)
 	 || (he->flags & HIST_FOREIGN && (Histent)oldnode == he->up)) {
+	    (void) addhashnode2(ht, oldnode->nam, oldnode); /* restore hash */
 	    he->flags |= HIST_DUP;
-	    addhashnode(ht, oldnode->nam, oldnode); /* Remove the new dup */
+	    he->flags &= ~HIST_MAKEUNIQUE;
 	}
 	else {
-	    oldnode->flags |= HIST_DUP;
+	    oldnode->flags |= HIST_DUP | (he->flags & HIST_DEPRECATED);
 	    if (hist_ignore_all_dups)
 		freehistnode(oldnode); /* Remove the old dup */
+	}
+	if (isset(HISTDEPRECATESPACE) && *nam == ' ') {
+	    while (*nam == ' ') nam++;
+	    if ((oldnode = gethashnode(ht, nam)) != NULL)
+		oldnode->flags |= HIST_DEPRECATED;
 	}
     }
     else
Index: Src/hist.c
@@ -794,16 +794,21 @@
 void
 histreduceblanks(void)
 {
-    int i, len, pos, needblank;
+    int i, len, pos, needblank, spacecount = 0;

-    for (i = 0, len = 0; i < chwordpos; i += 2) {
+    if (isset(HISTIGNORESPACE))
+	for (spacecount = 0; chline[spacecount] == ' '; spacecount++) ;
+    else
+	spacecount = isset(HISTDEPRECATESPACE) && chline[0] == ' ';
+
+    for (i = 0, len = spacecount; i < chwordpos; i += 2) {
 	len += chwords[i+1] - chwords[i]
 	     + (i > 0 && chwords[i] > chwords[i-1]);
     }
     if (chline[len] == '\0')
 	return;

-    for (i = 0, pos = 0; i < chwordpos; i += 2) {
+    for (i = 0, pos = spacecount; i < chwordpos; i += 2) {
 	len = chwords[i+1] - chwords[i];
 	needblank = (i < chwordpos-2 && chwords[i+2] > chwords[i+1]);
 	if (pos != chwords[i]) {
@@ -933,17 +938,24 @@
 	histlinect++;
     }
     else {
+	Histent del = NULL;
 	he = hist_ring->down;
-	if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) {
+	if (isset(HISTEXPIREDUPSFIRST) || isset(HISTDEPRECATESPACE)) {
 	    int max_unique_ct = getiparam("SAVEHIST");
 	    do {
 		if (max_unique_ct-- <= 0) {
 		    he = hist_ring->down;
 		    break;
 		}
+		if (isset(HISTEXPIREDUPSFIRST) && he->flags & HIST_DUP) {
+		    del = he;
+		    break;
+		}
+		if (he->flags & HIST_DEPRECATED)
+		    del = he;
 		he = he->down;
-	    } while (he != hist_ring->down && !(he->flags & HIST_DUP));
-	    if (he != hist_ring->down) {
+	    } while (he != hist_ring->down);
+	    if (del && (he = del) != hist_ring->down) {
 		he->up->down = he->down;
 		he->down->up = he->up;
 		he->up = hist_ring;
@@ -959,17 +971,25 @@
     return he;
 }

-/* A helper function for hend() */
+/* A helper function for hend().  The return is the "save" value:
+ * 0 = skip, 1 = save, 2 = deprecated save, 3 = temporary save. */

 static int
 should_ignore_line(Eprog prog)
 {
+    int spacecount = aliasspacecount;
+
     if (!prog)
-	return 0;
+	return 1;

-    if (isset(HISTIGNORESPACE)) {
-	if (*chline == ' ' || aliasspaceflag)
-	    return 1;
+    if (*chline == ' ')
+	spacecount = 1 + (chline[1] == ' ');
+    if (spacecount) {
+	if (isset(HISTIGNORESPACE)
+	 && (spacecount > 1 || !isset(HISTDEPRECATESPACE)))
+	    return 3;
+	if (isset(HISTDEPRECATESPACE))
+	    return 2;
     }

     if (isset(HISTNOFUNCTIONS)) {
@@ -977,7 +997,7 @@
 	wordcode code = *pc;
 	if (wc_code(code) == WC_LIST && WC_LIST_TYPE(code) & Z_SIMPLE
 	 && wc_code(pc[2]) == WC_FUNCDEF)
-	    return 1;
+	    return 3;
     }

     if (isset(HISTNOSTORE)) {
@@ -986,17 +1006,17 @@
 	    b += 8;
 	if (*b == 'h' && strncmp(b, "history", 7) == 0
 	 && (!b[7] || b[7] == ' '))
-	    return 1;
+	    return 3;
 	if (*b == 'f' && b[1] == 'c' && b[2] == ' ' && b[3] == '-') {
 	    b += 3;
 	    do {
 		if (*++b == 'l')
-		    return 1;
+		    return 3;
 	    } while (ialpha(*b));
 	}
     }

-    return 0;
+    return 1;
 }

 /* say we're done using the history mechanism */
@@ -1044,8 +1064,13 @@
 	    } else
 		save = 0;
 	}
-	if (chwordpos <= 2 || should_ignore_line(prog))
+	if (chwordpos <= 2) {
+	    if (*chline == ' ' && hist_ring->flags & HIST_TMPSTORE)
+		freehistnode((HashNode)hist_ring);
 	    save = 0;
+	}
+	else
+	    save = should_ignore_line(prog);
     }
     if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) {
 	char *ptr;
@@ -1065,7 +1090,12 @@
     }
     if (save) {
 	Histent he;
-	int keepflags;
+	int newflags;
+
+	for (he = hist_ring; he && he->flags & HIST_FOREIGN;
+	     he = up_histent(he)) ;
+	if (he && he->flags & HIST_TMPSTORE)
+	    freehistnode((HashNode)he);

 	for (he = hist_ring; he && he->flags & hist_skip_flags;
 	     he = up_histent(he)) ;
@@ -1083,6 +1113,8 @@
 	    if (isset(HISTREDUCEBLANKS))
 		histreduceblanks();
 	}
+	newflags = save == 1? 0
+		 : HIST_OLD | HIST_DEPRECATED | (save > 2? HIST_TMPSTORE : 0);
 	if ((isset(HISTIGNOREDUPS) || isset(HISTIGNOREALLDUPS)) && he
 	 && histstrcmp(chline, he->text) == 0) {
 	    /* This history entry compares the same as the previous.
@@ -1090,18 +1122,16 @@
 	     * previous one with the current one.  This also gets the
 	     * timestamp right.  Perhaps, preserve the HIST_OLD flag.
 	     */
-	    keepflags = he->flags & HIST_OLD; /* Avoid re-saving */
+	    newflags |= he->flags & HIST_OLD; /* Avoid re-saving */
 	    freehistdata(he, 0);
 	    curline.histnum = curhist;
-	} else {
-	    keepflags = 0;
+	} else
 	    he = prepnexthistent();
-	}

 	he->text = ztrdup(chline);
 	he->stim = time(NULL);
 	he->ftim = 0L;
-	he->flags = keepflags;
+	he->flags = newflags;

 	if ((he->nwords = chwordpos/2)) {
 	    he->words = (short *)zalloc(chwordpos * sizeof(short));
@@ -1894,8 +1924,10 @@
 	    } else
 		he->words = (short *)NULL;
 	    addhistnode(histtab, he->text, he);
-	    if (hist_ring != he)
-		curhist--; /* We discarded a foreign duplicate */
+	    if (he->flags & HIST_DUP) {
+		freehistnode((HashNode)he);
+		curhist--;
+	    }
 	}
 	if (start && readflags & HFILE_USE_OPTIONS) {
 	    zsfree(lasthist.text);
@@ -1963,7 +1995,8 @@
     if (out) {
 	for (; he && he->histnum <= xcurhist; he = down_histent(he)) {
 	    if ((writeflags & HFILE_SKIPDUPS && he->flags & HIST_DUP)
-	     || (writeflags & HFILE_SKIPFOREIGN && he->flags & HIST_FOREIGN))
+	     || (writeflags & HFILE_SKIPFOREIGN && he->flags & HIST_FOREIGN)
+	     || he->flags & HIST_DEPRECATED)
 		continue;
 	    if (writeflags & HFILE_SKIPOLD) {
 		if (he->flags & HIST_OLD)
Index: Src/lex.c
@@ -1601,7 +1601,7 @@
 				     inalmore)) {
 		inpush(an->text, INP_ALIAS, an);
 		if (an->text[0] == ' ')
-		    aliasspaceflag = 1;
+		    aliasspacecount = 1 + (an->text[1] == ' ');
 		lexstop = 0;
 		if (yytext == copy)
 		    yytext = tokstr;
Index: Src/options.c
@@ -125,6 +125,7 @@
 {NULL, "hashlistall",	      OPT_ALL,			 HASHLISTALL},
 {NULL, "histallowclobber",    0,			 HISTALLOWCLOBBER},
 {NULL, "histbeep",	      OPT_ALL,			 HISTBEEP},
+{NULL, "histdeprecatespace",  0,			 HISTDEPRECATESPACE},
 {NULL, "histexpiredupsfirst", 0,			 HISTEXPIREDUPSFIRST},
 {NULL, "histfindnodups",      0,			 HISTFINDNODUPS},
 {NULL, "histignorealldups",   0,			 HISTIGNOREALLDUPS},
Index: Src/parse.c
@@ -36,7 +36,7 @@
 mod_export int incmdpos;

 /**/
-int aliasspaceflag;
+int aliasspacecount;

 /* != 0 if we are in the middle of a [[ ... ]] */

@@ -432,7 +432,7 @@
 {
     tok = ENDINPUT;
     incmdpos = 1;
-    aliasspaceflag = 0;
+    aliasspacecount = 0;
     yylex();
     init_parse();
     return ((par_event()) ? bld_eprog() : NULL);
Index: Src/zsh.h
@@ -1252,6 +1252,8 @@
 #define HIST_READ	0x00000004	/* Command was read back from disk*/
 #define HIST_DUP	0x00000008	/* Command duplicates a later line */
 #define HIST_FOREIGN	0x00000010	/* Command came from another shell */
+#define HIST_DEPRECATED	0x00000020	/* Killed before other unique entries */
+#define HIST_TMPSTORE	0x00000040	/* Kill when not the newest entry */

 #define GETHIST_UPWARD  (-1)
 #define GETHIST_DOWNWARD  1
@@ -1362,6 +1364,7 @@
     HASHLISTALL,
     HISTALLOWCLOBBER,
     HISTBEEP,
+    HISTDEPRECATESPACE,
     HISTEXPIREDUPSFIRST,
     HISTFINDNODUPS,
     HISTIGNOREALLDUPS,
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Proposed history improvements
  2001-05-09 22:45 Proposed history improvements Wayne Davison
@ 2001-05-10  3:36 ` Zefram
  2001-05-10  5:54   ` Wayne Davison
  2001-05-10  7:04   ` Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: Zefram @ 2001-05-10  3:36 UTC (permalink / raw)
  To: Wayne Davison; +Cc: Zsh Workers

Wayne Davison wrote:
>                        My change makes an ignored command stick around
>just until the next command is typed.

Nice.

>                                                             Do you
>think something like this should require a separate option?

Probably, but I don't see a problem with the option being on by default.

>2. I thought it would be cool if I could hint to the history system
>about which lines I consider more important.  With HIST_DEPRECATE_SPACE
...

This bit is getting too complicated.  Instead of having multiple
competing options (HIST_DEPRECATE_SPACE and HIST_EXPIRE_DUPS_FIRST --
where's HIST_DEPRECATE_DUPS for the opposite priority ordering?), let's
have some configurable shell code to decide how important each history
entry is.  We can have a shell function that gets called whenever a
line is added to the history, which gets to reply a number saying how
important the line is.  The effect of both HIST_DEPRECATE_SPACE and
HIST_EXPIRE_DUPS_FIRST being on can then be achieved by

	function histimportance {
		if [[ -n "${(k)history[(r)$1]}" ]]; then
			REPLY=1
		elif [[ "$1" == " "* ]]; then
			REPLY=2
		else
			REPLY=3
		fi
	}

Or probably a better way would be to have a virtual associative array
giving this importance number for each history element, initialised
according to the existing options, and have a "histadded" function that
has the option to change this number for the current event or in fact
for any previous event (allowing duplicates to be expired oldest-first
instead of the newest-first that the above code does).

Other history stuff that could similarly be moved to shell code: deciding
whether a history line is to be stored at all (say, the "histadded"
function returns non-zero to say "don't add this to the history");
deciding whether a history line is to be saved in the history file
(another array, paralleling the `importance' one described above, or
an overloaded meaning for the importance array); possibly the history
file saving itself.  Actually almost the whole history mechanism *could*
be moved out of the C nd into shell code.

-zefram


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Proposed history improvements
  2001-05-10  3:36 ` Zefram
@ 2001-05-10  5:54   ` Wayne Davison
  2001-05-10  9:00     ` Peter Stephenson
  2001-05-10  7:04   ` Bart Schaefer
  1 sibling, 1 reply; 8+ messages in thread
From: Wayne Davison @ 2001-05-10  5:54 UTC (permalink / raw)
  To: Zefram; +Cc: Zsh Workers

Thanks for the feedback.  Since the idea for the lingering-history-drop
is fairly simple, let's separate that one out.  Here's a new patch that
just adds this functionality, and also adds a new option called
"hist_immediate_drop" that will restore the old behavior, should the
user decide to turn it on.

Comments?

After I test this for a while longer, I'd be comfortable committing this
to CVS.  If we're further along in the release cycle where that wouldn't
be a good idea, let me know.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Doc/Zsh/options.yo
@@ -544,18 +544,39 @@
 pindex(HIST_IGNORE_SPACE)
 cindex(history, ignoring spaces)
 item(tt(HIST_IGNORE_SPACE) (tt(-g)))(
-Do not enter command lines into the history list
-if the first character on the line is a space, or if one of
-the expanded aliases contained a leading space.
+Remove command lines from the history list when the first character on
+the line is a space, or when one of the expanded aliases contains a
+leading space.
+If tt(HIST_IMMEDIATE_DROP) is set, the line is dropped from the
+history right away, otherwise the command lingers in the internal
+history until the next command is entered before being dropped
+(allowing you to briefly reuse and/or edit the line).
 )
+pindex(HIST_IMMEDIATE_DROP)
+cindex(history, dropping lines)
+item(tt(HIST_IMMEDIATE_DROP))(
+When this option is set, dropped history lines are immediately lost.
+By default, the to-be-dropped history line lingers until the next
+command is typed, allowing you to briefly reuse and/or edit it.
+See also tt(HIST_IGNORE_SPACE), tt(HIST_NO_FUNCTIONS), and
+tt(HIST_NO_STORE).
+)
 pindex(HIST_NO_FUNCTIONS)
 item(tt(HIST_NO_FUNCTIONS))(
-Do not store function definitions in the history list.
+Remove function definitions from the history list.
+If tt(HIST_IMMEDIATE_DROP) is set, the line is dropped from the
+history right away, otherwise the function lingers in the internal
+history until the next command is entered before being dropped
+(allowing you to briefly reuse and/or edit the line).
 )
 pindex(HIST_NO_STORE)
 item(tt(HIST_NO_STORE))(
-Remove the tt(history) (tt(fc -l)) command from
-the history when invoked.
+Remove the tt(history) (tt(fc -l)) command from the history list
+when invoked.
+If tt(HIST_IMMEDIATE_DROP) is set, the line is dropped from the
+history right away, otherwise the command lingers in the internal
+history until the next command is entered before being dropped
+(allowing you to briefly reuse and/or edit the line).
 )
 pindex(HIST_REDUCE_BLANKS)
 item(tt(HIST_REDUCE_BLANKS))(
Index: Src/hashtable.c
@@ -1480,10 +1480,11 @@
     HashNode oldnode = addhashnode2(ht, nam, nodeptr);
     Histent he = (Histent)nodeptr;
     if (oldnode && oldnode != (HashNode)nodeptr) {
-	if (he->flags & HIST_MAKEUNIQUE
+	if (he->flags & (HIST_MAKEUNIQUE | HIST_TMPSTORE)
 	 || (he->flags & HIST_FOREIGN && (Histent)oldnode == he->up)) {
+	    (void) addhashnode2(ht, oldnode->nam, oldnode); /* restore hash */
 	    he->flags |= HIST_DUP;
-	    addhashnode(ht, oldnode->nam, oldnode); /* Remove the new dup */
+	    he->flags &= ~HIST_MAKEUNIQUE;
 	}
 	else {
 	    oldnode->flags |= HIST_DUP;
Index: Src/hist.c
@@ -794,16 +794,19 @@
 void
 histreduceblanks(void)
 {
-    int i, len, pos, needblank;
+    int i, len, pos, needblank, spacecount = 0;

-    for (i = 0, len = 0; i < chwordpos; i += 2) {
+    if (isset(HISTIGNORESPACE))
+	while (chline[spacecount] == ' ') spacecount++;
+
+    for (i = 0, len = spacecount; i < chwordpos; i += 2) {
 	len += chwords[i+1] - chwords[i]
 	     + (i > 0 && chwords[i] > chwords[i-1]);
     }
     if (chline[len] == '\0')
 	return;

-    for (i = 0, pos = 0; i < chwordpos; i += 2) {
+    for (i = 0, pos = spacecount; i < chwordpos; i += 2) {
 	len = chwords[i+1] - chwords[i];
 	needblank = (i < chwordpos-2 && chwords[i+2] > chwords[i+1]);
 	if (pos != chwords[i]) {
@@ -1044,8 +1047,10 @@
 	    } else
 		save = 0;
 	}
-	if (chwordpos <= 2 || should_ignore_line(prog))
+	if (chwordpos <= 2)
 	    save = 0;
+	else
+	    save = should_ignore_line(prog)? 2 : 1;
     }
     if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) {
 	char *ptr;
@@ -1062,10 +1067,17 @@
 	    save = 0;
 	} else
 	    zsfree(ptr);
+    }
+    if (isset(HISTIGNORESPACE) && (save || *chline == ' ')) {
+	Histent he;
+	for (he = hist_ring; he && he->flags & HIST_FOREIGN;
+	     he = up_histent(he)) ;
+	if (he && he->flags & HIST_TMPSTORE)
+	    freehistnode((HashNode)he);
     }
-    if (save) {
+    if (save == 1 || (save == 2 && !isset(HISTIMMEDIATEDROP))) {
 	Histent he;
-	int keepflags;
+	int newflags;

 	for (he = hist_ring; he && he->flags & hist_skip_flags;
 	     he = up_histent(he)) ;
@@ -1083,6 +1095,7 @@
 	    if (isset(HISTREDUCEBLANKS))
 		histreduceblanks();
 	}
+	newflags = save == 1? 0 : HIST_OLD | HIST_TMPSTORE;
 	if ((isset(HISTIGNOREDUPS) || isset(HISTIGNOREALLDUPS)) && he
 	 && histstrcmp(chline, he->text) == 0) {
 	    /* This history entry compares the same as the previous.
@@ -1090,18 +1103,16 @@
 	     * previous one with the current one.  This also gets the
 	     * timestamp right.  Perhaps, preserve the HIST_OLD flag.
 	     */
-	    keepflags = he->flags & HIST_OLD; /* Avoid re-saving */
+	    newflags |= he->flags & HIST_OLD; /* Avoid re-saving */
 	    freehistdata(he, 0);
 	    curline.histnum = curhist;
-	} else {
-	    keepflags = 0;
+	} else
 	    he = prepnexthistent();
-	}

 	he->text = ztrdup(chline);
 	he->stim = time(NULL);
 	he->ftim = 0L;
-	he->flags = keepflags;
+	he->flags = newflags;

 	if ((he->nwords = chwordpos/2)) {
 	    he->words = (short *)zalloc(chwordpos * sizeof(short));
@@ -1894,8 +1905,10 @@
 	    } else
 		he->words = (short *)NULL;
 	    addhistnode(histtab, he->text, he);
-	    if (hist_ring != he)
-		curhist--; /* We discarded a foreign duplicate */
+	    if (he->flags & HIST_DUP) {
+		freehistnode((HashNode)he);
+		curhist--;
+	    }
 	}
 	if (start && readflags & HFILE_USE_OPTIONS) {
 	    zsfree(lasthist.text);
@@ -1963,7 +1976,8 @@
     if (out) {
 	for (; he && he->histnum <= xcurhist; he = down_histent(he)) {
 	    if ((writeflags & HFILE_SKIPDUPS && he->flags & HIST_DUP)
-	     || (writeflags & HFILE_SKIPFOREIGN && he->flags & HIST_FOREIGN))
+	     || (writeflags & HFILE_SKIPFOREIGN && he->flags & HIST_FOREIGN)
+	     || he->flags & HIST_TMPSTORE)
 		continue;
 	    if (writeflags & HFILE_SKIPOLD) {
 		if (he->flags & HIST_OLD)
Index: Src/options.c
@@ -130,6 +130,7 @@
 {NULL, "histignorealldups",   0,			 HISTIGNOREALLDUPS},
 {NULL, "histignoredups",      0,			 HISTIGNOREDUPS},
 {NULL, "histignorespace",     0,			 HISTIGNORESPACE},
+{NULL, "histimmediatedrop",   0,			 HISTIMMEDIATEDROP},
 {NULL, "histnofunctions",     0,			 HISTNOFUNCTIONS},
 {NULL, "histnostore",	      0,			 HISTNOSTORE},
 {NULL, "histreduceblanks",    0,			 HISTREDUCEBLANKS},
Index: Src/zsh.h
@@ -1252,6 +1252,7 @@
 #define HIST_READ	0x00000004	/* Command was read back from disk*/
 #define HIST_DUP	0x00000008	/* Command duplicates a later line */
 #define HIST_FOREIGN	0x00000010	/* Command came from another shell */
+#define HIST_TMPSTORE	0x00000020	/* Kill when user enters another cmd */

 #define GETHIST_UPWARD  (-1)
 #define GETHIST_DOWNWARD  1
@@ -1367,6 +1368,7 @@
     HISTIGNOREALLDUPS,
     HISTIGNOREDUPS,
     HISTIGNORESPACE,
+    HISTIMMEDIATEDROP,
     HISTNOFUNCTIONS,
     HISTNOSTORE,
     HISTREDUCEBLANKS,
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Proposed history improvements
  2001-05-10  3:36 ` Zefram
  2001-05-10  5:54   ` Wayne Davison
@ 2001-05-10  7:04   ` Bart Schaefer
  2001-05-10 16:11     ` Wayne Davison
  1 sibling, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2001-05-10  7:04 UTC (permalink / raw)
  To: zsh-workers

On May 9,  3:45pm, Wayne Davison wrote:
} 
} 1. I have gotten in the habit of prefixing certain commands with a space
} that I don't want cluttering up my history.

I've never used hist_ignore_space because I frequently copy-and-paste
commands and I dislike having to be careful about whether I grab any
leading whitespace in the process.

I'd much rather decide after the fact that I didn't want that command
put into the history; for example, I'd expunge all commands involving
typographical errors as soon as I'd had a chance to retrieve them and
fix the error, so that correct commands are never pushed out of the
history file by mistaken ones.

} My change makes an ignored command stick around just until the next
} command is typed.

This is a step in the right direction, at least.

} Do you think something like this should require a separate option?

No, I don't think it needs an option ... I think it should have worked
like this all along.

On May 10,  4:36am, Zefram wrote:
} Subject: Re: Proposed history improvements
}
} Wayne Davison wrote:
} >2. I thought it would be cool if I could hint to the history system
} >about which lines I consider more important.  With HIST_DEPRECATE_SPACE
} ...
} 
} This bit is getting too complicated. [...]  We can have a shell
} function that gets called whenever a line is added to the history,
} which gets to reply a number saying how important the line is.
[...]
} Or probably a better way would be to have a virtual associative array
} giving this importance number for each history element [...]

I agree that the proposed "deprecate" options are getting a bit complex,
and that some sort of shell-code solution seems preferable (this assoc
array suggestion would even let me implement deprecate-ex-post-facto).

With the assoc, we could avoid calling a function every time the history
is modified, and simply fix it up by assigning directly to the parameter
from precmd, which is a nice safe time and place to do it with respect
to other commands the shell is executing.

We'd need a better way to get at the current and previous event numbers,
though.  (Have a look at the hack I did in zsh-workers/10996.)

} Actually almost the whole history mechanism *could* be moved out of
} the C [a]nd into shell code.

This would take quite a lot of work; emulating linked lists and rings
in shell code is messy at best.

(13.5% of all zsh options are related to history.  14.3% if Wayne goes
ahead with committing HIST_IMMEDIATE_DROP, on which I have no comment
except to say I think it's extraneous.)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Proposed history improvements
  2001-05-10  5:54   ` Wayne Davison
@ 2001-05-10  9:00     ` Peter Stephenson
  2001-05-10 16:59       ` Andrej Borsenkow
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2001-05-10  9:00 UTC (permalink / raw)
  To: Zsh hackers list

Wayne wrote:
> After I test this for a while longer, I'd be comfortable committing this
> to CVS.  If we're further along in the release cycle where that wouldn't
> be a good idea, let me know.

Better leave it out for now.  If curses has decided to work we may be able
to release what we now have (plus inet_*) in a few days.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Proposed history improvements
  2001-05-10  7:04   ` Bart Schaefer
@ 2001-05-10 16:11     ` Wayne Davison
  2001-05-11  9:55       ` Sven Wischnowsky
  0 siblings, 1 reply; 8+ messages in thread
From: Wayne Davison @ 2001-05-10 16:11 UTC (permalink / raw)
  To: zsh-workers

On Thu, 10 May 2001, Bart Schaefer wrote:
> I'd much rather decide after the fact that I didn't want that command
> put into the history; for example, I'd expunge all commands involving
> typographical errors as soon as I'd had a chance to retrieve them and
> fix the error, so that correct commands are never pushed out of the
> history file by mistaken ones.

Yeah, I was thinking about that too, but I hadn't decided on a good way
to do it yet.  I'm thinking that it might be nice to have a "delete this
history line" key sequence, and perhaps a combination of that with "...
and accept this line".  Such a command would immediately remove the line
out of the internal history, and if we're incrementally updating the
history file it would have to take steps to ensure that the line was
removed from everyone else reading the history file (such as adding the
line with a flag after the timestamp, and leaving the flag-line around
long enough that we assume all shells have read in the removal
instruction -- this is kinda tricky and might not be 100% effective).

> [...] HIST_IMMEDIATE_DROP, on which I have no comment except to say I
> think it's extraneous.)

I have no strong opinion either way, except to say that I will never use
HIST_IMMEDIATE_DROP.  Anyone else care to weigh in on this?

..wayne..


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Proposed history improvements
  2001-05-10  9:00     ` Peter Stephenson
@ 2001-05-10 16:59       ` Andrej Borsenkow
  0 siblings, 0 replies; 8+ messages in thread
From: Andrej Borsenkow @ 2001-05-10 16:59 UTC (permalink / raw)
  To: Zsh hackers list


> 
> Better leave it out for now.  If curses has decided to work we may be able
> to release what we now have (plus inet_*) in a few days.
> 

inet_* stuff commited.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Proposed history improvements
  2001-05-10 16:11     ` Wayne Davison
@ 2001-05-11  9:55       ` Sven Wischnowsky
  0 siblings, 0 replies; 8+ messages in thread
From: Sven Wischnowsky @ 2001-05-11  9:55 UTC (permalink / raw)
  To: zsh-workers

Wayne Davison wrote:

> ...
> 
> > [...] HIST_IMMEDIATE_DROP, on which I have no comment except to say I
> > think it's extraneous.)
> 
> I have no strong opinion either way, except to say that I will never use
> HIST_IMMEDIATE_DROP.  Anyone else care to weigh in on this?

Dunno how much my opinion weighs but, yes, this feature does indeed
sound interesting to have.

The other one sounds more complicated than what my fingers can handle
without me having to think about it, but maybe I could get used to it.

Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-05-11  9:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-09 22:45 Proposed history improvements Wayne Davison
2001-05-10  3:36 ` Zefram
2001-05-10  5:54   ` Wayne Davison
2001-05-10  9:00     ` Peter Stephenson
2001-05-10 16:59       ` Andrej Borsenkow
2001-05-10  7:04   ` Bart Schaefer
2001-05-10 16:11     ` Wayne Davison
2001-05-11  9:55       ` Sven Wischnowsky

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).