From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Error in C++ mode with Emacs 27.0.90 Date: Sat, 18 Feb 2023 17:52:06 +0000 Message-ID: References: <1385091004.1458082.1585083014184@mail1.libero.it> <2124649786.1598258.1585324562989@mail1.libero.it> <20200328151944.GF7449@ACM> <56971920.1649844.1585416890173@mail1.libero.it> <20200328201057.GH7449@ACM> <3d764ea5-0d60-1070-0d8a-f9820d013033@yandex.ru> <20200329115056.GA5469@ACM> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34081"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Angelo Graziosi , emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Feb 18 18:52:47 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pTROB-0008jw-Bs for ged-emacs-devel@m.gmane-mx.org; Sat, 18 Feb 2023 18:52:47 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTRNo-0006cW-2n; Sat, 18 Feb 2023 12:52:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTRNm-0006cK-Fk for emacs-devel@gnu.org; Sat, 18 Feb 2023 12:52:22 -0500 Original-Received: from mx3.muc.de ([193.149.48.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTRNk-0000l4-Es for emacs-devel@gnu.org; Sat, 18 Feb 2023 12:52:22 -0500 Original-Received: (qmail 24864 invoked by uid 3782); 18 Feb 2023 18:52:07 +0100 Original-Received: from acm.muc.de (p4fe151f6.dip0.t-ipconnect.de [79.225.81.246]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 18 Feb 2023 18:52:07 +0100 Original-Received: (qmail 31654 invoked by uid 1000); 18 Feb 2023 17:52:06 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.5; envelope-from=acm@muc.de; helo=mx3.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:303533 Archived-At: Hello, Dmitry. Forgive me for top-posting, but it's nearly three years ago since you wrote this last post, so I'm not going to chop it up before you've got the context back again. The issue is in imenu, there are certain special cases for calling imenu--create-keymap, and my committed patch fixed one (of two) of the places where this special casing happened. You proposed a patch that would just use (cdr menu) in both places, and reported that that seems to work. I've tried this patch out just now, and doing this omits the entry *Rescan*. I haven't yet worked out precisely why, but it seems the patch needs some refinement. The recipe you gave to throw an error ((setq imenu-use-popup-menu t) etc.) still throws an error. Anyhow, I think it's high time this bug was put to bed, so I intend working on it in the next few days. Clearly this will be a fix for the master branch. -- Alan Mackenzie (Nuremberg, Germany). On Mon, Mar 30, 2020 at 01:32:48 +0300, Dmitry Gutov wrote: > On 29.03.2020 14:50, Alan Mackenzie wrote: > > It seems unlikely that we can get a nested list (in imenu--index-alist) > > with only one element. I have tried creating a C++ buffer with 25 > > functions in it. This gives a simple list of 25 elements. With 26 > > functions, I get a nested alist with two elements. > What's the worst that can happen in this case? We get a nested submenu > with just one element? > > However, in an emacs-lisp-mode buffer, we get things like "Variables" > > and "*Rescan*", but I've not yet succeeded in causing a nested list with > > just one element. I'm not convinced enough that it couldn't happen, > > though. > > > > The latter part of the function looks like this (before my patch): > > > > (let* ((menu (imenu--split-menu index-alist > > (buffer-name))) > > (menu1 (imenu--create-keymap (car menu) > > ========> (cdr (if (< 1 (length (cdr menu))) > > menu > > (car (cdr menu)))) > > 'imenu--menubar-select))) > > (setcdr imenu--menubar-keymap (cdr menu1))))))) > > > > That `if' form has been there since imenu-update-menubar was first > > written by Karl Heuer in 1997 (commit 0a8e8bc63e3). Presumably, it > > really was needed back then. > If you're implying we can get rid of the check and always return (cdr > menu), I say let's try. > >> In any case, imenu--create-keymap is also called from imenu--mouse-menu, > >> which probably needs the same kind of fix. > > > > Possibly. I've not managed to create the same error in > > imenu--mouse-menu, > (setq imenu-use-popup-menu t) > followed by > M-x imenu > did that for me in the example buffer. > > but perhaps it could do with the same correction, > > just in case. What do you think? > Yup. > > Incidentally, that patch from last night was a bit untidy. I think it > > needs cleaning up a bit. > So how about this one? In my very brief testing, it seems to work, both > in the example buffer, and for imenu indices in several bigger files: > diff --git a/lisp/imenu.el b/lisp/imenu.el > index fb8b3de662..809ddd7ed1 100644 > --- a/lisp/imenu.el > +++ b/lisp/imenu.el > @@ -814,9 +814,7 @@ imenu--mouse-menu > (setq index-alist (imenu--split-submenus index-alist)) > (let* ((menu (imenu--split-menu index-alist (or title (buffer-name)))) > (map (imenu--create-keymap (car menu) > - (cdr (if (< 1 (length (cdr menu))) > - menu > - (car (cdr menu))))))) > + (cdr menu)))) > (popup-menu map event))) > (defun imenu-choose-buffer-index (&optional prompt alist) > @@ -912,9 +910,7 @@ imenu-update-menubar > (let* ((menu (imenu--split-menu index-alist > (buffer-name))) > (menu1 (imenu--create-keymap (car menu) > - (cdr (if (< 1 (length (cdr menu))) > - menu > - (car (cdr menu)))) > + (cdr menu) > 'imenu--menubar-select))) > (setcdr imenu--menubar-keymap (cdr menu1)))))))