Developer's Blog

Display a list of file methods and jump with Emacs – Objective-C

In Xcode there is a jump bar for jumping to files or methods on top of the editor. In Emacs, moving files is really easy, but moving by method is done using isearch which is a little bit of bother.
As you are using Emacs, why not try making something that isn’t there to start with!

Easily create with “anything”

There is a function called “headline” in anything-config.el.
You can use this to display lines that match a specified regular expression by using “anything”.
This is the code.

(require 'anything)
(require 'anything-config)

(defvar anything-c-source-objc-headline
  '((name . "Objective-C Headline")
    (headline  "^[-+@]\\|^#pragma mark")))

(defun objc-headline ()
  (interactive)
  ;; Set to 500 so it is displayed even if all methods are not narrowed down.
  (let ((anything-candidate-number-limit 500))
    (anything-other-buffer '(anything-c-source-objc-headline)
                           "*ObjC Headline*")))

In Xcode, this becomes the separator, and #pragma mark is set to display.
The class construction can be checked just like that making it really easy to write neat codes.
There are also functions in the jump bar, but writing them with regular expressions is quite difficult so I haven’t included any functions in this elisp. You shouldn’t have any trouble as there is no need to write many C functions.

Because you can put this to use if you just know some regular expressions, I recommend using the “anything” headline.

Please join us on Facebook for Sleipnir for Windows!


Please follow us on Twitter!

Facebook Comments