From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: [PATCH] Fix imenu bug with shared list structure Date: Thu, 25 Sep 2008 16:53:01 -0400 Organization: Merrill Press Message-ID: <200809251653.01990.danc@merrillpress.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1222376019 25285 80.91.229.12 (25 Sep 2008 20:53:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Sep 2008 20:53:39 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 25 22:54:35 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 1Kixqw-0002La-Dv for ged-emacs-devel@m.gmane.org; Thu, 25 Sep 2008 22:54:22 +0200 Original-Received: from localhost ([127.0.0.1]:34017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kixpu-0002sn-5P for ged-emacs-devel@m.gmane.org; Thu, 25 Sep 2008 16:53:18 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kixpk-0002qP-4X for emacs-devel@gnu.org; Thu, 25 Sep 2008 16:53:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kixpi-0002pB-92 for emacs-devel@gnu.org; Thu, 25 Sep 2008 16:53:07 -0400 Original-Received: from [199.232.76.173] (port=37709 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kixpi-0002p7-2Y for emacs-devel@gnu.org; Thu, 25 Sep 2008 16:53:06 -0400 Original-Received: from vpn.merrillpress.com ([64.61.107.78]:33298) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kixph-00022W-Jh for emacs-devel@gnu.org; Thu, 25 Sep 2008 16:53:05 -0400 Original-Received: from pluto.merrillpress.net ([10.136.5.5]) by mars.merrillpress.net with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1Kixpf-00062y-2l for emacs-devel@gnu.org; Thu, 25 Sep 2008 16:53:03 -0400 User-Agent: KMail/1.9.9 X-Face: 9VC; >}hM+`K4j{H4n=pq/!61'7Rt"vEaPUdCwpS'=; @B7Ll,~Q.xb(|A>; 8M[\UzKQi{>Q Iptc6NY\M(0<{W?ob}e/91Y!k|XE:2SA2LU"cni>#Dmw4siEWG7|L9zkOZ\[nQPe9[PG|s P2n_jW\TzsG2N1Z0q:E#NmWU~0i]JE)gqB|4{jCjolaX6)KO[@k\:>01.58.Pk5Nb\5s": R,Q78_s; 6+vLj\V1y(`]\G3("(Y!G^79x}q[4L8w[.qEs|+ZN0R`Hk,>y; d7!SFx%M2M39 y[/Kc!p!:.E3Zx')v*l6IlR Content-Disposition: inline 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:104155 Archived-At: Fixes a subtle bug caused by insufficient care being taken with shared list structure. It involves nested menu items being mysteriously deleted. --- /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)