From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Fix imenu bug with shared list structure Date: Thu, 25 Sep 2008 17:54:48 -0400 Message-ID: References: <200809251653.01990.danc@merrillpress.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1222379706 3841 80.91.229.12 (25 Sep 2008 21:55:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Sep 2008 21:55:06 +0000 (UTC) Cc: emacs-devel@gnu.org To: Daniel Colascione Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 25 23:56:03 2008 connect(): Connection refused 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 1Kiyob-0006LG-VP for ged-emacs-devel@m.gmane.org; Thu, 25 Sep 2008 23:56:02 +0200 Original-Received: from localhost ([127.0.0.1]:35408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KiynZ-00019e-JO for ged-emacs-devel@m.gmane.org; Thu, 25 Sep 2008 17:54:57 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KiynU-000199-OV for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:54:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KiynT-00018l-Eu for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:54:52 -0400 Original-Received: from [199.232.76.173] (port=53352 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KiynT-00018i-5r for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:54:51 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:45379) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KiynS-0002VF-Tu for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:54:51 -0400 Original-Received: from alfajor.home (vpn-132-204-232-232.acd.umontreal.ca [132.204.232.232]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id m8PLsnt6004849; Thu, 25 Sep 2008 17:54:49 -0400 Original-Received: by alfajor.home (Postfix, from userid 20848) id 52B391C136; Thu, 25 Sep 2008 17:54:48 -0400 (EDT) In-Reply-To: <200809251653.01990.danc@merrillpress.com> (Daniel Colascione's message of "Thu, 25 Sep 2008 16:53:01 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3112=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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:104161 Archived-At: > Fixes a subtle bug caused by insufficient care being taken with shared list > structure. It involves nested menu items being mysteriously deleted. Just a note about top-level comments: they should use ";;" rather than ";;;" because ";;;" is used for sectioning. Lots of places use ";;;" for historical reasons, but when you come across them, please change them rather than imitate them. Users of outline-minor-mode will be thankful, Stefan > --- /dev/stdin 2008-09-25 16:51:54.840409301 -0400 > +++ imenu.el 2008-09-25 16:51:36.000000000 -0400 > @@ -483,8 +483,10 @@ > (/ (1- pos) (max (/ total 100) 1)) > (/ (* 100 (1- pos)) (max total 1))))) > -;; Split LIST into sublists of max length N. > -;; Example (imenu--split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8)) > +;;; Split LIST into sublists of max length N. > +;;; Example (imenu--split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8)) > +;;; > +;;; The returned list DOES NOT share structure with LIST > (defun imenu--split (list n) > (let ((remain list) > (result '()) > @@ -504,12 +506,17 @@ > (push (nreverse sublist) result)) > (nreverse result))) > -;;; Split the alist MENULIST into a nested alist, if it is long enough. > -;;; In any case, add TITLE to the front of the alist. > +;;; Split the alist MENULIST into a nested alist, if it is long > +;;; enough. In any case, add TITLE to the front of the alist. If > +;;; IMENU--RESCAN-ITEM is present in MENULIST, it is moved to the > +;;; beginning of the returned alist. > +;;; > +;;; The returned alist DOES NOT share structure with MENULIST. > (defun imenu--split-menu (menulist title) > - (let (keep-at-top tail) > + (let ((menulist (copy-sequence menulist)) > + keep-at-top tail) > (if (memq imenu--rescan-item menulist) > - (setq keep-at-top (cons imenu--rescan-item nil) > + (setq keep-at-top (list imenu--rescan-item) > menulist (delq imenu--rescan-item menulist))) > (setq tail menulist) > (dolist (item tail) > @@ -517,18 +524,22 @@ > (push item keep-at-top) > (setq menulist (delq item menulist)))) > (if imenu-sort-function > - (setq menulist (sort (copy-sequence menulist) imenu-sort-function))) > + (setq menulist (sort menulist imenu-sort-function))) > (if (> (length menulist) imenu-max-items) > (setq menulist > (mapcar > (lambda (menu) > (cons (format "From: %s" (caar menu)) menu)) > (imenu--split menulist imenu-max-items)))) > + > (cons title > (nconc (nreverse keep-at-top) menulist)))) > ;;; Split up each long alist that are nested within ALIST > ;;; into nested alists. > +;;; > +;;; Return a split and sorted copy of ALIST. The returned alist DOES > +;;; NOT share structure with ALIST. > (defun imenu--split-submenus (alist) > (mapcar (function > (lambda (elt)