From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: HaiJun Zhang Newsgroups: gmane.emacs.devel Subject: Re: cc-mode Objective C method names Date: Sat, 4 Jan 2020 19:07:15 +0800 Message-ID: References: <20200101112757.GA41966@breton.holly.idiocy.org> <20200104104854.GA4009@ACM> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="5e1071e9_69454021_4379" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="2718"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Emacs-Devel devel To: Alan Third , Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 04 12:08:15 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1inhHw-0000YE-BD for ged-emacs-devel@m.gmane.org; Sat, 04 Jan 2020 12:08:12 +0100 Original-Received: from localhost ([::1]:33186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1inhHu-0003FK-Iy for ged-emacs-devel@m.gmane.org; Sat, 04 Jan 2020 06:08:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34319) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1inhHL-0002ov-Om for emacs-devel@gnu.org; Sat, 04 Jan 2020 06:07:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1inhHI-0004Et-JP for emacs-devel@gnu.org; Sat, 04 Jan 2020 06:07:34 -0500 Original-Received: from mail-oln040092253098.outbound.protection.outlook.com ([40.92.253.98]:34400 helo=APC01-SG2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1inhHH-0003wU-8j for emacs-devel@gnu.org; Sat, 04 Jan 2020 06:07:32 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N/bZ0PAmqu14psvMQAGBPk0BuE+xpvJ4977V6J+WdrzFQts83Qb8R8L5x4qEuPK5e/TuJbkr2wtWLu0aPjkAHoc+rtbpkh/EDhKR350Rhx7HCnkwprAfvdnAdpZAzILBjc6Vx1ao13VOidSDmWh+vAerQB4QGV9OCbHKUXJ8IsaY+HSBwDpLZ2XdAwq0SX+pd50W7OzoDVnoZXvOxQW/D/4pQxlTVhfXLImgr5zErcX1oaybe0oep5FsmFYqAyh1HxIZDb5hjAxtHIMSbF7E+3W6qTicErg1gYbqvVasdMZsDeMZQdN5CNKX/7OwhPuwpSIqgeEWMn2AyyniGhEsRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qhZgIVItNg3xbRSe2iNHdzUHiTTHnhKsIstX9doSg3k=; b=EtD0E0lv7/8ycZi64DFKCjZhMSYpQA50ZqbwzJ8pgBgyGPNWG5Eb3N3rzu9EvjY9J4B/Z5ncO1TGaSY1axHZz4P6/vXmOOR6KMxxn8rKXHUGz2uvpdtOYEvK2E/bQpfiumn+enQcSSDYzSal6rjw8zjdpJKtJ23dy5aa8rgQnMguDtmQxiScwWhSDN1UW/o6rB0fTKCdDPr69ZUJXfsesY3GKFqkw6Yz4IbZyphpIGW9PMi46waZKJH8wT6KiCJW+C3g333Yd8D0NkwEuBk/w2CQ1WNwrXgl7ndVN3F70VVo/cyYI0yQPTfQChknYdRLKwVuZUW+XpEADrX8c3dvww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=outlook.com; dmarc=pass action=none header.from=outlook.com; dkim=pass header.d=outlook.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qhZgIVItNg3xbRSe2iNHdzUHiTTHnhKsIstX9doSg3k=; b=JGQvIqX/z8mE31Mb/u6BdNOZUj8XQT6kTXXu3G3dS35TQq+6IGUicWeUyU7nXdUW9dPZLgGT/NIZgLaZz0jfGgr7/tp1Dc93NDHqEJQmBKspjgB8juotSztYCQRQRWiipcl8azAq2D/UvvSGTXPHTp/oAoLwncUP8X8x/QBuJKqncBUiEoc2eCR47XjzbkhVrp03WgCLlht72h9g8W9mJYffZCGzKJ2K2tycRop5hcnD6wGPw0/0R3VNbw1LfbT9gFOXWwPsWHOJD3ceWlpGXMRMAD1Ywvyu4mmz4Fw4Rx8u+camQRRLClRO5GO82YxYUivmYk+YthG01FTcPRAksA== Original-Received: from HK2APC01FT060.eop-APC01.prod.protection.outlook.com (10.152.248.53) by HK2APC01HT154.eop-APC01.prod.protection.outlook.com (10.152.249.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Sat, 4 Jan 2020 11:07:26 +0000 Original-Received: from PS1PR03MB3606.apcprd03.prod.outlook.com (10.152.248.52) by HK2APC01FT060.mail.protection.outlook.com (10.152.249.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11 via Frontend Transport; Sat, 4 Jan 2020 11:07:26 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:57BD9AD9A4FADC7BDDA317EE6E18E73FE0F391A36850D39A48E072ABC9321BA2; UpperCasedChecksum:BE41790C58653A0952DC83779D1CB2E870EF94C33D661FBCC5613987B2202332; SizeAsReceived:8733; Count:48 Original-Received: from PS1PR03MB3606.apcprd03.prod.outlook.com ([fe80::b470:80bc:efed:9117]) by PS1PR03MB3606.apcprd03.prod.outlook.com ([fe80::b470:80bc:efed:9117%7]) with mapi id 15.20.2623.002; Sat, 4 Jan 2020 11:07:26 +0000 In-Reply-To: <20200104104854.GA4009@ACM> X-Readdle-Message-ID: 951a4191-52ff-4c26-872f-3cb90729759c@Spark X-ClientProxiedBy: HK2PR03CA0049.apcprd03.prod.outlook.com (2603:1096:202:17::19) To PS1PR03MB3606.apcprd03.prod.outlook.com (2603:1096:803:4e::17) X-Microsoft-Original-Message-ID: <951a4191-52ff-4c26-872f-3cb90729759c@Spark> Original-Received: from [192.168.1.103] (1.199.245.197) by HK2PR03CA0049.apcprd03.prod.outlook.com (2603:1096:202:17::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.4 via Frontend Transport; Sat, 4 Jan 2020 11:07:24 +0000 X-Readdle-Message-ID: 951a4191-52ff-4c26-872f-3cb90729759c@Spark X-Microsoft-Original-Message-ID: <951a4191-52ff-4c26-872f-3cb90729759c@Spark> X-TMN: [DlOhWAf4Zz012Z1TyMI4UOEWutEvpfs1] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: e702bdeb-3283-4fab-57bc-08d7910647ec X-MS-TrafficTypeDiagnostic: HK2APC01HT154: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: is0EgRF8oxU6I4B8Jdm1C83aOw8h7wJS/7KCpH25CCzEMFEu1M+bv8arLuPxU6PCH1yJfM+xFD0lfOU/KkeGamxxVZqCT0WTrTL3vGJvS0BUQOnSutlWiWGZiQFKGyY5hTC6ZXVv+KGsyrzskF8dGRa8IJt5aFnKGIshoA8msSJ/ui0zwQ3e3IDbjgnUbook X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e702bdeb-3283-4fab-57bc-08d7910647ec X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2020 11:07:26.1145 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT154 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.92.253.98 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:243913 Archived-At: --5e1071e9_69454021_4379 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline There is a related bug: =2338749. =E5=9C=A8 2020=E5=B9=B41=E6=9C=884=E6=97=A5 +0800 PM6:49=EF=BC=8CAlan Mac= kenzie =EF=BC=8C=E5=86=99=E9=81=93=EF=BC=9A > Hello, Alan. > > On Wed, Jan 01, 2020 at 11:27:57 +0000, Alan Third wrote: > > One small annoyance I=E2=80=99ve had with developing Emacs is that th= e > > helpers for filling in the changelog entries don=E2=80=99t work with = Objective > > C methods. I=E2=80=99ve tried writing a patch to make it work. > > > =46or reference, an Objective C class looks something like: > > > =40implementation ClassName > > > - (int)doSomething > > =7B > > /* do that something */ > > return 1; > > =7D > > > - (void)doSomethingTo: (SomeClass *)object with: (int)someParam > > =7B > > return; > > =7D > > > =40end > > > And I think the methods=E2=80=99 names should be written something li= ke: > > > -=5BClassName doSomething=5D > > -=5BClassName doSomethingTo:with:=5D > > > The =E2=80=98-=E2=80=99 means it=E2=80=99s an instance method and a =E2= =80=98+=E2=80=99 would mean it was a > > class method. > > If either ClassName or doSomethingTo is long, you might be taking up to= o > much space on, for example, the first line of a commit message. But > you've probably already thought this through. How long are these > extended names in practice=3F > > > It appears to work for me, but I=E2=80=99m not great at Emacs lisp so= I > > thought it best to run this by the mailing list in case I=E2=80=99ve = made any > > boneheaded errors. > > I've got just a few comments to add to Eli's and Stefan's, so .... > > > Thanks=21 > > -- > > Alan Third > > > > > =46rom 2945f1c6c57eeabdbeb8e7c058070587a9bf4c0a Mon Sep 17 00:00:= 00 2001 > > =46rom: Alan Third > > Date: Mon, 30 Dec 2019 16:38:47 +0000 > > Subject: =5BPATCH=5D Add ability to find ObjC method names > > > * lisp/progmodes/cc-cmds.el (c-defun-name-1): Add Objective-C method > > name ability. > > --- > > lisp/progmodes/cc-cmds.el =7C 30 ++++++++++++++++++++++++++++++ > > 1 file changed, 30 insertions(+) > > > diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el > > index 0343f9df32..9165398132 100644 > > --- a/lisp/progmodes/cc-cmds.el > > +++ b/lisp/progmodes/cc-cmds.el > > =40=40 -2024,6 +2024,36 =40=40 c-defun-name-1 > > (c-backward-syntactic-ws) > > (point)))) > > > + ((looking-at =22=5B-+=5D=5C=5Cs-*(=22) ; Objective-C method > > I'd be happier here if you could also check we're really in Objc with > (c-major-mode-is 'objc-mode). > > > + (let ((class > > + (save-excursion > > + (re-search-backward =22=40=5C=5C(implementation=5C=5C=7Cclass=5C=5C= =7Cinterface=5C=5C)=22) > > Here, you might want to give a NOERROR argument to re-search-backward, > so that if implementation etc., isn't found, you can handle the error > gracefully. Something like > > (if (re-search-backward =22=40=5C=5C(....=5C=5C)=22 nil t) > (progn > (c-forward-token-2) > .....) > =22=22) > > > + (c-forward-token-2) > > + (thing-at-point 'word t))) > > + (type (buffer-substring-no-properties (point) (+ (point) 1))) > > + (name > > + (save-excursion > > + (c-forward-token-2 2 t) > > c-forward-token-2 might not be the best function, here. It moves to the= > next token, but if there isn't a next token it doesn't move at all. > c-forward-over-token-and-ws might be better. Alternatively, you could > check the result of c-forward-token-2 (say, with zerop) and take specia= l > action if the call has failed. This comment also applies to the later > uses of c-forward-token-2. > > > + (let ((name =22=22)) > > I feel there ought to be a standard CC Mode function which would do the= > following scanning to the =7B, but I can't find it at the moment. > > > + (while (not (looking-at =22=5B=7B;=5D=22)) > > Or, (not (memq (char-after) '(=3F=7B =3F=5C;))), which would be minutel= y faster. > It would also not change the match-data if you cared about that (which > you don't, here). > > > + (let ((start (point)) > > + (end > > + (progn > > + (c-forward-syntactic-ws) > > + (forward-word) > > + (if (looking-at =22:=22) > > + (+ (point) 1) > > + (point))))) > > + (when (looking-at =22:=22) > > + (c-forward-token-2) > > + (if (looking-at =22(=22) > > + (c-forward-token-2 2 t) > > + (c-forward-token-2 1 t))) > > + (c-forward-syntactic-ws) > > + (setq name (concat name (buffer-substring-no-properties start end))= ))) > > Just a small point: isn't name always the empty string before this form= =3F > If so, you could get rid of the concat and just use > buffer-substring-no-properties. > > > + name)))) > > + (format =22%s=5B%s %s=5D=22 type class name))) > > As an alternative to format, you could use (concat type =22=5B=22 class= =22 =22 > name =22=5D=22) > , which is more direct, but probably doesn't matter here. > > > + > > (t ; Normal function or initializer. > > (when (looking-at c-defun-type-name-decl-key) ; struct, etc. > > (goto-char (match-end 0)) > > -- > > 2.24.0 > > -- > Alan Mackenzie (Nuremberg, Germany). > --5e1071e9_69454021_4379 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
There is a related bug: #38749.
=E5=9C=A8 2020=E5=B9=B41=E6=9C=884=E6=97= =A5 +0800 PM6:49=EF=BC=8CAlan Mackenzie <acm@muc.de>=EF=BC=8C=E5= =86=99=E9=81=93=EF=BC=9A
Hello, Alan.

On Wed, Jan 01, 2020 at 11:27:57 +0000, Alan Third wrote:
One small annoyance I= =E2=80=99ve had with developing Emacs is that the
helpers for filling in the changelog entries don=E2=80=99t work with Object= ive
C methods. I=E2=80=99ve tried writing a patch to make it work.

For reference, an Obje= ctive C class looks something like:

@implementation ClassN= ame

- (int)doSomething
{
/* do that something */
return 1;
}

- (void)doSomethingTo:= (SomeClass *)object with: (int)someParam
{
return;
}

@end

And I think the method= s=E2=80=99 names should be written something like:

-[ClassName doSomethin= g]
-[ClassName doSomethingTo:with:]

The =E2=80=98-=E2=80= =99 means it=E2=80=99s an instance method and a =E2=80=98+=E2=80=99 wou= ld mean it was a
class method.

If either ClassName or doSomethingTo is long, you might be taking up too much space on, for example, the first line of a commit message. But
you've probably already thought this through. How long are these
extended names in practice?

It appears to work for= me, but I=E2=80=99m not great at Emacs lisp so I
thought it best to run this by the mailing list in case I=E2=80=99ve made a= ny
boneheaded errors.

I've got just a few comments to add to Eli's and Stefan's, so ....

Thanks!
--
Alan Third

From 2945f1c6c57eeabdb= eb8e7c058070587a9bf4c0a Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Mon, 30 Dec 2019 16:38:47 +0000
Subject: [PATCH] Add ability to find ObjC method names

* lisp/progmodes/cc-cm= ds.el (c-defun-name-1): Add Objective-C method
name ability.
---
lisp/progmodes/cc-cmds.el | 30 +++++++++= ;+++++++++++++++= ;++++++
1 file changed, 30 insertions(+)

diff --git a/lisp/prog= modes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 0343f9df32..9165398132 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -2024,6 +2024,36 @@ c-defun-name-1
(c-backward-syntactic-ws)
(point))))

+ ((looking-at &qu= ot;[-+]\\s-*(") ; Objective-C method

I'd be happier here if you could also check we're really in Objc with
(c-major-mode-is 'objc-mode).

+ (let ((class
+ (save-excursion
+ (re-search-backward "@\\(implementation\\|class\\|interface\\)&q= uot;)

Here, you might want to give a NOERROR argument to re-search-backward,
so that if implementation etc., isn't found, you can handle the error
gracefully. Something like

(if (re-search-backward "@\\(....\\)" nil t)
(progn
(c-forward-token-2)
.....)
"")

+ (c-forward-token= -2)
+ (thing-at-point 'word t)))
+ (type (buffer-substring-no-properties (point) (+ (point) 1)))
+ (name
+ (save-excursion
+ (c-forward-token-2 2 t)

c-forward-token-2 might not be the best function, here. It moves to the
next token, but if there isn't a next token it doesn't move at all.
c-forward-over-token-and-ws might be better. Alternatively, you could
check the result of c-forward-token-2 (say, with zerop) and take special action if the call has failed. This comment also applies to the later
uses of c-forward-token-2.

+ (let ((name &quo= t;"))

I feel there ought to be a standard CC Mode function which would do the
following scanning to the {, but I can't find it at the moment.

+ (while (not (loo= king-at "[{;]"))

Or, (not (memq (char-after) '(?{ ?\;))), which would be minutely faster. It would also not change the match-data if you cared about that (which
you don't, here).

+ (let ((start (po= int))
+ (end
+ (progn
+ (c-forward-syntactic-ws)
+ (forward-word)
+ (if (looking-at ":")
+ (+ (point) 1)
+ (point)))))
+ (when (looking-at ":")
+ (c-forward-token-2)
+ (if (looking-at "(")
+ (c-forward-token-2 2 t)
+ (c-forward-token-2 1 t)))
+ (c-forward-syntactic-ws)
+ (setq name (concat name (buffer-substring-no-properties start end))))= )

Just a small point: isn't name always the empty string before this form? If so, you could get rid of the concat and just use
buffer-substring-no-properties.

+ name))))
+ (format "%s[%s %s]" type class name)))

As an alternative to format, you could use (concat type "[" class= " "
name "]")
, which is more direct, but probably doesn't matter here.

+
(t ; Normal function or initializer.
(when (looking-at c-defun-type-name-decl-key) ; struct, etc.
(goto-char (match-end 0))
--
2.24.0

--
Alan Mackenzie (Nuremberg, Germany).

--5e1071e9_69454021_4379--