emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: should search ring contain duplicates?


From: Kim F. Storm
Subject: Re: should search ring contain duplicates?
Date: Wed, 03 May 2006 10:26:02 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Dan Nicolaescu <address@hidden> writes:

>           (when history-delete-duplicates
>             (setq regexp-search-ring (delete string regexp-search-ring)))
>           (push string regexp-search-ring)
>           (if (> (length regexp-search-ring) regexp-search-ring-max)
>               (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
>                       nil))))

IMO, that would be a very good candidate for a standard macro
in subr.el.  

There are several places which does this (or should do it -- but
actually doesn't get this right!):

   (history-push ELT HIST &optional LENGTH KEEPDUPS)

Default for LENGTH would be history-length, but it should also look at
the history-length property of HIST.

If KEEPDUPS is t, ignore value of history-delete-duplicates.

This would make it easy for Lisp code to do the same history
manipulation as C code:

      if (NILP (histval)
          || (CONSP (histval)
              /* Don't duplicate the most recent entry in the history.  */
              && (keep_all
                  || NILP (Fequal (histstring, Fcar (histval))))))
        {
          Lisp_Object length;

          if (history_delete_duplicates) Fdelete (histstring, histval);
          histval = Fcons (histstring, histval);
          Fset (Vminibuffer_history_variable, histval);

          /* Truncate if requested.  */
          length = Fget (Vminibuffer_history_variable, Qhistory_length);
          if (NILP (length)) length = Vhistory_length;
          if (INTEGERP (length))
            {
              if (XINT (length) <= 0)
                Fset (Vminibuffer_history_variable, Qnil);
              else
                {
                  Lisp_Object temp;

                  temp = Fnthcdr (Fsub1 (length), histval);
                  if (CONSP (temp)) Fsetcdr (temp, Qnil);
                }
            }
        }


-- 
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]