From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: cc-mode Objective C method names Date: Sat, 4 Jan 2020 10:48:54 +0000 Message-ID: <20200104104854.GA4009@ACM> References: <20200101112757.GA41966@breton.holly.idiocy.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="191798"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: Emacs-Devel devel To: Alan Third Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 04 11:49:16 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 1ingzb-000ndz-7t for ged-emacs-devel@m.gmane.org; Sat, 04 Jan 2020 11:49:15 +0100 Original-Received: from localhost ([::1]:33092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ingzU-00057I-5a for ged-emacs-devel@m.gmane.org; Sat, 04 Jan 2020 05:49:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38017) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ingzN-00057C-Vn for emacs-devel@gnu.org; Sat, 04 Jan 2020 05:49:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ingzM-0007Rp-BZ for emacs-devel@gnu.org; Sat, 04 Jan 2020 05:49:01 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:32180 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1ingzK-0007Aa-S4 for emacs-devel@gnu.org; Sat, 04 Jan 2020 05:49:00 -0500 Original-Received: (qmail 356 invoked by uid 3782); 4 Jan 2020 10:48:56 -0000 Original-Received: from acm.muc.de (p2E5D57E0.dip0.t-ipconnect.de [46.93.87.224]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 04 Jan 2020 11:48:55 +0100 Original-Received: (qmail 4201 invoked by uid 1000); 4 Jan 2020 10:48:54 -0000 Content-Disposition: inline In-Reply-To: <20200101112757.GA41966@breton.holly.idiocy.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 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:243912 Archived-At: Hello, Alan. On Wed, Jan 01, 2020 at 11:27:57 +0000, Alan Third wrote: > One small annoyance I’ve had with developing Emacs is that the > helpers for filling in the changelog entries don’t work with Objective > C methods. I’ve tried writing a patch to make it work. > For reference, an Objective C class looks something like: > @implementation ClassName > - (int)doSomething > { > /* do that something */ > return 1; > } > - (void)doSomethingTo: (SomeClass *)object with: (int)someParam > { > return; > } > @end > And I think the methods’ names should be written something like: > -[ClassName doSomething] > -[ClassName doSomethingTo:with:] > The ‘-’ means it’s an instance method and a ‘+’ would 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’m not great at Emacs lisp so I > thought it best to run this by the mailing list in case I’ve made any > boneheaded errors. I've got just a few comments to add to Eli's and Stefan's, so .... > Thanks! > -- > Alan Third > >>From 2945f1c6c57eeabdbeb8e7c058070587a9bf4c0a Mon Sep 17 00:00:00 2001 > From: Alan Third > Date: Mon, 30 Dec 2019 16:38:47 +0000 > Subject: [PATCH] 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 | 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 > @@ -2024,6 +2024,36 @@ c-defun-name-1 > (c-backward-syntactic-ws) > (point)))) > + ((looking-at "[-+]\\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\\)") 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 "")) 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 (looking-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 (point)) > + (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).