Author Topic: Can't unload macro  (Read 10411 times)

jfilion

  • Community Member
  • Posts: 16
  • Hero Points: 0
Can't unload macro
« on: April 07, 2008, 01:47:33 pm »
I loaded a macro that I wrote using another macro.  In the loading macro, I called the built in "load" macro and then called "save_config".  Now, no matter what I do, I cannot unload that macro.  Is there something that has to be unlocked somehow in order to unload this?

I don't know if this matters, but the path I specified in the load command was slightly malformed.  It had two forward slashes in it.  I have since fixed this and tried reloading the macro with the correct path, but I still can't unload it.

Any help would be greatly appreciated.  I'm really stuck on this.

Thanks,
Joe


Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4791
  • Hero Points: 388
Re: Can't unload macro
« Reply #1 on: April 07, 2008, 02:05:51 pm »
Sounds like the first macro is a batch macro (i.e. it has a defmain). If so, you must use do a _post_call() to save_config. That way, your batch macro gets unload before you attempt to save the configuration.  This is what our hot fix loader does. See hotfix.e --> hotfixDoRestart().

jfilion

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: Can't unload macro
« Reply #2 on: April 07, 2008, 03:32:56 pm »
Hi Clark,

Thanks for the reply.  Neither of my macros are batch macros (although the loader one probably should be).  I added a call to safe_exit (like in hotfix.e) at the end of the loader and reran it.  I still can't unload the loaded macro.  I think something is in a bad state and I don't know how to get it out of that state.

Joe

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Can't unload macro
« Reply #3 on: April 07, 2008, 03:57:47 pm »
A few questions might help clarify the issue:

How are you trying to unload the macro?
What happens when you try to unload the macro?
Is there an error message, and if so what is it?
If there isn't an error message, what are the ways that you discover the macro is not unloaded?

jfilion

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: Can't unload macro
« Reply #4 on: April 07, 2008, 05:08:27 pm »
I've tried unloading the macro from the "Macro->Unload Module..." menu and also by calling the "unload" built in command.  In both cases, I get a dialog box with an exclamation point in it that simply says "Cannot remove module".

Joe

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Can't unload macro
« Reply #5 on: April 07, 2008, 07:53:27 pm »
The help for the _load function has the following paragraph.  (_load is what is getting called under the covers, with a "u" option that causes it to unload instead of load).

If load_option=='U' the modules specified are unloaded. If any of the modules can not be unloaded because they are running, unloading stops and CANT_REMOVE_MODULE_RC is returned. Upon successful completion, 0 is returned.

What does your macro do?  Is it something you can post, so someone can inspect it?  Perhaps it is somehow running and needs to be somehow stopped before it can be removed.  Just a guess, though -- maybe there are other reasons why a module can't be unloaded, I don't know.

jfilion

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: Can't unload macro
« Reply #6 on: April 07, 2008, 08:47:13 pm »
Here is the macro (modified only by replacing my companies name with "MyCompany").  I had loaded and unloaded it several times by hand before I tried loading it programatically.  There's not much to  it.  It just looks for a copyright string when you save a buffer and adds one if you don't have it and want it.

The macro that caused the problem is below this one and is part of a different file.  I was just starting to experiment, so it isn't very pretty (of course, neither is the first macro; oh well).  The thought was to have a way to deploy a set of macros to my co-workers.  I was using the cpyrite macro to experiment with.


#include "slick.sh"

void _cbsave_cpyrite()
{
   _save_pos2(p);

   split(p_buf_name, '/', splitResult);

   if ((search('copyright', '@HI') != 0) &&
       (search('copyright', '-@HI') != 0) &&
       (strcmp(splitResult[1], 'vobs') == 0))
   {
      if (_message_box('Would you like to add a Copyright string to ' :+
                       p_buf_name :+ '?',
                       'Copyright Query',
                       MB_YESNO | MB_ICONQUESTION) == IDYES)
      {
         date = _date('U');
         _str yyyy, mm, dd;
         parse date with mm'/'dd'/'yyyy;
         cpyriteStr = '// Copyright (C) ' :+
                      yyyy :+
                      ' by MyCompany Corporation. All rights reserved.';
         top();
         insert_literal("\n");
         top();
         insert_line(cpyriteStr);
         insert_line('');
         save();
      }
   }
   _restore_pos2(p);
}


----------

from boostrapmacros.e:


#include "slick.sh"


