SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: flethuseo on May 07, 2014, 04:57:04 PM

Title: expanding alias from a macro
Post by: flethuseo on May 07, 2014, 04:57:04 PM
Hi all,

Is it possible to expand an alias in a macro specifying what I want to fill in for the variables:

I have the following alias:
print =
printf("%(col_name)=%%s\n", %(col_name));

I want to somehow tell it to 'expand_alias print "propertyName"', and then it should silently expand the alias on its own without prompting.

Title: Re: expanding alias from a macro
Post by: Graeme on May 08, 2014, 12:04:10 PM
I don't understand what you want to do.  What do you mean by "expand an alias in a macro"?
Title: Re: expanding alias from a macro
Post by: flethuseo on May 08, 2014, 04:59:00 PM
I hope this question clarifies it:
Is it possible to have an alias with parameters execute (expand automatically) when executing a macro?
Title: Re: expanding alias from a macro
Post by: chrisant on May 09, 2014, 07:11:58 AM
SE aliases can specify parameters.
When expanding such an alias, SE prompts the user to supply values for the parameters, which then get inserted into appropriate spots in the alias.

The question is how to skip the prompts, and just supply parameters directly from the SE command line.

SE doesn't currently seem to have a way to do that.  You can examine the source code for the expand_alias2 in macros\alias.e to see how SE goes about prompting and then passing the prompt results downstream to the alias expansion engine.  You might be able to write a macro that handles what expand_alias2 does, but without prompting.  I can't tell offhand how advanced macro programming familiarity that would require, but I would guess it may be "medium" to "advanced".
Title: Re: expanding alias from a macro
Post by: Graeme on May 09, 2014, 10:12:00 AM
Maybe you could write a (brain twisting) macro that mirrors the alias.
This is untested - I don't know what slick will do with \\n.

e.g. alias_print(_str xyz)
{
    _insert_text('printf("' :+ xyz :+ ' = %s\\n", ' :+ xyz :+ ');'  );
}
Title: Re: expanding alias from a macro
Post by: flethuseo on May 13, 2014, 10:52:44 PM
Tried it, no need for the \\n
_command void PrintMacro(_str xyz='xyz')
{
   _insert_text('printf("' :+ xyz :+ ' = %s\n", ' :+ xyz :+ ');'  );
}
Title: Re: expanding alias from a macro
Post by: MindprisM on May 28, 2014, 10:45:50 AM
I have some code for this, but you will have to modify it, hopefully what I paste here won't have too many dependencies. The public function has a osh_ parameter which is like a json string that gets turned into a hash immediately, so you can just swap out that and pass a hash since I won't be providing the code to turn json into hash.

This code needs to reside in alias.e, I think.


Looking at it now, watch the PARMs var, thats the hash, and calls to hash_get_r can be swapped out by direct code to access the hash val.