From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: Error in C++ mode with Emacs 27.0.90 Date: Mon, 30 Mar 2020 01:32:48 +0300 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=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="40535"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 Cc: Angelo Graziosi , emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Mar 30 00:33:42 2020 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 1jIgUw-000ASg-5Z for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Mar 2020 00:33:42 +0200 Original-Received: from localhost ([::1]:42346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIgUv-0000OG-7g for ged-emacs-devel@m.gmane-mx.org; Sun, 29 Mar 2020 18:33:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58261) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIgU9-0008Ny-6K for emacs-devel@gnu.org; Sun, 29 Mar 2020 18:32:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIgU8-0003VK-0A for emacs-devel@gnu.org; Sun, 29 Mar 2020 18:32:53 -0400 Original-Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:40123) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIgU7-0003V3-Q7 for emacs-devel@gnu.org; Sun, 29 Mar 2020 18:32:51 -0400 Original-Received: by mail-wm1-x336.google.com with SMTP id a81so19471512wmf.5 for ; Sun, 29 Mar 2020 15:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=uvCU5sTKtED1K6IpM/ZoZdXhTNz6qpIFqPXaYksjIsY=; b=oXJd3VaEuNi0wjDEcpeuX3oa7rvfo8yfyNiuIN5GsUpeJgDv4RAr7wNMuf2REfN48O Yfo5C3INkr7Cd3/I6F7cPg9sSn3AeNzAraNhk/U8x6goChG8cYle0I9XU1AGuWvidsPq Fznh44hQd9f5C12NoNDGoQ5ThRuDLFLwpURpT9T82ROAzrBeJ43hE74cMqGzT1DRJ+ye YqPlG5wohmaFX050V/joHe29ZKOYbRw7nznFtJHfaZFdXIl2bhoGQjCdlntQNx4aaKff QTaojNH8Kde3q6PKFxQGP5szodm1SVdo4xpPaUWOQZWkZ4fEPOef/lyCXDdbOYdKiuVH dGiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=uvCU5sTKtED1K6IpM/ZoZdXhTNz6qpIFqPXaYksjIsY=; b=G+9g5L5v37rlGo/xRmLzkyacCHhl27Lq1hXcyp+PnJBaadyASiseHATTm3qXFbh9Ym b1OIgLakf2BAq8bb6UZVZSjJGlDg1yCuT9D0Q/3st/BVTiaNYxC3EGFXUtpAzDMUB82D QX/vWyKTYJG/sPIMaE0c50LSh0P/RhPZg5/IhBOo0lFhMknUO+KGc8wW2AIM4+hHga1C KqWL2RsKkgQ6aB1essqlZLx/wvy40BJHvUqwBxOr5LPq3q4N3hPer6Opv/DvwbvQTQaT FFQFRt/B0WomtDWlQzq2O5gwTuO1UvCSj1bF9RJNv85xG/UrPdVqQJuR9Vb0cAS6LlJy 17tA== X-Gm-Message-State: ANhLgQ3yujQAY/rdTPOyK4ShEkpD9UwBXJgQKxT6zxfSx1oDCzYQi0o2 wChrBQRls9NBsKmsG5vgOxRp0xLB X-Google-Smtp-Source: ADFU+vu1P3Z+Fk8BuFMxsNWW5ffeJnR0AQMhkyLuyCEgUPcZ3pNNd/j5EQufnD33lZtLaZhypF04AA== X-Received: by 2002:a7b:c4c8:: with SMTP id g8mr10063031wmk.8.1585521170388; Sun, 29 Mar 2020 15:32:50 -0700 (PDT) Original-Received: from [192.168.0.2] ([66.205.73.129]) by smtp.googlemail.com with ESMTPSA id r11sm20284201wrn.24.2020.03.29.15.32.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Mar 2020 15:32:49 -0700 (PDT) In-Reply-To: <20200329115056.GA5469@ACM> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::336 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:245980 Archived-At: 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)))))))