From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: should search ring contain duplicates? Date: Wed, 03 May 2006 10:26:02 +0200 Message-ID: References: <200605030727.k437R2Wx009975@amrm2.ics.uci.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1146644904 29793 80.91.229.2 (3 May 2006 08:28:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 3 May 2006 08:28:24 +0000 (UTC) Cc: Emacs-Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 03 10:28:21 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FbCiN-0002JL-BL for ged-emacs-devel@m.gmane.org; Wed, 03 May 2006 10:28:07 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FbCiM-0001lX-OX for ged-emacs-devel@m.gmane.org; Wed, 03 May 2006 04:28:06 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FbCi4-0001iQ-72 for emacs-devel@gnu.org; Wed, 03 May 2006 04:27:48 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FbCi3-0001hp-E9 for emacs-devel@gnu.org; Wed, 03 May 2006 04:27:47 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FbCi3-0001hi-6G for emacs-devel@gnu.org; Wed, 03 May 2006 04:27:47 -0400 Original-Received: from [195.41.46.235] (helo=pfepa.post.tele.dk) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FbCiO-00018M-8V for emacs-devel@gnu.org; Wed, 03 May 2006 04:28:08 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (unknown [80.165.4.124]) by pfepa.post.tele.dk (Postfix) with SMTP id 508C3FAC035; Wed, 3 May 2006 10:27:45 +0200 (CEST) Original-To: Dan Nicolaescu In-Reply-To: <200605030727.k437R2Wx009975@amrm2.ics.uci.edu> (Dan Nicolaescu's message of "Wed, 3 May 2006 00:27:02 -0700") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:53839 Archived-At: Dan Nicolaescu 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 http://www.cua.dk