From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: should search ring contain duplicates? Date: Thu, 04 May 2006 12:29:56 +0200 Message-ID: <85iromw09n.fsf@lola.goethe.zz> References: <200605030727.k437R2Wx009975@amrm2.ics.uci.edu> <87bqufwbls.fsf@jurta.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1146738630 5671 80.91.229.2 (4 May 2006 10:30:30 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 4 May 2006 10:30:30 +0000 (UTC) Cc: Juri Linkov , dann@ics.uci.edu, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 04 12:30:27 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 1Fbb6I-0005vB-Pp for ged-emacs-devel@m.gmane.org; Thu, 04 May 2006 12:30:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fbb6I-0008GU-3P for ged-emacs-devel@m.gmane.org; Thu, 04 May 2006 06:30:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Fbb67-0008EP-NR for emacs-devel@gnu.org; Thu, 04 May 2006 06:30:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fbb66-0008E3-TB for emacs-devel@gnu.org; Thu, 04 May 2006 06:30:15 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fbb66-0008E0-QL for emacs-devel@gnu.org; Thu, 04 May 2006 06:30:14 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1Fbb6h-0004FU-4t for emacs-devel@gnu.org; Thu, 04 May 2006 06:30:51 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1Fbb65-0002tA-8w; Thu, 04 May 2006 06:30:13 -0400 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id 5FADD1C3ACCD; Thu, 4 May 2006 12:29:56 +0200 (CEST) Original-To: storm@cua.dk (Kim F. Storm) In-Reply-To: (Kim F. Storm's message of "Thu, 04 May 2006 12:12:20 +0200") 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:53888 Archived-At: storm@cua.dk (Kim F. Storm) writes: > storm@cua.dk (Kim F. Storm) writes: > >> I definitely think we need the history-push macro! >> Here is something which works for me: > > .. almost :-) Here is a better version: > > (defmacro history-push (newelt history &optional maxelt) > "Add NEWELT to the history list stored in the symbol HISTORY. > If symbol MAXELT is specified, the maximum length of the history is > specified by the value of that symbol. Otherwise, the maximum history > length is to the value of the `history-length' property on symbol > HISTORY, if set, or to the value of the `history-length' variable. > Remove duplicates of NEWELT unless `history-delete-duplicates' is nil." > (declare (debug (form sexp))) > (unless maxelt > (setq maxelt `(or (get ',history 'history-length) > history-length))) > `(let ((len ,maxelt)) > (if history-delete-duplicates > (setq ,history (delete ,newelt ,history))) > (setq ,history (cons ,newelt ,history)) > (when (integerp len) > (if (= 0 len) > (setq ,history nil) > (if (> (length ,history) len) > (setcdr (nthcdr (1- len) ,history) nil)))))) What is the rationale for making this a macro? It's not performance relevant, and not short. Seems like something (defun history-push (newelt history &optional maxelt) "Add NEWELT to the history list stored in the symbol HISTORY. If symbol MAXELT is specified, the maximum length of the history is specified by the value of that symbol. Otherwise, the maximum history length is to the value of the `history-length' property on symbol HISTORY, if set, or to the value of the `history-length' variable. Remove duplicates of NEWELT unless `history-delete-duplicates' is nil." (unless maxelt (setq maxelt (or (get history 'history-length) history-length))) (if history-delete-duplicates (set history (delete newelt (symbol-value history)))) (set history (cons newelt (symbol-value history))) (when (integerp maxelt) (if (= 0 maxelt) (set history nil) (if (> (length (symbol-value history)) maxelt) (setcdr (nthcdr (1- maxelt) (symbol-value history)) nil))))) Sure, you need to quote history in the call then, but it seems like the trouble for a macro is not really warranted. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum