Author Topic: using macro to insert an incrementing number  (Read 919 times)

akobari

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
using macro to insert an incrementing number
« on: August 14, 2015, 04:35:34 pm »
Hello forum,
I am new to this forum, but I have been using SlickEdit for a while. I am very interested to find a way to add an incrementing number by using SlickEdit macro recording/programming method, like 0.1.2.3.4, to a specific character in a c code: like this:

so each time when I call my macro, it searches the keyword "printf" and then adds a number 0, 1 .. 2 ,etc after "occurrence".
printf("===>  occurance#1");

printf("===>  occurrence#2");

This is very useful to me for debugging, let say I have 100's of these printf() and I do not want to edit the text 100 time to add an incrementing number!!

Thans,

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: using macro to insert an incrementing number
« Reply #1 on: August 14, 2015, 05:19:07 pm »
Just simplified examples:
Code: [Select]
// use 'set-var akobari_print_index' on cmdline / 'Macro>Set Macro Variable' to init
int akobari_print_index = 1;
_command void akobari_insert_print_index()
{
   _insert_text( (_str)akobari_print_index++ );
}

_command void akobari_insert_print_occurance()
{
   _insert_text( 'printf("===>  occurance#':+ (_str)akobari_print_index++ :+ ');');
}

Hope it helps, HS2

akobari

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Re: using macro to insert an incrementing number
« Reply #2 on: August 14, 2015, 06:06:13 pm »
Hello hs2,
That was exactly what I was looking for :), I was not sure if I can use a global variable in MACRO programming, like other languages i.e. C

thank you so much,