_command void bootstrapmacros()
{
   _str macroPath = get_env('VSLICKCONFIG') :+ 'macros';
   if (file_match(macroPath, 1) == '')
   {
      execute('mkdir ' :+ macroPath);
   }

   // Copy to macro directory if necessary.
   _str fileToCopy = macroPath :+ '/cpyrite.e';
   if (file_match(fileToCopy, 1) != '')
   {
      execute('rm ' :+ fileToCopy);
   }
   commandString = 'cp /Toolkit/util/cpyrite.e ' :+ macroPath;
   execute(commandString);

   // Load macro.
   load(macroPath :+ '/cpyrite.e');

   save_config();
   safe_exit();  // <-- Added this morning after response in this forum.
}

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4791
  • Hero Points: 388
Re: Can't unload macro
« Reply #7 on: April 08, 2008, 03:01:02 pm »
The following can't work:

Code: [Select]
// Load macro.
   load(macroPath :+ '/cpyrite.e');

   save_config();
   safe_exit();  // <-- Added this morning after response in this forum.

At the time you call "save_config()" the macro you loaded is on a reload list and has not been loaded yet.  "load" does not load immediately.  It's a bit like a post call.  The "save_config() and safe_exit()" calls must be done in a post call callback like hotfix.e.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Can't unload macro
« Reply #8 on: April 08, 2008, 06:01:55 pm »
@Clark: Trying to put 2 and 2 together...Am I correct in understanding that you mean the reason the macro can't be unloaded, is because it never actually got loaded in the first place?

@jfilion: You can confirm that the macro isn't loaded by choosing Macro->Unload Module... from the menu, and then look in the listbox to see if your macro is listed.

jfilion

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: Can't unload macro
« Reply #9 on: April 09, 2008, 03:33:44 pm »
@Clark: The macro is loaded and cannot be unloaded.  I can fix the problem you refer to; I will take a closer look at hotfix.e.  But that doesn't get me out of my immediate problem: how do I get out of the bad state that my slickedit install is in?  I'm stuck with a macro loaded.  I certainly don't want to blow away my entire slickedit state and start over.

@chrisant: I am trying to do just what you describe, and it is always loaded.  It fails when I try to unload it.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4791
  • Hero Points: 388
Re: Can't unload macro
« Reply #10 on: April 09, 2008, 03:57:19 pm »
You should be able to use the Macro>Unload menu item to unload your module which you say won't unload.  Then go back to Macro>Unload and verify that the module has been unloaded.  If it was unloaded, it won't appear in the list any more.  You may have already done this but I just want to make sure.  If this doesn't work, I don't think there is any way to fix your problem short of rebuilding your state file.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Can't unload macro
« Reply #11 on: April 09, 2008, 05:59:31 pm »
@jfilion:  I've found it's not much work to maintain a "Reconfig.e" batch script macro that reapplies all my key bindings, settings, colors, reloads my custom macros, etc.  I've had to rebuild my state file a few times (due to my own fault each time) and this has made it a breeze.

If you take snapshot of your vusrdefs.e file every so often it becomes pretty easy to maintain the Reconfig.e script without needing to remember the individual changes you've made.  Whenever you want to update your Reconfig.e script, you can diff the snapshot with the current vusrdefs.e and identify which changes are ones you'd want to reapply during a rebuild.  Er, I suppose you may be able to just run vusrdefs.e, too.  But I like having only my important-and-different-from-default settings spelled out in a file anyway, and it's more reliable than running vusrdefs.e - e.g. in the event the state file needs to be rebuilt due to something that's in vusrdefs.e, or if you realize you goofed up some settings or key bindings.

jfilion

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: Can't unload macro
« Reply #12 on: April 09, 2008, 08:17:47 pm »
@Clark:  I have used the Macro->Unload menu to unload the module.  It always gives me the error.  And when I go back into Macro->Unload, my module is always there.

@chrisant: Thanks for the info.  Not sure what vusrdefs.e is, but I'll look into it.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Can't unload macro
« Reply #13 on: June 20, 2008, 04:51:52 am »
Gah.  Now I'm in the same boat.  I forgot about this thread and wrote a macro to reload some stuff and did exactly the same thing:
I called makeNload on several custom macros, then save_config, then safe_exit.
Now all those macros show up as loaded in the Unload dialog, but none of them can be unloaded.
Nor can they be loaded anymore.

WadeHatler

  • Community Member
  • Posts: 19
  • Hero Points: 0
  • Been using VSlick since the dawn of time
Re: Can't unload macro
« Reply #14 on: February 23, 2009, 08:19:28 pm »
Has anyone ever resolved this problem?  I'm in the same boat, and this thread seems to have just died out.