Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com May 31 '13 at 5:43

This question came from our site for professional and enthusiast programmers.

    
You may want to search on integrating cscope with Emacs. –  user315052 May 30 '13 at 16:19
    
    
Use helm-semantic-or-iemnu. –  Amumu Apr 20 '14 at 10:14

3 Answers 3

up vote 6 down vote accepted

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

share|improve this answer
    
Exactly it. Thanks. –  Jack May 30 '13 at 16:18
    
Hmm. Seems imenu only searches the current open buffers. Any info on configuring it to search the whole project? –  cevaris Mar 28 at 16:33

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

share|improve this answer
    
Could you post your cscope config? I'm still trying to figure out how to configure it for efficient and streamlined workflow... –  elemakil May 30 '13 at 19:18
    
Yes, edit with config posted... –  Mats Petersson May 30 '13 at 19:26
    
Wait... that's all? Now I feel kinda stupid... :-) –  elemakil May 30 '13 at 20:11

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

share|improve this answer
1  
This is a cool solution! –  katspaugh May 31 '13 at 2:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.