zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: histignoredups done properly
Date: Mon, 12 Aug 1996 14:56:14 +0200	[thread overview]
Message-ID: <199608121256.OAA02157@hydra.ifh.de> (raw)

Here's another largely cosmetic patch, though this one is more likely
to have unpleasant side effects I haven't noticed and should now
probably be delayed until after 3.0 is released.  (I don't think it
*does*, but virtually any code with pointers and history lists
*might*.)

This fixes histignoredups so that only lines which are really
different are stored; insignificant changes in whitespace are not
treated as differences.  Significant whitespace changes, for example
inside quotation marks, are treated as a difference.  The code simply
uses the extent of command line words which is already recorded.

There is one subtlety:  since you may deliberately alter just the
whitespace on a line, for example pruning a space at the end which
resulted from completion, it is the more recent version which is
stored in the history list, replacing the older one.

One consequent change is that the start time in the extended history
now always reflects the start time of the last command, rather than
the start time of the first command of a repeated sequence.  The
previous behaviour is easy to restore if that seems better (it doesn't
to me, but I can see possible arguments for it).

*** Src/hist.c.id	Fri Aug  2 15:07:29 1996
--- Src/hist.c	Mon Aug 12 14:26:51 1996
***************
*** 627,632 ****
--- 627,653 ----
  	histremmed = 1;
  }
  
+ /* compare current line with history entry using only text in words */
+ 
+ /**/
+ int
+ histcmp(Histent he)
+ {
+     int iword, lword;
+     int nwords = chwordpos/2;
+ 
+     if (nwords != he->nwords)
+ 	return 1;
+ 
+     for (iword = 0; iword < 2*nwords; iword += 2)
+ 	if ((lword = chwords[iword+1]-chwords[iword])
+ 	    != he->words[iword+1]-he->words[iword] ||
+ 	    memcmp(he->text+he->words[iword], chline+chwords[iword], lword))
+ 	    return 1;
+ 
+     return 0;
+ }
+ 
  /* say we're done using the history mechanism */
  
  /**/
***************
*** 634,640 ****
  hend(void)
  {
      int flag, save = 1;
!     Histent he;
  
      if (!chline)
  	return 1;
--- 655,661 ----
  hend(void)
  {
      int flag, save = 1;
!     Histent he = NULL;
  
      if (!chline)
  	return 1;
***************
*** 655,665 ****
  		*--hptr = '\0';
  	    } else
  		save = 0;
- 	he = gethistent(curhist - 1);
  	if (!*chline || !strcmp(chline, "\n") ||
- 	    (isset(HISTIGNOREDUPS) && he->text && !strcmp(he->text, chline)) ||
  	    (isset(HISTIGNORESPACE) && spaceflag))
  	    save = 0;
      }
      if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) {
  	char *ptr;
--- 676,701 ----
  		*--hptr = '\0';
  	    } else
  		save = 0;
  	if (!*chline || !strcmp(chline, "\n") ||
  	    (isset(HISTIGNORESPACE) && spaceflag))
  	    save = 0;
+ 	else if (save) {
+ #ifdef DEBUG
+ 	    /* debugging only */
+ 	    if (chwordpos%2) {
+ 		hwend();
+ 		DPUTS(1, "internal:  uncompleted line in history");
+ 	    }
+ #endif
+ 	    /* get rid of pesky \n which we've nulled out:
+ 	     * needed here by HISTIGNOREDUPS code, but needed anyway.
+ 	     */
+ 	    if (!chline[chwords[chwordpos-2]])
+ 		chwordpos -= 2;
+ 	    he = gethistent(curhist - 1);
+ 	    if (isset(HISTIGNOREDUPS) && he->text && !histcmp(he))
+ 		save = 2;
+ 	}
      }
      if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) {
  	char *ptr;
***************
*** 682,697 ****
      curhistent->ftim = 0L;
      curhistent->flags = 0;
      if (save) {
! #ifdef DEBUG
! 	/* debugging only */
! 	if (chwordpos%2) {
! 	    hwend();
! 	    DPUTS(1, "internal:  uncompleted line in history");
  	}
- #endif
- 	/* get rid of pesky \n which we've already nulled out */
- 	if (!chline[chwords[chwordpos-2]])
- 	    chwordpos -= 2;
  	if ((curhistent->nwords = chwordpos/2)) {
  	    curhistent->words =
  		(short *)zalloc(curhistent->nwords*2*sizeof(short));
--- 718,736 ----
      curhistent->ftim = 0L;
      curhistent->flags = 0;
      if (save) {
! 	if (save == 2) {
! 	    /* Don't duplicate history entry, but use the current rather than
! 	     * the previous one, in case minor changes were made to it.
! 	     */
! 	    Histent hold = curhistent;
! 	    zsfree(he->text);
! 	    if (he->nwords)
! 		zfree(he->words, he->nwords*2*sizeof(short));
! 	    curhist--;
! 	    *he = *curhistent;
! 	    curhistent = he;
! 	    hold->text = NULL;
  	}
  	if ((curhistent->nwords = chwordpos/2)) {
  	    curhistent->words =
  		(short *)zalloc(curhistent->nwords*2*sizeof(short));

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


             reply	other threads:[~1996-08-12 13:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-12 12:56 Peter Stephenson [this message]
1996-08-12 19:17 ` hist_strip_spaces (was Re: histignoredups done properly) Wayne Davison
1996-08-12 21:13   ` hist_strip_spaces Wayne Davison
1996-08-13  9:22     ` hist_strip_spaces Wayne Davison
1996-08-13  5:48   ` hist_strip_spaces (was Re: histignoredups done properly) Andrej Borsenkow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199608121256.OAA02157@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).