Author Topic: help, how can i tag this kind of file  (Read 10663 times)

Gilvin

  • Community Member
  • Posts: 86
  • Hero Points: 1
help, how can i tag this kind of file
« on: October 28, 2010, 02:09:36 AM »
I tried to write a macro about this for a month, still no clue.

the format is like this:

Code: [Select]
/=#
#include "BiosInfo.uni"

#string SYS_INFO_STR_TITLE                 #language eng  "System Information"
                                           #language fra  "Informations systeme"
                                           #language spa  "Informacion del sistema"
#string SYS_INFO_STR_NOTE_BOOK_MODEL       #language eng  "Notebook Model"
                                           #language fra  "Modele de portable"
                                           #language spa  "Modelo de portatil"
#string STR_ENTER_REBOOT_TEXT              #language eng   "ENTER - Reboot the system"
                                           #language fra   "Entree - Redemarrer le systeme"
                                           #language spa   "Intro: reiniciar el sistema"

and i want to tag those STR_xxxx symbols, because .c file will not directly include these files, these files are binded after compile, so if a .c file do a function like

Code: [Select]
string_token (SYS_INFO_STR_TITLE);
i could find the write symbol like

Code: [Select]
SYS_INFO_STR_TITLE    #language eng "System Information"
really frustrated, i read all the context tagging macro tutorial but still can not do this....

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: help, how can i tag this kind of file
« Reply #1 on: October 28, 2010, 11:47:23 PM »
It's probably easier to create an index of these files yourself if all you want to do is jump to the "definition".

Another way is to translate the string files into something that looks like C/C++  e.g. replace "string" with define.  Every time you save one of the string files you could run the translator.  See the save_file function in saveload.e

Graeme


chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: help, how can i tag this kind of file
« Reply #2 on: October 29, 2010, 05:04:59 AM »
C files will only look up tags from other C language files.

So if you write a custom language tag parser, C files won't "see" the tags from those custom language files.

I think you posted about this a while back, but I may have misled you, because I did not understand that you wanted the custom language tags to be "seen" by C files.  SlickEdit treats tags as specific only to the language that generated them.  This is also a problem with Windows Resource files (.RC), at least up through v14 -- I haven't tried v15 yet, maybe v15 improves that.

Gilvin

  • Community Member
  • Posts: 86
  • Hero Points: 1
Re: help, how can i tag this kind of file
« Reply #3 on: November 01, 2010, 02:02:35 AM »
hi chrisant, i tried v15 trail version but still no improvement, thanks :)

Dennis

  • Senior Community Member
  • Posts: 3960
  • Hero Points: 517
Re: help, how can i tag this kind of file
« Reply #4 on: August 16, 2011, 02:56:37 PM »
This is a quick tutorial on how to add tagging support for a custom configuration file in 30 minutes or less.  The code example is specific to the customer's actual example, but easily adapted (by changing the regular expression for searching) to match your own file format.  Hope this helps.

Step 1:  Define a language mode for the file, let's call it "stringfile"
            Tools > Options... > Language Manager > Add New Language...

Step 2:  Create a new color coding lexer for the language.
            Define #string and #language as Keywords in the color coding.
            Turn on support for recognizing double quoted strings
            Define the identifier regex.

Step 3:  Set up your tab settings so it will be easier to edit these files.

Step 4:  Create a new module "stringfile.e" and add this function.  Then Module > Load Module...

Step 5:  Open one of the string files and look at the Defs tool window to see if it is indexed and color coded as you'd expect.

Step 5:  Add all the "stringfile" files to your workspace tag file.  Now your workspace tag file will be a mixed language tag file, so any tagging operation you do in C++ code will also see the symbols defined in the stringfiles.


Code: [Select]
int stringfile_proc_search(_str &proc_name,boolean find_first)
{
   int status=0;
   if ( find_first ) {
      if ( proc_name:=='') {
          proc_name = _clex_identifier_re();
      }
      status=search('^[ \t]*\#string:b\c{'proc_name'}[ \t]','@rhi');
   } else {
      status=repeat_search();
   }
   if ( status ) {
      return(status);
   }
   get_line(auto line);
   parse line with . proc_name;
   proc_name = tag_tree_compose_tag(proc_name, "", "const");
   return(0);
}

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: help, how can i tag this kind of file
« Reply #5 on: August 16, 2011, 09:57:30 PM »
Step 5:  Add all the "stringfile" files to your workspace tag file.  Now your workspace tag file will be a mixed language tag file, so any tagging operation you do in C++ code will also see the symbols defined in the stringfiles.

Awesome, thanks.  It sounds like mixed language support exists now -- is there a way to get auto complete to work in .RC files?  Typing "IDC_ST" in a .RC file and hitting Ctrl+Space still has no effect for me in a Windows project.  Hopefully I'm missing a setting or something.

Dennis

  • Senior Community Member
  • Posts: 3960
  • Hero Points: 517
Re: help, how can i tag this kind of file
« Reply #6 on: August 17, 2011, 02:08:51 PM »
Add this function as a user macro.  I'm also adding it to the next release of SlickEdit.  If the RC file is in your project or workspace, then it will get tagged, even though it won't have any symbols.  That will make the workspace tag file a cross-language tag file with RC files and your C/C++ source code together, which will enable completion in your RC file.

Code: [Select]
_str rc_proc_search(_str &proc_name,boolean find_first)
{
   return "";
}


chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: help, how can i tag this kind of file
« Reply #7 on: August 17, 2011, 04:41:44 PM »
Thanks, Dennis -- it works beautifully, perfect!  ++hp

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: help, how can i tag this kind of file
« Reply #8 on: August 17, 2011, 08:02:43 PM »
This is really nice Dennis. Although I don't have to work with rc files very often but I also missed the smart editing features I'm used to.
HS2

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: help, how can i tag this kind of file
« Reply #9 on: August 28, 2011, 05:24:51 AM »
Add this function as a user macro.  I'm also adding it to the next release of SlickEdit.  If the RC file is in your project or workspace, then it will get tagged, even though it won't have any symbols.  That will make the workspace tag file a cross-language tag file with RC files and your C/C++ source code together, which will enable completion in your RC file.

Code: [Select]
_str rc_proc_search(_str &proc_name,boolean find_first)
{
   return "";
}

Ran into a probem with this tonight:

In a CPP file, I clicked on a symbol IDM_NEWWINDOW that happens to be used in the RC file.  Then I pressed Ctrl+/ to find references.

When the references search reaches the RC file, SE gets a Slick-C stack and an error dialog "Invalid number argument".  Dismissing the error dialog results in the same error dialog popping up again immediately.  It seems to be stuck in an infinite loop (or at least holding Escape for a few minutes remained in the same state).

tagsdb.dll 0x5bdd0390 tag-match-occurrences-in-file(23741,24113,23985,78792,23900,67022,64220,23769,0,0,23829,24120,C:\chrisant\projectdir\ProjectName.vpj,0)
   p_window_id: 142
   p_object: OI_EDITOR
   p_name:
 Slick-C STACK TRACE ******************************
 Created on 8/27/2011 at 22:21:46 (647 ms)
 SlickEdit Version 16.0.2.0 Copyright 1988-2011 SlickEdit Inc.
 Edit module and type "st -f <offset>" to get the
 run-time error position

 error code=-3009
 Invalid number argument

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: help, how can i tag this kind of file
« Reply #10 on: September 06, 2011, 04:36:43 PM »
I had to remove rc_proc_search, because of how often it locks up the editor in an infinite loop of errors (see previous).  Looking forward to a more complete implementation in the next version.