Author Topic: getting the directory of the macro itself  (Read 8004 times)

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
getting the directory of the macro itself
« 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?

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: getting the directory of the macro itself
« Reply #1 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

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: getting the directory of the macro itself
« Reply #2 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.

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: getting the directory of the macro itself
« Reply #3 on: November 10, 2011, 08:26:16 AM »
very nice...
thanx

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: getting the directory of the macro itself
« Reply #4 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)

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: getting the directory of the macro itself
« Reply #5 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...

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: getting the directory of the macro itself
« Reply #6 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);

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: getting the directory of the macro itself
« Reply #7 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.

ShaunIv

  • Community Member
  • Posts: 10
  • Hero Points: 1
Re: getting the directory of the macro itself
« Reply #8 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.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: getting the directory of the macro itself
« Reply #9 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

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: getting the directory of the macro itself
« Reply #10 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.

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: getting the directory of the macro itself
« Reply #11 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...