Author Topic: Calling a macro from alias template  (Read 8310 times)

Kung Foo

  • Community Member
  • Posts: 29
  • Hero Points: 0
Calling a macro from alias template
« on: January 11, 2008, 12:03:43 pm »
How does one call a macro from alias file?
The SlickEdit help says that alias escape sequence "%\m MacroName ArgumentList%" should do the call, but I did not get this to work in 12.0.3.0.

So should e.g. this work in the alias file:

%\m _date%

hs2

  • Senior Community Member
  • Posts: 2757
  • Hero Points: 291
Re: Calling a macro from alias template
« Reply #1 on: January 11, 2008, 12:41:30 pm »
The macro commands used in an alias need to modify the current buffer directly. '_date' just returns a _str to the caller.
This is an example of an alias macro command (see http://community.slickedit.com/index.php?topic=2149.msg8949#msg8949)
Code: [Select]
void add_prefix_and_capitalize_word (_str prefix = '') {
   prev_word(); begin_word();
   _insert_text( prefix );
   select_word();
   cap_selection();
   deselect();
}

For '_date' you'd need sth. like this:
Code: [Select]
_insert_text( _date() );Good luck,
HS2
« Last Edit: January 11, 2008, 12:43:18 pm by hs2 »

Kung Foo

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: Calling a macro from alias template
« Reply #2 on: January 11, 2008, 01:20:51 pm »
Sorry, I'm a newbie, so I need dummy instructions  ;D

So, do I need to create a file like this:
Code: [Select]
#include 'slick.sh'

void _my_date()
   {
   _insert_text( _date() );
   }

..and then add the call of this to my alias file like this:

Code: [Select]
This is the file template..
Current date: %\m _my_date()%

I do not seem to get this working..

hs2

  • Senior Community Member
  • Posts: 2757
  • Hero Points: 291
Re: Calling a macro from alias template
« Reply #3 on: January 11, 2008, 03:05:29 pm »
In the alias you need to specify '-my-date'. Note the translated '_' -> '-'. That was wrong - sorry :(

In add. omit the parens. Calling a macro in an alias follows the same rules as you'd invoke it on SE commandline.
If you want to test your macros on SE cmdline add the '_command' keyword to the global (!) function.
BTW: You should also have a look at The 'Macro Programming' section in the manual and/or the 'Professional SlickEdit' book.
HS2
« Last Edit: January 14, 2008, 09:42:40 am by hs2 »

Kung Foo

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: Calling a macro from alias template
« Reply #4 on: January 14, 2008, 07:06:24 am »
Thanks, that worked (removing the parens)  ;D

David_O

  • Senior Community Member
  • Posts: 152
  • Hero Points: 8
Re: Calling a macro from alias template
« Reply #5 on: January 15, 2008, 03:25:59 pm »
In this case, there is no need for your own macro.  Either of the escape sequences %\d or %\e will insert the date for you.

There are many more escape sequences that you can put in your macros.  See the docs.  In a future release we hope to make these easier to find and use.

Kung Foo

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: Calling a macro from alias template
« Reply #6 on: January 15, 2008, 03:47:13 pm »
In this case, there is no need for your own macro.  Either of the escape sequences %\d or %\e will insert the date for you.

There are many more escape sequences that you can put in your macros.  See the docs.  In a future release we hope to make these easier to find and use.

Yep, I checked the escape sequences. But there was none that matched the format that I needed.
What I'd hope to see is some escape sequence for date which could be configured. I need the format to be "DD-MON-YYYY".

hs2

  • Senior Community Member
  • Posts: 2757
  • Hero Points: 291
Re: Calling a macro from alias template
« Reply #7 on: January 15, 2008, 06:08:49 pm »
I've added this to alias.e to support both date versions:
%\e[-]    Insert the date - format:ddmmyy [yymmdd]
Code: [Select]
         } else if ( code=='%\E' ) {
            // Date
            _str month, day, year;
            parse _date() with month'/'day'/'year;
            if (length(month)<2) month='0'month;
            if (length(day)<2) day='0'day;
            if (length(year)>2) year=substr(year,3);
            // HS2: added 'swap' direction using '-'
            _str ch=substr(after,1,1);
            if ( ch=='-' )
               after=year:+month:+day:+substr(after,2);
            else
               after=day:+month:+year:+after; // HS2-CHG: and use this instead of mmddyy
         } else if ( code=='%\X' ) {
Maybe sth. to add to v13 since it's backwards compatible.
HS2

Kung Foo

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: Calling a macro from alias template
« Reply #8 on: January 16, 2008, 12:54:20 pm »
I've added this to alias.e to support both date versions:
%\e[-]    Insert the date - format:ddmmyy [yymmdd]
...
Maybe sth. to add to v13 since it's backwards compatible.
HS2

Thanks, that sounds nice. It would be nice to see some additions (like this) in future releases of SlickEdit.
One good idea would be to add support for separate escape sequences for year, month and date numbers (perhaps something like %\Y, %\M and %\D). This would enable people to easily do their own format based on these.

I did however already implement my own date generating macro, which I now use in my templates.
Thanks for the very quick support :)

David_O

  • Senior Community Member
  • Posts: 152
  • Hero Points: 8
Re: Calling a macro from alias template
« Reply #9 on: January 16, 2008, 02:38:48 pm »
After reading this thread, I was thinking the same thing, to allow separate day, month, and year escape sequences.

There has to be a balance, though.  If we tried to build an escape sequence for all date formats, we'd rapidly run out of letters.  That's why we have the %\m sequence to accommodate those with specific needs.

The separate day, month, year approach may offer the best balance.

Thanks for the input.

Kung Foo

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: Calling a macro from alias template
« Reply #10 on: January 16, 2008, 03:50:15 pm »
After reading this thread, I was thinking the same thing, to allow separate day, month, and year escape sequences.

The separate day, month, year approach may offer the best balance.

Thanks for the input.

No problem. It's great to get such nice support and get it as fast as this :)