0

In semantic; to move around function declarations it is possible to use C-c , J to open declaration, and just C-u C-SPC to return where the function was called. However to map those functions to some other short keybindings like that M-right (meaning alt key in combination with right arrow), so in our .emacs we can have:

(define-key global-map [(M-right)] 'semantic-complete-jump).

This indeed works because C-c , J is mapped to invoke the semantic-complete-jump function.

So two questions:

  1. How to map M-left to the C-u C-SPC? remembering that C-u is not a part of the command, it is just the argument passed to the invoked function.

  2. Is there any way to invoke semantic-complete-jump via C-c , J without being interactive and using by default always the default value (that it is mainly the word under where is the cursor)? This will allow to avoid one additional keystroke moving much faster around the code.

This is possible to do with M-. (mapped to find-tag) and M-* (mapped to pop-tag-mark) playing with tags and etags with emacs, but using semantic it seems to be much more powerful and ideal for big projects with large amount of code.

S̲o̲ ̲t̲h̲e̲ ̲p̲r̲e̲v̲i̲o̲u̲s̲ ̲t̲w̲o̲ ̲q̲u̲e̲s̲t̲i̲o̲n̲s̲ ̲w̲h̲a̲t̲ ̲a̲r̲e̲ ̲a̲s̲k̲i̲n̲g̲ ̲i̲s̲: what configuration lines are needed just to use M-right to move inside the function declarations (without being asked) and M-left to go to the previous point were this function was called using semantic.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Borja Tarraso
  • 863
  • 2
  • 12
  • 20

1 Answers1

1

Here's what I've got:

(add-hook
 'c-mode-common-hook
 (lambda()
   (define-key c-mode-base-map
       (kbd "C-x C-h") 'semantic-ia-fast-jump)))

(global-set-key
 (kbd "M-p")
 (lambda()(interactive) (set-mark-command 4)))
abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • 1
    It works perfectly :-) only remaining thing is about second question, still asking to where function to jump when I press M-left, I have this: (define-key global-map [(M-left)] 'semantic-complete-jump). How can I modify to automatically take the default value without asking anything and perform the action? – Borja Tarraso Nov 30 '13 at 13:33
  • Well, simply before jumping to function declaration is asking to which function jump, in the minibuffer I have: "Jump to symbol (default name_of_function):". – Borja Tarraso Nov 30 '13 at 17:47
  • You probably still have `semantic-complete-jump` on. That one asks for symbol. You want `semantic-ia-fast-jump` which is in the answer. – abo-abo Nov 30 '13 at 18:38
  • Thanks, now it works amazingly well. It was the keybinding I was using, that it was wrong, but your comment gave me the clue to fix. – Borja Tarraso Nov 30 '13 at 19:39
  • What I saw after testing it a bit more; it is not working well if for example I did with the function printf(), it jumps to the stdio.h, but never return back with the message "no mark set in this buffer". – Borja Tarraso Nov 30 '13 at 19:45
  • 1
    It returns within current buffer. Simply kill stdio.h to return. The point will be at the same spot that you left – abo-abo Nov 30 '13 at 20:17
  • Indeed, but means that if I go through 20 files (quite easy in Linux kernel source e.g.) I need to kill 20 buffers. I assume there should be some way to do this without killing 20 buffers :-) – Borja Tarraso Nov 30 '13 at 21:10
  • Kill 20 buffers or go back 20 times. Is there really a difference? – abo-abo Dec 01 '13 at 08:47
  • Well, could be. If two of those jumps are referring to the same buffers, and we kill the buffer, means we cannot go back anymore. E.g.: if we jump from f1() to f2() to f3(), and f1() and f3() are in the same file, but f2() in different file. When we kill the buffer in f3(), we will go back to f2(), but never possible to go back to f1(), because buffer was already killed (when leaving from f3()). – Borja Tarraso Dec 01 '13 at 09:46