all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* cc-mode Objective C method names
@ 2020-01-01 11:27 Alan Third
  2020-01-01 15:29 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alan Third @ 2020-01-01 11:27 UTC (permalink / raw)
  To: Emacs-Devel devel

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

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.

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.

Thanks!
-- 
Alan Third

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

From 2945f1c6c57eeabdbeb8e7c058070587a9bf4c0a 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-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
+	  (let ((class
+		 (save-excursion
+		   (re-search-backward "@\\(implementation\\|class\\|interface\\)")
+		   (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)
+		   (let ((name ""))
+		     (while (not (looking-at "[{;]"))
+		       (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)))))
+		     name))))
+	    (format "%s[%s %s]" type class name)))
+
 	 (t				; Normal function or initializer.
 	  (when (looking-at c-defun-type-name-decl-key) ; struct, etc.
 	    (goto-char (match-end 0))
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-04 17:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.