Author Topic: expanding alias from a macro  (Read 3246 times)

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
expanding alias from a macro
« 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.


Graeme

  • Senior Community Member
  • Posts: 2422
  • Hero Points: 320
Re: expanding alias from a macro
« Reply #1 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"?

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Re: expanding alias from a macro
« Reply #2 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?

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: expanding alias from a macro
« Reply #3 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".
« Last Edit: May 09, 2014, 05:15:51 pm by chrisant »

Graeme

  • Senior Community Member
  • Posts: 2422
  • Hero Points: 320
Re: expanding alias from a macro
« Reply #4 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 :+ ');'  );
}

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Re: expanding alias from a macro
« Reply #5 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 :+ ');'  );
}

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
Re: expanding alias from a macro
« Reply #6 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.