Search code examples
emacsconfiguration-fileskey-bindingskeymapsemacs-semantic

Keymapping in emacs using semantic with interactive functions and default parameters invocation


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.


Solution

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