From unknown Sun Jun 22 03:52:29 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#46301 <46301@debbugs.gnu.org> To: bug#46301 <46301@debbugs.gnu.org> Subject: Status: 28.0.50; cc-mode: add support for c++ lambda expression Reply-To: bug#46301 <46301@debbugs.gnu.org> Date: Sun, 22 Jun 2025 10:52:29 +0000 retitle 46301 28.0.50; cc-mode: add support for c++ lambda expression reassign 46301 emacs submitter 46301 Utkarsh Singh severity 46301 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Feb 04 13:27:23 2021 Received: (at submit) by debbugs.gnu.org; 4 Feb 2021 18:27:23 +0000 Received: from localhost ([127.0.0.1]:42209 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7jLe-00078C-IM for submit@debbugs.gnu.org; Thu, 04 Feb 2021 13:27:23 -0500 Received: from lists.gnu.org ([209.51.188.17]:45082) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7gpS-0005DR-Mf for submit@debbugs.gnu.org; Thu, 04 Feb 2021 10:46:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7gpS-00008M-DG for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 10:45:58 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:54722) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l7gpO-00054h-GI for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 10:45:57 -0500 Received: by mail-pj1-x102d.google.com with SMTP id m12so1915460pjs.4 for ; Thu, 04 Feb 2021 07:45:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=dYatPbPm6wuU6ExV0W8c1yZUXXeZhTQDIp8awrNHrVE=; b=ME5vWZqW760HA3SMSqryhL9M93/QE3C3BKS9rBZwriFkMC1Fk5R+znTVPtJqkfp2Fe 7SqvyzGSSfi1e6YC7q6Zzr2RBP+qIZ/pN1+loG0sTXrEfGi0GicHQq8czN+8PnP8+Bh5 qe/o/OnpAxqryQeUgufMGv5oeczsi5xZelhpL61zoptx5ergvV5ocjdxe0UsqHnttmlB qeZsrDieXyO+1n6gB6Kpkjh5F0YeYFyX4VaDkToaR5k1ICHQ/sOY/T9b1mQK07bje7hH ivcy+rRWVvzL0s1zxlKrwcxBaiG4vRz+phL7xP+kl5WG4iqNs3WzwYZhfi8/4GyY55ZV wy+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=dYatPbPm6wuU6ExV0W8c1yZUXXeZhTQDIp8awrNHrVE=; b=FgJqvjo14OC4X0Db2cr4Z6hnRa12IzU+bKh/6zQWh8qLfnepPjMBcdVkDs3mdobzcj y+lx5+uTGEOXul21DiwmtrczLXAAo1jcysCCT6lm4U3hVkXKCqpOMx8ATSx1W8bJqhMS Z8qHJdvbEOf5GzMeNhHC0OsEl3un1ViUOKTSMiPD4OcnOD+tZqJb5ttgFjWEzfZ0Xz9+ JburZsrSEvyUxr1/uNDpIqDovLeC3rXOOFp79HIiOJTnABRN7iXP4zEjEEcKhRnKxDSy Z3Rlcx5OB0EjabDaNZF8pI/DW0P/QzDLjh+JxtcLhNU09kLbP328Ca9cQk6IG3OFkVKs Muag== X-Gm-Message-State: AOAM531dJouBMuZHBJh4w9G3ZXRbrY0oDhqVKrRrnYsO6W1bG13Kpyju 8P7bU0MJaZevlg9l0HY0WBQQFbML0eQ= X-Google-Smtp-Source: ABdhPJwIBgu5kAWc9NSwrmGE5P8UjOaQzomRjd4JVWTKReNifhasSTh3MEv+4vpm/sRxff9p5MptpA== X-Received: by 2002:a17:902:8496:b029:e1:5637:2995 with SMTP id c22-20020a1709028496b02900e156372995mr8450889plo.71.1612453550912; Thu, 04 Feb 2021 07:45:50 -0800 (PST) Received: from localhost ([43.230.66.102]) by smtp.gmail.com with ESMTPSA id h4sm6316740pfo.187.2021.02.04.07.45.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 07:45:49 -0800 (PST) From: Utkarsh Singh To: bug-gnu-emacs@gnu.org Subject: 28.0.50; cc-mode: add support for c++ lambda expression Date: Thu, 04 Feb 2021 21:17:22 +0530 Message-ID: <87czxfx2b9.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=utkarsh190601@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Thu, 04 Feb 2021 13:27:21 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.1 (--) --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Hi, This bugs only occurs when we assign lambda expression as default arguments in C++. I know there are better ways of using lambda but I was just playing with both C++ and Emacs on a hobby project. Consider this C++ code: template void bubble_sort(std :: vector &v, bool cmp(T, T)=[](T a, T b){return a < b;}) { bool swapped = true; for(size_t i = 0; i < v.size() && swapped; i++) { swapped = false; for(size_t j = 0; j < v.size()-i; j++){ if(cmp(v[j+1], v[j])) { std::swap(v[j], v[j+1]); swapped=true; } } } } Here cmp takes a lambda as default argument and if in c++-mode if we try using C-M-e(c-end-of-defun) it will get trapped into lambda. To solve this is added c-forward-to-nth ((memq where '(at-function-end outwith-function at-header in-header)) (when (c-syntactic-re-search-forward "{" nil 'eob) (backward-char) (forward-sexp) ;; continue to move sexp if we are looking ) and , (while (looking-at ")\\|,") (c-syntactic-re-search-forward "{" nil 'eob) (backward-char) (forward-sexp)) (setq n (1- n)))) By this I am trying to move forward lambda's which are separated by ',' or ended with ')'. I will also attaching the necessary diff to support the issue. -- Utkarsh Singh --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=cc-cmds.el.diff Content-Transfer-Encoding: quoted-printable Content-Description: support c++ lambda 1970a1971,1976 >=20 > (while (looking-at ")\\|,") > (c-syntactic-re-search-forward "{" nil 'eob) > (backward-char) > (forward-sexp)) >=20 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQFMBAEBCAA2FiEEO/UPT8Dq/qDVNhySSfZAAWYhrHYFAmAcFwoYHHV0a2Fyc2gx OTA2MDFAZ21haWwuY29tAAoJEEn2QAFmIax2LKAH+gP13j5MRGJ3S9KMIU903qWa inrIjV7PdbWBjxQ4k5Nisn5iPkD0VlqtRr04M6qhNc6Osq0Z9Cw1ZXJQuzAZdknl FLvpRbRl8+T3PEp7qHaCsPUvq/xZA4HfZzSIWH4cP57kKY6cqtnI2zJBU9HR1liG 5iBJGBB5Yr2udVtsSNjqIWwmWTWS7aMMgvWDsyysJaU+7EL5Z1mhkti1jPDOCWog EW4AjLZ2wnkA23Sp1r/PCsEYhUvvf8h/7j02VJYDjxpEO9BVfX9SHvsny6u4Gx0r sk99zfjwZMBSNRzPgn1ArrCnYBFdn8cQmSmnzRteg2ttMqLqn+KD0ZbkK/2lomk= =ATIg -----END PGP SIGNATURE----- --==-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 23 14:19:39 2021 Received: (at 46301) by debbugs.gnu.org; 23 Feb 2021 19:19:39 +0000 Received: from localhost ([127.0.0.1]:60552 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lEdDe-0003x0-T2 for submit@debbugs.gnu.org; Tue, 23 Feb 2021 14:19:39 -0500 Received: from colin.muc.de ([193.149.48.1]:11572 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lEdDc-0003wn-Ux for 46301@debbugs.gnu.org; Tue, 23 Feb 2021 14:19:37 -0500 Received: (qmail 60874 invoked by uid 3782); 23 Feb 2021 19:19:29 -0000 Received: from acm.muc.de (p4fe15b08.dip0.t-ipconnect.de [79.225.91.8]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 23 Feb 2021 20:19:29 +0100 Received: (qmail 1248 invoked by uid 1000); 23 Feb 2021 19:19:28 -0000 Date: Tue, 23 Feb 2021 19:19:28 +0000 To: Utkarsh Singh Subject: Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression Message-ID: References: <87czxfx2b9.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87czxfx2b9.fsf@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 46301 Cc: 46301@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, Utkarsh. On Thu, Feb 04, 2021 at 21:17:22 +0530, Utkarsh Singh wrote: > Hi, > This bugs only occurs when we assign lambda expression as default > arguments in C++. I know there are better ways of using lambda but I > was just playing with both C++ and Emacs on a hobby project. > Consider this C++ code: > template > void bubble_sort(std :: vector &v, bool cmp(T, T)=[](T a, T b){return a < b;}) > { > bool swapped = true; > for(size_t i = 0; i < v.size() && swapped; i++) { > swapped = false; > for(size_t j = 0; j < v.size()-i; j++){ > if(cmp(v[j+1], v[j])) { > std::swap(v[j], v[j+1]); > swapped=true; > } > } > } > } > Here cmp takes a lambda as default argument and if in c++-mode if we try > using C-M-e(c-end-of-defun) it will get trapped into lambda. But from the end of that lambda, a further C-M-e takes point to the end of bubble_sort. Why do you think this is a bug? The lambda form is a function, it is at the top level (i.e. not within braces), so why shouldn't C-M-e stop at its end? That's a genuine question, by the way, not a rhetorical one. If anything, the rather unsystematic behaviour of C-M-a near this lambda function is of more concern. And there's the worry that this example will break other places where it's assumed that braces cannot occur in parameter lists. But of all the languages there are, trust C++ to be awkward. ;-) > To solve this is added c-forward-to-nth [ patch received with thanks, but snipped. ] > -- > Utkarsh Singh -- Alan Mackenzie (Nuremberg, Germany). From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 23 23:05:22 2021 Received: (at 46301) by debbugs.gnu.org; 24 Feb 2021 04:05:22 +0000 Received: from localhost ([127.0.0.1]:33025 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lElQP-0002LN-Ue for submit@debbugs.gnu.org; Tue, 23 Feb 2021 23:05:22 -0500 Received: from mail-pl1-f174.google.com ([209.85.214.174]:32864) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lElQO-0002L7-2j for 46301@debbugs.gnu.org; Tue, 23 Feb 2021 23:05:20 -0500 Received: by mail-pl1-f174.google.com with SMTP id d16so424786plg.0 for <46301@debbugs.gnu.org>; Tue, 23 Feb 2021 20:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:cc:date:message-id :mime-version; bh=4xHX6KkLNjEITnOmeZUZKYklM5vzpxXOQdAaTo2dT60=; b=B/j3KS3UgMfM9xHCgVtsAF4WW9pt0x3ps3oj3XFDidm2JGOemRF4IYSKc47vd7THxC /FUCScgrxaLuMWlcp0yywJRNz5IWBRMJ06vbapfXuTVWt4cMWRcNGc1BlxZKjGMnotd9 dUpUUOQKlUDH7KDq1N1da4eZ0XfeZQZFHaeGyyrsNcPrx9J7Yw4YEgUZsydZ3848Hu6z qq56gXInUU1f/JHn22Bwwo8lt51gsmfcxb/1sXzSQQYxSqsuz1/kA9b785lGO5xVb8rb jcysV6G5ieAGaLqNQJ+CSd1D64GYqkcByrR7dc8x/nepT/CvxY9bhtpBO3CvO530lnQa XASA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:cc:date :message-id:mime-version; bh=4xHX6KkLNjEITnOmeZUZKYklM5vzpxXOQdAaTo2dT60=; b=OIlmamNxZBZERUCfEdzgxOWl+sD9EkSoPJ/aDvGzRmEn0uEyaYHan/QfwPSpW7Km3T LjrWqyHqpbTQEF02qymSNS7YG/l5UtUCgxZwuDtU52djoYJx9nvq+WMBe501hmTS1h8s MIkxV5p4HciMCyemxkK+SiH8QMtgNYrAz6qRGk4kkbYD7qMkls3qmMPMKo15cyzRCCK3 3fnGR3ZgidOqilu3JY4r8S6L/YO5H9GWthhLVNKt24RNH+97pDE/ceq1Hnz2MO7uqRZv uGohMSuu/TcQO//eG/QGm1hh9JealWh4D5oXrpPCMCcmAdC2GlOlbLPQe7B/Vr2mraZ6 NLEw== X-Gm-Message-State: AOAM531knH6jgOHQ+sh3bs5O+O8qvyuS2iDhUsPpiOiLuUTSxIGwVwll CQ6CXTMSbjZQWg062LNWCIu5nzi+qA2MLw== X-Google-Smtp-Source: ABdhPJza8v3D8QhNDbT+HvdA0DEKGyL6nTt+gyLGdTOEFRib3GtkwRBVkI9dIKuWistV0HI7YaxEow== X-Received: by 2002:a17:90a:d492:: with SMTP id s18mr2236268pju.37.1614139514182; Tue, 23 Feb 2021 20:05:14 -0800 (PST) Received: from localhost ([103.77.0.122]) by smtp.gmail.com with ESMTPSA id 190sm480510pgh.81.2021.02.23.20.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 20:05:13 -0800 (PST) From: Utkarsh Singh To: Alan Mackenzie Subject: Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression In-Reply-To: References: <87czxfx2b9.fsf@gmail.com> Date: Wed, 24 Feb 2021 09:37:08 +0530 Message-ID: <87y2fe2jo3.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 46301 Cc: 46301@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Alan Mackenzie writes: > But from the end of that lambda, a further C-M-e takes point to the end > of bubble_sort. > > Why do you think this is a bug? The lambda form is a function, it is at > the top level (i.e. not within braces), so why shouldn't C-M-e stop at > its end? That's a genuine question, by the way, not a rhetorical one. I think there was some misunderstanding on my side as I was interpreting c-end-of-defun as c-end-of-*named*-defun. This means I was not considering lambda as an unnamed function but just as a default argument. > If anything, the rather unsystematic behaviour of C-M-a near this lambda > function is of more concern. And there's the worry that this example > will break other places where it's assumed that braces cannot occur in > parameter lists. > > But of all the languages there are, trust C++ to be awkward. ;-) Yes, C++ can get really ugly sometimes. The main moto behind my "feature request" was not solving the problem logically but to be so called "contributor" of GNU Emacs. Apology for that. -- Utkarsh Singh From debbugs-submit-bounces@debbugs.gnu.org Thu Feb 25 15:51:24 2021 Received: (at 46301) by debbugs.gnu.org; 25 Feb 2021 20:51:24 +0000 Received: from localhost ([127.0.0.1]:39453 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lFNbX-0006Ql-Tw for submit@debbugs.gnu.org; Thu, 25 Feb 2021 15:51:24 -0500 Received: from colin.muc.de ([193.149.48.1]:35672 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lFNbU-0006QV-Jw for 46301@debbugs.gnu.org; Thu, 25 Feb 2021 15:51:22 -0500 Received: (qmail 48794 invoked by uid 3782); 25 Feb 2021 20:51:13 -0000 Received: from acm.muc.de (p4fe15c19.dip0.t-ipconnect.de [79.225.92.25]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 25 Feb 2021 21:51:13 +0100 Received: (qmail 1166 invoked by uid 1000); 25 Feb 2021 20:51:13 -0000 Date: Thu, 25 Feb 2021 20:51:12 +0000 To: Utkarsh Singh Subject: Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression Message-ID: References: <87czxfx2b9.fsf@gmail.com> <87y2fe2jo3.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87y2fe2jo3.fsf@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 46301 Cc: 46301@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, Utkarsh. On Wed, Feb 24, 2021 at 09:37:08 +0530, Utkarsh Singh wrote: > Alan Mackenzie writes: > > But from the end of that lambda, a further C-M-e takes point to the end > > of bubble_sort. > > Why do you think this is a bug? The lambda form is a function, it is at > > the top level (i.e. not within braces), so why shouldn't C-M-e stop at > > its end? That's a genuine question, by the way, not a rhetorical one. > I think there was some misunderstanding on my side as I was interpreting > c-end-of-defun as c-end-of-*named*-defun. This means I was not > considering lambda as an unnamed function but just as a default > argument. I've looked into a bit more, and come to the conclusion that this behaviour really is a bug. At least C-M-a/e don't recognize other C++ lambda functions as functions, so it shouldn't with this one in the parameter list, either. Besides, lambda functions in C++ are typically short, so the need for C-M-a/e to work on them seems less than the annoyance just moving 1 or 2 lines would cause. > > If anything, the rather unsystematic behaviour of C-M-a near this lambda > > function is of more concern. And there's the worry that this example > > will break other places where it's assumed that braces cannot occur in > > parameter lists. > > But of all the languages there are, trust C++ to be awkward. ;-) > Yes, C++ can get really ugly sometimes. Indeed. > The main moto behind my "feature request" was not solving the problem > logically but to be so called "contributor" of GNU Emacs. Apology for > that. No need to apologize! On the contrary, you've reported a bug, which has led to an improvement in the source code. Without bug reports, CC Mode would not be anywhere near what it is today. I've spent the last couple of days fixing the handling of C-M-a/e in cc-cmds.el. It took rather more than the four line patch you proposed. ;-) Could I ask you, please, to apply the following patch (which should apply cleanly to the Emacs master branch), byte compile cc-cmds.el, load it into Emacs, and test it for me on your real source code. Then please report back whether the bug is in fact fixed, and if not, what is still wrong. In the event you would like help with the patching or byte compiling, feel free to send me private email. Thanks! diff -r 00245e7ea2c5 cc-cmds.el --- a/cc-cmds.el Tue Feb 23 10:58:22 2021 +0000 +++ b/cc-cmds.el Thu Feb 25 20:15:09 2021 +0000 @@ -1621,7 +1621,7 @@ ;; ;; This function might do hidden buffer changes. (save-excursion - (let* (kluge-start + (let* (kluge-start knr-start knr-res decl-result brace-decl-p (start (point)) (paren-state (c-parse-state)) @@ -1652,63 +1652,39 @@ (not (looking-at c-defun-type-name-decl-key)))))) 'at-function-end) (t - ;; Find the start of the current declaration. NOTE: If we're in the - ;; variables after a "struct/eval" type block, we don't get to the - ;; real declaration here - we detect and correct for this later. - - ;;If we're in the parameters' parens, move back out of them. - (if least-enclosing (goto-char least-enclosing)) - ;; Kluge so that c-beginning-of-decl-1 won't go back if we're already - ;; at a declaration. - (if (or (and (eolp) (not (eobp))) ; EOL is matched by "\\s>" - (not (looking-at -"\\([;#]\\|\\'\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s$\\|\\s<\\|\\s>\\|\\s!\\)"))) - (forward-char)) - (setq kluge-start (point)) - ;; First approximation as to whether the current "header" we're in is - ;; one followed by braces. - (setq brace-decl-p - (save-excursion - (and (c-syntactic-re-search-forward "[;{]" nil t t) - (or (eq (char-before) ?\{) - (and c-recognize-knr-p - ;; Might have stopped on the - ;; ';' in a K&R argdecl. In - ;; that case the declaration - ;; should contain a block. - (c-in-knr-argdecl)))))) - (setq decl-result - (car (c-beginning-of-decl-1 - ;; NOTE: If we're in a K&R region, this might be the start - ;; of a parameter declaration, not the actual function. - ;; It might also leave us at a label or "label" like - ;; "private:". - (and least-enclosing ; LIMIT for c-b-of-decl-1 - (c-safe-position least-enclosing paren-state))))) - - ;; Has the declaration we've gone back to got braces? - (if (or (eq decl-result 'label) - (looking-at c-protection-key)) - (setq brace-decl-p nil)) - - (cond - ((or (eq decl-result 'label) ; e.g. "private:" or invalid syntax. - (= (point) kluge-start)) ; might be BOB or unbalanced parens. - 'outwith-function) - ((eq decl-result 'same) - (if brace-decl-p - (if (eq (point) start) - 'at-header + (if (and least-enclosing + (eq (char-after least-enclosing) ?\()) + (c-go-list-forward least-enclosing)) + (c-forward-syntactic-ws) + (setq knr-start (point)) + (if (c-syntactic-re-search-forward "{" nil t t) + (progn + (backward-char) + (cond + ((or (progn + (c-backward-syntactic-ws) + (<= (point) start)) + (and c-recognize-knr-p + (and (setq knr-res (c-in-knr-argdecl)) + (<= knr-res knr-start)))) 'in-header) - 'outwith-function)) - ((eq decl-result 'previous) - (if (and (not brace-decl-p) - (c-in-function-trailer-p)) - 'at-function-end - 'outwith-function)) - (t (error - "c-where-wrt-brace-construct: c-beginning-of-decl-1 returned %s" - decl-result)))))))) + ((and knr-res + (goto-char knr-res) + (c-backward-syntactic-ws))) ; Always returns nil. + ((and (eq (char-before) ?\)) + (c-go-list-backward)) + (c-syntactic-skip-backward "^;" start t) + (if (eq (point) start) + (if (progn (c-backward-syntactic-ws) + (memq (char-before) '(?\; ?} nil))) + (if (progn (c-forward-syntactic-ws) + (eq (point) start)) + 'at-header + 'outwith-function) + 'in-header) + 'outwith-function)) + (t 'outwith-function))) + 'outwith-function)))))) (defun c-backward-to-nth-BOF-{ (n where) ;; Skip to the opening brace of the Nth function before point. If @@ -1730,9 +1707,11 @@ (goto-char (c-least-enclosing-brace (c-parse-state))) (setq n (1- n))) ((eq where 'in-header) - (c-syntactic-re-search-forward "{") - (backward-char) - (setq n (1- n))) + (let ((encl-paren (c-least-enclosing-brace (c-parse-state)))) + (if encl-paren (goto-char encl-paren)) + (c-syntactic-re-search-forward "{" nil t t) + (backward-char) + (setq n (1- n)))) ((memq where '(at-header outwith-function at-function-end in-trailer)) (c-syntactic-skip-backward "^}") (when (eq (char-before) ?\}) @@ -1941,21 +1920,24 @@ ;; The actual movement is done below. (setq n (1- n))) ((memq where '(at-function-end outwith-function at-header in-header)) - (when (c-syntactic-re-search-forward "{" nil 'eob) + (if (eq where 'in-header) + (let ((pos (c-least-enclosing-brace (c-parse-state)))) + (if pos (c-go-list-forward pos)))) + (when (c-syntactic-re-search-forward "{" nil 'eob t) (backward-char) (forward-sexp) (setq n (1- n)))) (t (error "c-forward-to-nth-EOF-\\;-or-}: `where' is %s" where))) - (when (c-in-function-trailer-p) - (c-syntactic-re-search-forward ";" nil 'eob t)) - ;; Each time round the loop, go forward to a "}" at the outermost level. (while (and (> n 0) (not (eobp))) (when (c-syntactic-re-search-forward "{" nil 'eob) (backward-char) (forward-sexp) (setq n (1- n)))) + + (when (c-in-function-trailer-p) + (c-syntactic-re-search-forward ";" nil 'eob t)) n) (defun c-end-of-defun (&optional arg) > -- > Utkarsh Singh -- Alan Mackenzie (Nuremberg, Germany). From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 27 10:45:24 2021 Received: (at 46301) by debbugs.gnu.org; 27 Feb 2021 15:45:24 +0000 Received: from localhost ([127.0.0.1]:45178 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lG1mV-0008FM-W0 for submit@debbugs.gnu.org; Sat, 27 Feb 2021 10:45:24 -0500 Received: from mail-pj1-f46.google.com ([209.85.216.46]:52503) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lG1mT-0008F5-FY for 46301@debbugs.gnu.org; Sat, 27 Feb 2021 10:45:22 -0500 Received: by mail-pj1-f46.google.com with SMTP id e9so5101284pjs.2 for <46301@debbugs.gnu.org>; Sat, 27 Feb 2021 07:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=B4VjVmP8iaf88Cm/TzEpTruPRZMHiAAEIPi+FIu3n70=; b=NQfmmPL89n2JlrrfneLvRgbptRf0WHeoKrYb5/deIQj/geUGJXVicTPH/V65bijk9d zZtKYirNxvIWQCRdrlmjcazMi/cfJHrSYz3rMMrB2tjLyWiGfb7yachh43Jx3Du81eth heQlyZB3pf7Hi6vWtPcoO3Qa0V/Mpiu86xSx0PGMq+7hRuHKhtGsRx7y+IvHg18v04DL 32ggsF4kQ1EQLtCCho4t7QQoZ8Es+g5mWhdWn60MqsclWCpE4A4lhxKO7mF9uagMGmSN An1JxNWfBUBzRALK462eFAceAbHfs7yE5wBxEXnD46gjx2dJl85fFkwBLbSC4bUfK2Jz 9WQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=B4VjVmP8iaf88Cm/TzEpTruPRZMHiAAEIPi+FIu3n70=; b=craU8E6x0iuEX3bTYfwpZZv2PySc+l6hZbNcjLOIw+phk7WkJPgUm3Di6zuCcgB5Fo OOWRG2675eP7IpaxQOLiNmU/aI1lrT4reEYk7bPp2hHe2aBylk6RjDYv/mQsocWgOyTr gYUIYpCjDnf7N+fDEZf4mhORm3qia+ZGLSCwwtGBIwExz+CRTEQLXiYchbPp+niIBRnt qMeAgObvpc2hg8ua6qLABqByw+hvQ6hk3tRJr1i/Lw0apS0ydQ2P4ts/6WDr+VVs9xie dhYvYJbHOU9GZRRV4J6z+2T8anKDkP5YW9xYBw4hzk/aLylJBE1UDxDDcBCOAgbbPHxU VaxQ== X-Gm-Message-State: AOAM531ck8Sy7TPtzL7Z+GLX30DXgvFFHxWm1Qzpb7rcNUaXEemRxb2/ QQMQWt8zTeRC1S0OUnb/VDs+dpJ8cG0= X-Google-Smtp-Source: ABdhPJwmq/FjYuzIHF4TsyOx9z8SBy65dymcuZpOnsXLTFVzsZVj65SulXwvB7NcC5jtE/SyvjPq3A== X-Received: by 2002:a17:90a:7d0a:: with SMTP id g10mr8756796pjl.3.1614440715165; Sat, 27 Feb 2021 07:45:15 -0800 (PST) Received: from localhost ([103.77.0.48]) by smtp.gmail.com with ESMTPSA id j5sm11806312pgl.55.2021.02.27.07.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Feb 2021 07:45:14 -0800 (PST) From: Utkarsh Singh To: Alan Mackenzie , 46301@debbugs.gnu.org Subject: Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression In-Reply-To: References: <87czxfx2b9.fsf@gmail.com> <87y2fe2jo3.fsf@gmail.com> Date: Sat, 27 Feb 2021 21:17:11 +0530 Message-ID: <87v9ad4io0.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 46301 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Alan Mackenzie writes: > I've spent the last couple of days fixing the handling of C-M-a/e in > cc-cmds.el. It took rather more than the four line patch you proposed. > ;-) Could I ask you, please, to apply the following patch (which should > apply cleanly to the Emacs master branch), byte compile cc-cmds.el, load > it into Emacs, and test it for me on your real source code. Then please > report back whether the bug is in fact fixed, and if not, what is still > wrong. In the event you would like help with the patching or byte > compiling, feel free to send me private email. > Thanks now issue is fixed and code itself looks pretty solid. Due to my in-experience in Elisp and comprehensive cc-mode library I was unable to deep dive into the patch but I have a questions about it: Why non-interactive functions of cc-mode doesn't provide doc-string? -- Utkarsh Singh From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 01 14:34:37 2021 Received: (at 46301-done) by debbugs.gnu.org; 1 Mar 2021 19:34:37 +0000 Received: from localhost ([127.0.0.1]:50848 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGoJR-0002X1-56 for submit@debbugs.gnu.org; Mon, 01 Mar 2021 14:34:37 -0500 Received: from colin.muc.de ([193.149.48.1]:13171 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lGoJO-0002Wm-Lb for 46301-done@debbugs.gnu.org; Mon, 01 Mar 2021 14:34:35 -0500 Received: (qmail 74117 invoked by uid 3782); 1 Mar 2021 19:34:28 -0000 Received: from acm.muc.de (p4fe15d36.dip0.t-ipconnect.de [79.225.93.54]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 01 Mar 2021 20:34:27 +0100 Received: (qmail 8717 invoked by uid 1000); 1 Mar 2021 19:34:27 -0000 Date: Mon, 1 Mar 2021 19:34:27 +0000 To: Utkarsh Singh Subject: Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression Message-ID: References: <87czxfx2b9.fsf@gmail.com> <87y2fe2jo3.fsf@gmail.com> <87v9ad4io0.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87v9ad4io0.fsf@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 46301-done Cc: 46301-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, Utkarsh. On Sat, Feb 27, 2021 at 21:17:11 +0530, Utkarsh Singh wrote: > Alan Mackenzie writes: > > I've spent the last couple of days fixing the handling of C-M-a/e in > > cc-cmds.el. It took rather more than the four line patch you proposed. > > ;-) Could I ask you, please, to apply the following patch (which should > > apply cleanly to the Emacs master branch), byte compile cc-cmds.el, load > > it into Emacs, and test it for me on your real source code. Then please > > report back whether the bug is in fact fixed, and if not, what is still > > wrong. In the event you would like help with the patching or byte > > compiling, feel free to send me private email. > Thanks now issue is fixed and code itself looks pretty solid. Thanks for doing the testing. I've committed the patch to all the relevant places, and I'm closing the bug with this post. > Due to my in-experience in Elisp and comprehensive cc-mode library I was > unable to deep dive into the patch but I have a questions about it: > Why non-interactive functions of cc-mode doesn't provide doc-string? Quite a lot of functions, even non-interactive ones, and variables have a doc string. This means that those functions/variables are available to modes derived from CC Mode, and their interfaces are fixed. The ones without doc strings are regarded as "internal" to CC Mode, and their interfaces can (and do) change at any time. There's a comment to this effect burried in the first few hundred lines of cc-engine.el. A few years ago, an alternative convention started being adopted by Emacs, where a double hypen is used to indicate an "internal" function or variable. > -- > Utkarsh Singh -- Alan Mackenzie (Nuremberg, Germany). From unknown Sun Jun 22 03:52:29 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 30 Mar 2021 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator