From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: ring.el patch: new functions member, next, previous, convert-sequence etc. Date: Wed, 10 Oct 2007 14:41:32 -0700 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0061_01C80B4B.A6559B20" X-Trace: sea.gmane.org 1192052524 30437 80.91.229.12 (10 Oct 2007 21:42:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 10 Oct 2007 21:42:04 +0000 (UTC) To: "Emacs-Devel" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 10 23:42:02 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IfjJY-0002eu-Ff for ged-emacs-devel@m.gmane.org; Wed, 10 Oct 2007 23:42:01 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IfjJS-0003BA-My for ged-emacs-devel@m.gmane.org; Wed, 10 Oct 2007 17:41:54 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IfjJO-00039Z-KL for emacs-devel@gnu.org; Wed, 10 Oct 2007 17:41:50 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IfjJM-00035f-K4 for emacs-devel@gnu.org; Wed, 10 Oct 2007 17:41:49 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IfjJM-00035P-Gk for emacs-devel@gnu.org; Wed, 10 Oct 2007 17:41:48 -0400 Original-Received: from agminet01.oracle.com ([141.146.126.228]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IfjJM-0004hf-3X for emacs-devel@gnu.org; Wed, 10 Oct 2007 17:41:48 -0400 Original-Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l9ALfjrD030155 for ; Wed, 10 Oct 2007 16:41:46 -0500 Original-Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id l9AFs1l7028709 for ; Wed, 10 Oct 2007 15:41:45 -0600 Original-Received: from dhcp-4op11-4op12-west-130-35-178-158.us.oracle.com by acsmt351.oracle.com with ESMTP id 3282924651192052488; Wed, 10 Oct 2007 14:41:28 -0700 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-reply-to: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-Detected-Kernel: Linux 2.4-2.6 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:80547 Archived-At: This is a multi-part message in MIME format. ------=_NextPart_000_0061_01C80B4B.A6559B20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > From: Drew Adams Sent: Monday, October 08, 2007 3:25 PM > The attached patch to ring.el provides these new functions: > `ring-convert-sequence-to-ring', > `ring-insert+extend', `ring-remove+insert+extend', > `ring-member', `ring-next', `ring-previous' Sorry; I meant to send the patch, not the patched file - see attached. > Change log: > > 2007-10-08 Drew Adams > > * ring.el: Added functions > ring-convert-sequence-to-ring, ring-insert+extend, > ring-remove+insert+extend, ring-member, ring-next, > ring-previous Here's the Change log in standard format (IIUC): 2007-10-08 Drew Adams * ring.el (ring-convert-sequence-to-ring, ring-insert+extend, ring-remove+insert+extend, ring-member, ring-next, ring-previous): New functions. ------=_NextPart_000_0061_01C80B4B.A6559B20 Content-Type: application/octet-stream; name="ring-2007-10-08a.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ring-2007-10-08a.patch" *** ring-2007-10-08a.el Mon Oct 8 15:13:08 2007=0A= --- ring-patched-2007-10-08a.el Mon Oct 8 15:12:26 2007=0A= ***************=0A= *** 164,169 ****=0A= --- 164,241 ----=0A= (dotimes (var (cadr ring) lst)=0A= (push (aref vect (mod (+ start var) size)) lst))))=0A= =0A= + (defun ring-member (ring item)=0A= + "Return index of ITEM if on RING, else nil. Comparison via `equal'.=0A= + The index is 0-based."=0A= + (let ((ind 0)=0A= + (len (1- (ring-length ring)))=0A= + (memberp nil))=0A= + (while (and (<=3D ind len)=0A= + (not (setq memberp (equal item (ring-ref ring ind)))))=0A= + (setq ind (1+ ind)))=0A= + (and memberp ind)))=0A= + =0A= + (defun ring-next (ring item)=0A= + "Return the next item in the RING, after ITEM.=0A= + Raise error if ITEM is not in the RING."=0A= + (let ((curr-index (ring-member ring item)))=0A= + (unless curr-index (error "Item is not in the ring: `%s'" item))=0A= + (ring-ref ring (ring-plus1 curr-index (ring-length ring)))))=0A= + =0A= + (defun ring-previous (ring item)=0A= + "Return the previous item in the RING, before ITEM.=0A= + Raise error if ITEM is not in the RING."=0A= + (let ((curr-index (ring-member ring item)))=0A= + (unless curr-index (error "Item is not in the ring: `%s'" item))=0A= + (ring-ref ring (ring-minus1 curr-index (ring-length ring)))))=0A= + =0A= + (defun ring-insert+extend (ring item &optional grow-p)=0A= + "Like ring-insert, but if GROW-P is non-nil, then enlarge ring.=0A= + Insert onto ring RING the item ITEM, as the newest (last) item.=0A= + If the ring is full, behavior depends on GROW-P:=0A= + If GROW-P is non-nil, enlarge the ring to accommodate the new item.=0A= + If GROW-P is nil, dump the oldest item to make room for the new."=0A= + (let* ((vec (cdr (cdr ring)))=0A= + (veclen (length vec))=0A= + (hd (car ring))=0A= + (ringlen (ring-length ring)))=0A= + (prog1=0A= + (cond ((and grow-p (=3D ringlen veclen)) ; Full ring. Enlarge = it.=0A= + (setq veclen (1+ veclen))=0A= + (setcdr ring (cons (setq ringlen (1+ ringlen))=0A= + (setq vec (vconcat vec (vector = item)))))=0A= + (setcar ring hd))=0A= + (t (aset vec (mod (+ hd ringlen) veclen) item)))=0A= + (if (=3D ringlen veclen)=0A= + (setcar ring (ring-plus1 hd veclen))=0A= + (setcar (cdr ring) (1+ ringlen))))))=0A= + =0A= + (defun ring-remove+insert+extend (ring item &optional grow-p)=0A= + "`ring-remove' ITEM from RING, then `ring-insert+extend' it.=0A= + This ensures that there is only one ITEM on RING.=0A= + =0A= + If the RING is full, behavior depends on GROW-P:=0A= + If GROW-P is non-nil, enlarge the ring to accommodate the new ITEM.=0A= + If GROW-P is nil, dump the oldest item to make room for the new."=0A= + (let (ind)=0A= + (while (setq ind (ring-member ring item)) (ring-remove ring ind)))=0A= + (ring-insert+extend ring item grow-p))=0A= + =0A= + (defun ring-convert-sequence-to-ring (seq)=0A= + "Convert sequence SEQ to a ring. Return the ring.=0A= + If SEQ is already a ring, return it."=0A= + (if (ring-p seq)=0A= + seq=0A= + (let* ((size (length seq))=0A= + (ring (make-ring size))=0A= + (count 0))=0A= + (while (< count size)=0A= + (if (or (ring-empty-p ring)=0A= + (not (equal (ring-ref ring 0) (elt seq count))))=0A= + (ring-insert-at-beginning ring (elt seq count)))=0A= + (setq count (1+ count)))=0A= + ring)))=0A= + =0A= ;;; provide ourself:=0A= =0A= (provide 'ring)=0A= =0A= Diff finished at Mon Oct 08 15:13:28=0A= ------=_NextPart_000_0061_01C80B4B.A6559B20 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ------=_NextPart_000_0061_01C80B4B.A6559B20--