Skip to content

Instantly share code, notes, and snippets.

@lalawue
Created January 7, 2014 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lalawue/8303150 to your computer and use it in GitHub Desktop.
Save lalawue/8303150 to your computer and use it in GitHub Desktop.
quickly locate C/C++/ObjC function in current buffer
;; for Xcode pragma mark, and C/C++ functions
(require 'anything)
(require 'anything-config)
(defvar anything-c-source-objc-headline
'((name . "Objective-C Headline")
(headline "^[-+@]\\|^#pragma mark")
))
(defvar anything-c-source-c-headline
'((name . "C Headline")
(headline "^[A-Za-z_]+?[ A-Za-z_0-9\*]+[A-Za-z_0-9]+?(")
))
(defvar anything-c-source-cpp-headline
'((name . "Cpp Headline")
(headline "^[A-Za-z_]+?[ A-Za-z_:~0-9\*]+[A-Za-z_0-9]+?(")
))
(defun c-base-mode-headline ()
(interactive)
;; Set to 500 so it is displayed even if all methods are not narrowed down.
(let ((anything-candidate-number-limit 500))
(cond
((eq major-mode 'objc-mode)
(anything-other-buffer '(anything-c-source-objc-headline)
"*ObjC Headline*"))
((eq major-mode 'c++-mode)
(anything-other-buffer '(anything-c-source-cpp-headline)
"*Cpp Headline*"))
((eq major-mode 'c-mode)
(anything-other-buffer '(anything-c-source-c-headline)
"*C Headline*"))
)))
(add-hook
'c-mode-common-hook
(lambda ()
(define-key c-mode-base-map (kbd "M-i") 'c-base-mode-headline)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment