Author Topic: About go to definition or declaration  (Read 2510 times)

frank_lv

  • Community Member
  • Posts: 30
  • Hero Points: 0
About go to definition or declaration
« on: September 12, 2008, 02:07:55 am »
User guide said : Go to Definition navigates to symbol definition (proc) or declaration (proto)

Can I defined a key to go to definition and defined another key to go to symbol declaration

Graeme

  • Senior Community Member
  • Posts: 1981
  • Hero Points: 226
Re: About go to definition or declaration
« Reply #1 on: September 12, 2008, 10:08:34 pm »
User guide said : Go to Definition navigates to symbol definition (proc) or declaration (proto)

Can I defined a key to go to definition and defined another key to go to symbol declaration


yep, you can, but did you know that if you press Ctrl+dot (bound to push-tag) twice it will take you to the "alternate"  -  i.e. definition or declaration  - and pressing Ctrl+dot repeatedly, alternates between definition and declaration.

Anyway, one way to do what you want is record a macro like this

macro menu -> start macro recording
tools -> options -> C/C++ -> context tagging -> check "prefer to go to definition"
close the options dialog
press Ctrl+dot
macro menu -> end macro recording

In the dialog that comes up, enter a name for your macro  e.g. goto_definition, then click "save and bind to key".  The key binding dialog will come up and you can bind to a key.

Now you can record a similar macro but this time for goto declaration.

If you open vusrmacs.e in the editor you'll see something like this

Code: [Select]
   _macro('R',1);
   _SetLanguageOption('c','codehelp','139480940');
   push_tag();

The effect of running this macro is to assign some configuration options for C/C++ language before calling push-tag.  This might actually change some things you don't want changed, plus it works only for C/C++.

To avoid these problems, you need to get the existing configuration flags first, modify them and write them back, like this.

Code: [Select]
#include "slick.sh"

_command goto_definition() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _str ext = _Filename2LangId(_mdi.p_child.p_buf_name);
   int ff = _GetCodehelpFlags(ext);
   ff = ((ff & ~VSCODEHELPFLAG_FIND_TAG_PREFERS_DECLARATION) | VSCODEHELPFLAG_FIND_TAG_PREFERS_DEFINITION);
   _SetLanguageOption(ext,'codehelp',ff);
   push_tag();
}

This also works for all languages.  Note  - this macro actually changes your configuration options for goto def / goto decl preferences.  You can write a similar goto declaration macro that clears the definition flag and sets the declaration flag.

To create the macros, open vusrmacs.e from your configuration folder, add the code and use the load module command on the macro menu to load it.

Graeme

frank_lv

  • Community Member
  • Posts: 30
  • Hero Points: 0
Re: About go to definition or declaration
« Reply #2 on: September 15, 2008, 02:49:58 am »
Yes,You are right.
It is worked so perfect.
Thanks!