SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: boaz on November 09, 2011, 10:10:48 am

Title: getting the directory of the macro itself
Post by: boaz on November 09, 2011, 10:10:48 am
in my macro, I need to get the cwd of the macro itself (where the e file resides)
when I do getcwd() I get the directory of the current slickedit project (which is irrelevant to the macro in hand)

What can I  do?
Title: Re: getting the directory of the macro itself
Post by: Graeme on November 09, 2011, 12:11:12 pm
in my macro, I need to get the cwd of the macro itself (where the e file resides)
when I do getcwd() I get the directory of the current slickedit project (which is irrelevant to the macro in hand)

What can I  do?

Have a look at tag_command_html_documentation() in tags.e.  The keybindings dialog uses it when it wants to get the "documentation" for a command.  The name of the command is passed to tag_command_html_documentation().  it looks like it checks for whether the slick c tag file needs rebuilding in the process of getting the cmd doc text.

Graeme
Title: Re: getting the directory of the macro itself
Post by: Dan on November 09, 2011, 01:11:04 pm
Also if you can guarantee the file being run is open, you could use _file_path(p_buf_name).  I do this in my macro that sets my configuration (most of us here have one since we work in so many editors).  Mine actually insures that the file dansetup.e is the current file and then uses that path for some other things.  Very hacky, but works for personal use.
Title: Re: getting the directory of the macro itself
Post by: boaz on November 10, 2011, 08:26:16 am
very nice...
thanx
Title: Re: getting the directory of the macro itself
Post by: boaz on November 28, 2011, 12:24:36 pm
Is there really no way to refer to "my_macro_directory"?
(for instance, I wish to display a bmp with my form and it is in the same directory)
Title: Re: getting the directory of the macro itself
Post by: boaz on November 28, 2011, 12:29:30 pm
Graeme - I looked again in the example in tags.e - I can deduce the name of the macro, not it's original directory...
Title: Re: getting the directory of the macro itself
Post by: Graeme on November 28, 2011, 12:59:20 pm
Graeme - I looked again in the example in tags.e - I can deduce the name of the macro, not it's original directory...

Are you sure?  My understanding of the following code is that _open_temp_view requires a fully qualified pathname - so tag_get_match_info() must be setting that up.  If you can require that your users put the bmp file into their configuration folder or a sub-folder of the configuration folder then you can use _config_path() to get the configuration folder name.


Code: [Select]
   //If we couldn't find the file name in the usual way, try another method.
   if ((fileName == '') && !strieq(extension, 'DLL')) {
      _str tagfiles = '';
      int tagsMatching = -1;
      tagfiles = tags_filename('e', false);
      tagsMatching = find_tag_matches(tagfiles, tagName);
      tag_remove_duplicate_symbol_matches(false, false, false, false);
      VS_TAG_BROWSE_INFO cm;
      tag_browse_info_init(cm);
      int i;
      for (i = 0; i <= tag_get_num_of_matches(); ++i) {
         tag_get_match_info(i, cm);
         if (cm.type_name == 'func') {
            fileName = cm.file_name;
            break;
         }
      }
   }

   //Get the line number the proc is on
   int status = 0;
   int tempWID = 0;
   int origWID = 0;
   boolean bufferExists = false;
   status = _open_temp_view(fileName, tempWID, origWID, '', bufferExists, false,
                            true);
Title: Re: getting the directory of the macro itself
Post by: Dan on November 28, 2011, 02:26:01 pm
If it is not an absolute path, it will be treated relative to the current directory.  So "macros/files.e" might or might not open successfully depending on the current directory of the editor.

In this case (the code from tag_command_html_documentation()), fileName is being set by a path search of the VSLICKMACROS environment variable.  Can you use something like this?  Perform a path_search() of VSLICKMACROS or some other environment variable?  It could be a "private" one that you set in <configPath>/<version>/vslick.ini.
Title: Re: getting the directory of the macro itself
Post by: ShaunIv on January 06, 2012, 09:30:18 pm
I put all of my macros in the per-user macros folder, which is identified by the [apparently undocumented] environment variable SLICKEDITCONFIGVERSION.  You can use get_env('SLICKEDITCONFIGVERSION') to get this path.
Title: Re: getting the directory of the macro itself
Post by: hs2 on January 06, 2012, 11:49:10 pm
@ShaunIv: You should use the _ConfigPath() function.
Not that obvious but documented (Help>Index: File_Functions)
HS2
Title: Re: getting the directory of the macro itself
Post by: Graeme on January 07, 2012, 01:55:50 am
I put all of my macros in the per-user macros folder, which is identified by the [apparently undocumented] environment variable SLICKEDITCONFIGVERSION.  You can use get_env('SLICKEDITCONFIGVERSION') to get this path.

That's an oversight in the help file.  SLICKEDITCONFIG is in the help file but the description is incorrect and SLICKEDITCONFIGVERSION is missing.  You can see some of the environment variables slick uses by entering "set" on the slick command line (no quotes) or type "help set" on the slick command line to see what it does.
Title: Re: getting the directory of the macro itself
Post by: boaz on January 09, 2012, 09:58:37 am
configpath is no good for me.
It is an "installer" that copies all the other .e files to CONFIGPATH
currently I'm prompting the user for the folder with the files ("please choose the directory this macro resides in")
pretty  :( but I couldn't find any solution...