How to quickly navigate/jump between functions on emacs?

How to quickly navigate/jump between functions on emacs? I'm looking for a way to jump quickly to functions on emacs. I'm using the emacs search to do it,but it's too slow and fail. For example,I need to make sure to type a string that will not match to function prototype or function call. I need to include the type of function and begging of parameters type to it.. and depending to coding syntax style used in the program,it's hard/inviable to do. What exactly I'm looking for: something that I type just the function name and jump to begging of it. My current language is C on linux. But if there's such feature to another programming languages and platforms,please show me too. Will be very appreciated.

Please: don't suggest "use an IDE" I'm fine with emacs.

3

3 Answers

M-x imenu lets you jump to functions in the same file. I have bound it to Super-i for easy access.

2

I have been using cscope integrated into Emacs, and it works really well for searching for functions, variables etc and jumping around between them.

Edit: in .emacs (or .xemacs/init.el) I have:

(require 'xcscope)
(setq cscope-do-not-update-database t)

Then I just manually run cscope on the source files as needed (for the Linux kernel, make cscope, which also works on many other large projects).

3

As already suggested by others I also use Imenu exclusively to navigate in the buffer. I find it very useful to do that by having ido interface for Imenu. here is my config for ido-imenu. (this is slightly modified version from the function you find it emacswiki page)

(defun ido-imenu () "Update the imenu index and then use ido to select a symbol to navigate to.
Symbols matching the text at point are put first in the completion list." (interactive) (imenu--make-index-alist) (let ((name-and-pos '()) (symbol-names '())) (flet ((addsymbols (symbol-list) (when (listp symbol-list) (dolist (symbol symbol-list) (let ((name nil) (position nil)) (cond ((and (listp symbol) (imenu--subalist-p symbol)) (addsymbols symbol)) ((listp symbol) (setq name (car symbol)) (setq position (cdr symbol))) ((stringp symbol) (setq name symbol) (setq position (get-text-property 1 'org-imenu-marker symbol)))) (unless (or (null position) (null name)) (add-to-list 'symbol-names name) (add-to-list 'name-and-pos (cons name position)))))))) (addsymbols imenu--index-alist)) ;; If there are matching symbols at point, put them at the beginning ;; of `symbol-names'. (let ((symbol-at-point (thing-at-point 'symbol))) (when symbol-at-point (let* ((regexp (concat (regexp-quote symbol-at-point) "$")) (matching-symbols (delq nil (mapcar (lambda (symbol) (if (string-match regexp symbol) symbol)) symbol-names)))) (when matching-symbols (sort matching-symbols (lambda (a b) (> (length a) (length b)))) (mapc (lambda (symbol) (setq symbol-names (cons symbol (delete symbol symbol-names)))) matching-symbols))))) (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names)) (position (cdr (assoc selected-symbol name-and-pos)))) (push-mark) (if (overlayp position) (goto-char (overlay-start position)) (goto-char position)))))
(global-set-key (kbd "C-x C-i") 'ido-imenu)

And I can use C-xC-i in many number of languages modes that support imenu

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like