all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Alan Mackenzie <acm@muc.de>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: cc-mode Objective C method names
Date: Sat, 4 Jan 2020 17:09:35 +0000	[thread overview]
Message-ID: <20200104170935.GA68892@breton.holly.idiocy.org> (raw)
In-Reply-To: <20200104104854.GA4009@ACM>

[-- Attachment #1: Type: text/plain, Size: 1612 bytes --]

On Sat, Jan 04, 2020 at 10:48:54AM +0000, Alan Mackenzie wrote:
> Hello, Alan.
> 
> On Wed, Jan 01, 2020 at 11:27:57 +0000, Alan Third wrote:
> > 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?

They can be extremely long, but our code doesn’t tend to have these
very long names.

I’m not sure what we could do to shorten them unless we really don’t
care very much about accuracy. For example we could drop the class
names, but we don’t limit classes to one per file, so we can easily
end up with two classes with the same method name in the same file.
Alternatively we could not list the parameter labels, but we
definitely have methods that only differ by their parameter lists in
Emacs.

FWIW, I’ve not run into any problems so far.

> > 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 ....

I was working through them when I thought of a neater way to do this,
but it’s probably less like the rest of the code in cc mode. Hopefully
it’s OK. Patch attached.
-- 
Alan Third

[-- Attachment #2: v2-0001-Add-ability-to-find-ObjC-method-names.patch --]
[-- Type: text/plain, Size: 1585 bytes --]

From b75a1ac30204d10f395c1885e1ad80692317c94e Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Mon, 30 Dec 2019 16:38:47 +0000
Subject: [PATCH v2] 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 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 0343f9df32..18fb459e40 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -2024,6 +2024,23 @@ c-defun-name-1
 	     (c-backward-syntactic-ws)
 	     (point))))
 
+	 ((and (c-major-mode-is 'objc-mode) (looking-at "[-+]\\s-*("))     ; Objective-C method
+	  ;; Move to the beginning of the method name.
+	  (c-forward-token-2 2 t)
+	  (let* ((class
+		  (save-excursion
+		    (when (re-search-backward
+			   "^\\s-*@\\(implementation\\|class\\|interface\\)\\s-+\\(\\sw+\\)" nil t)
+		      (match-string-no-properties 2))))
+		 (limit (save-excursion (re-search-forward "[;{]" nil t)))
+		 (method (when (re-search-forward "\\(\\sw+:?\\)" limit t)
+			   (match-string-no-properties 1))))
+	    (when (and class method)
+	      ;; Add the parameter labels onto name.  They always end in ':'.
+	      (while (re-search-forward "\\(\\sw+:\\)" limit 1)
+		(setq method (concat method (match-string-no-properties 1))))
+	      (concat "[" class " " method "]"))))
+
 	 (t				; Normal function or initializer.
 	  (when (looking-at c-defun-type-name-decl-key) ; struct, etc.
 	    (goto-char (match-end 0))
-- 
2.24.0


      parent reply	other threads:[~2020-01-04 17:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-01 11:27 cc-mode Objective C method names Alan Third
2020-01-01 15:29 ` Stefan Monnier
2020-01-02 11:02   ` Alan Third
2020-01-01 16:41 ` Eli Zaretskii
2020-01-04 10:48 ` Alan Mackenzie
2020-01-04 11:07   ` HaiJun Zhang
2020-01-04 17:09   ` Alan Third [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200104170935.GA68892@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.