Author Topic: Is it possible to record straight through Command Line prompt  (Read 17877 times)

steve-o

  • Community Member
  • Posts: 8
  • Hero Points: 0
Hi:

Have downloaded the trial of SlickEdit - looking for a replacement to CodeWright which I've used for the last ten years. Looks absolutely awesome, and does almost everything I want and more.

One thing I use constantly in CodeWright that I haven't found a way to do yet in SE:

I start recording a macro. Part of the macro I'm recording is an i-search for some value. When I replay the macro, I want SE to use the keystrokes I typed into my i-search as I recorded. Instead, it prompts me with a new input box when I replay (making the point moot that I recorded the macro in the first place).

I am comfortable with a programmatic solution if one exists - or perhaps I have one of the innumerable options set wrong.

Thanks for any help.


Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Is it possible to record straight through Command Line prompt
« Reply #1 on: May 06, 2009, 11:48:59 AM »
What's the point of doing an I-search in a macro if you don't want it to prompt you for the search string.  You could just do a normal search.  Can you explain more about what you're trying to do?

steve-o

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: Is it possible to record straight through Command Line prompt
« Reply #2 on: May 07, 2009, 03:33:51 PM »
Thanks for your reply.

I'll try and explain a little further. I am a c++ programmer, and let's say I create a class with a number of members. For instance:

class foo
{
      (...)
private:
   int32_t         m_nMember1;
   int32_t         m_nMember2;
   int32_t         m_nMember3;

      (etc...)   
}


I will then record a macro to create getters and setters for all the private class members. That macro will search for things like 'm_', parens, and other delimiters during the course of its running. So, by invoking my macro at the beginning of each of my member declarations, I end up with:


{
public:
   int32_t   GetMember1() { return m_nMember1 };
   void SetMember1(int32_t nMember1) { m_nMember1 = nMember1 };

   int32_t   GetMember2() { return m_nMember2 };
   void SetMember2(int32_t nMember2) { m_nMember2 = nMember2 };

   int32_t   GetMember3() { return m_nMember3 };
   void SetMember3(int32_t nMember3) { m_nMember3 = nMember3 };

private
      (...)
   
   int32_t         m_nMember1;
   int32_t         m_nMember2;
   int32_t         m_nMember3;

      (etc...)
      
}



Any procedure where a macro involves searching for something is a candidate for my question. In other words, I want to perform one or more searches druing the recording of the macro, and have those exact same searches repeated on every execution.

Any help is greatly appreciated!!!

Thanks in advance.

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Is it possible to record straight through Command Line prompt
« Reply #3 on: May 07, 2009, 04:05:19 PM »
Have a look at the attached file -- it might do what you are trying to do.
(I didn't write it, I think I found it somewhere in this forum.)

steve-o

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: Is it possible to record straight through Command Line prompt
« Reply #4 on: May 07, 2009, 07:50:12 PM »
Thanks... there are some cool functions there.

But really, what I'm looking for is very simply this:

  While recording a macro, have it record not only my keystrokes into edit buffers, but my keystrokes into the command line prompt as well.

This enables me to record very complex macros through several searches etc.

Thanks ;)

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Is it possible to record straight through Command Line prompt
« Reply #5 on: May 07, 2009, 07:56:12 PM »
Quote
Any procedure where a macro involves searching for something is a candidate for my question. In other words, I want to perform one or more searches druing the recording of the macro, and have those exact same searches repeated on every execution.

I assume you're using i-search because you want to search repeatedly for the m_ prefix.  You can use the search function to do that - by using the W:P option.  Click help -> macro function by category -> search functions -> search   - or on the slick cmd line, type fp search.  The search function will also let you include/exclude words of a certain type  e.g. you can exclude comments from the search or limit the search to comments only etc  - as you can see in the help, the XCS option excludes comments and strings from the search.  If you're using the GUI find/replace dialog, you can select these search options by clicking the color button.  If you record a macro while doing a search, then edit the recorded macro, you'll see what options it generates - the macro will call "find" instead of search but the options are similar.

See also SlickCMacroBestPractices.pdf in the installation docs folder for some tips on macro programming.

If I still haven't understood, you could try asking again...

Graeme

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6862
  • Hero Points: 528
Re: Is it possible to record straight through Command Line prompt
« Reply #6 on: May 07, 2009, 09:37:32 PM »
As you have noticed, you can't record a macro and have it record key strokes when on the command line.  SlickEdit actually does have a key stroke recording mechanism but it is only used for VI emulation and it is limited to the edit window and doesn't currently recording keystrokes typed in the command line. It could be enhanced and exposed as commands for other emulations. This is a subtle difference between macro recording and key stroke recording.  Macro recording is usually better but not always  ;D

Phil Barila

  • Senior Community Member
  • Posts: 745
  • Hero Points: 61
Re: Is it possible to record straight through Command Line prompt
« Reply #7 on: May 07, 2009, 09:52:34 PM »
Pardon my public display of ignorance  :D, but would it not be a relatively simple workaround to modify the recorded macro to contain the appropriate text, save it, reload it, and be done with it?  Not to suggest that it wouldn't be nice to have what the OP asked for ...

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Is it possible to record straight through Command Line prompt
« Reply #8 on: May 08, 2009, 01:02:46 PM »
Pardon my public display of ignorance  :D, but would it not be a relatively simple workaround to modify the recorded macro to contain the appropriate text, save it, reload it, and be done with it?  Not to suggest that it wouldn't be nice to have what the OP asked for ...
... or have the macro prompt for the desired text...

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Is it possible to record straight through Command Line prompt
« Reply #9 on: May 08, 2009, 01:25:29 PM »
Pardon my public display of ignorance  :D, but would it not be a relatively simple workaround to modify the recorded macro to contain the appropriate text, save it, reload it, and be done with it?  Not to suggest that it wouldn't be nice to have what the OP asked for ...
... or have the macro prompt for the desired text...

Well if you record a macro that does an i-search that the OP asked about, you won't get any text in your macro - all you get is a call to i-search(), which prompts for text on the command line when you run the macro.  It looks like the slickedit core calls the _search_ft function each time a key is pressed when i-search is active.  I don't know why you would want to call i-search from a macro though, if you already know what text you're searching for.

Graeme

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Is it possible to record straight through Command Line prompt
« Reply #10 on: May 08, 2009, 01:56:23 PM »
Well if you record a macro that does an i-search that the OP asked about, you won't get any text in your macro - all you get is a call to i-search(), which prompts for text on the command line when you run the macro. 
I meant have the macro pop up a dialog to ask for the text to search for, not call isearch().

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Is it possible to record straight through Command Line prompt
« Reply #11 on: May 08, 2009, 02:04:09 PM »
I think that's a fair request on behalf of the OP, he'd rather have the results of the i-search recorded rather than the action of prompting for i-search.  I certainly can file a Feature Request on that see if it can be improved.  Unfortunately, it's not as easy as jumping to the next occurrence of the typed string.  You can change toggle the search options (ignore case, whole word, regex, forward/backward direction), you can jump to next/prev occurrence, and you can even toggle off Incremental search and just do a prompted search.  (See the help section on Incremental Search for all the options and key sequences to enable them.  So all that has to be accounted for in the recorded macro.

steve-o

  • Community Member
  • Posts: 8
  • Hero Points: 0
Re: Is it possible to record straight through Command Line prompt
« Reply #12 on: May 08, 2009, 04:05:01 PM »
Quote
I don't know why you would want to call i-search from a macro though, if you already know what text you're searching for.

Let me give you another example for how this is very powerful. Lets say I have a .csv file containing rows from a database:

1,"Joe", "Shmoe", "225 Some Rd", "Some City", "NY", "10028"
2,"Jean", "McGoogle", "1 First St NW", "Some Other City", "CA", "91112"

etc....

Now, lets say I want to copy only the cities from my data. I can record a disposable macro which:

  1) searches for the correct quote (the 7th);   
  2) begins a selection on the next character; 
  3) does another search for the next quote;
  4) then copies the selection somewhere else.

I can then repeat this macro I just recorded in a few seconds on every line. Voila! I have my list of cities.

I understand that I could do this programatically, or "why the h*ll didn't I just do 'select city from table' in the first place?", but my point is that there is a good reason I found myself using this feature constantly in CodeWright in "throw-away" macros like the example above.

By the way, I am absolutely loving SE, have about 1000 lines of new macros coded up in the first week of my switch from CodeWright, and (other than this little bump) am doing everything I could do in CW and more!

Great job.


chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Is it possible to record straight through Command Line prompt
« Reply #13 on: May 08, 2009, 05:29:45 PM »
Now, lets say I want to copy only the cities from my data. I can record a disposable macro which:
  1) searches for the correct quote (the 7th);   
  2) begins a selection on the next character; 
  3) does another search for the next quote;
  4) then copies the selection somewhere else.

Certainly.  Searching in a macro is very useful.  The thing that some folks are asking is, is there some reason why incremental search is absolutely required instead of, say, normal search?  Your example is addressed equally well by both i-search and search.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Is it possible to record straight through Command Line prompt
« Reply #14 on: May 09, 2009, 12:28:55 AM »
I sometimes use slickedit to do quite complicated table manipulations by recording a macro which I then edit.  It took me more than a few seconds though (due to the fact that character selection gets "turned off" when you do a search so I had to hunt for something that worked) but just to show that it's possible, I used macro recording to create the following macro which extracts the city string and pastes it at the bottom of the buffer.  I manually added the clear-message() call at the end to get rid of an annoying message that appears on the cmd line.

Not sure if you realise, but macro recording works through quite a few dialogs and menu commands.
To record this macro I did

Ctrl-F  (search for ")
Ctrl-G (6 times)
Cursor right
Search menu -> push bookmark
Ctrl-G
Edit menu -> select -> char
Search menu -> pop bookmark
Ctrl-C
Home
Cursor down
Search menu -> push bookmark
Ctrl-End
Enter
Ctrl-V
Search menu -> pop bookmark

In practice I would probably change push/pop bookmark to save_pos2, restore_pos2 manually.  If you want to allow for embedded quotes in the strings, you have a bit more work to do.

Code: [Select]
_command last_recorded_macro_y() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
   _macro('R',1);
   find('"','I?');
   find_next();
   find_next();
   find_next();
   find_next();
   find_next();
   find_next();
   _end_select('',false,false);
   _deselect();
   execute('push-bookmark');
   find_next();
   execute('select-char');
   execute('pop-bookmark');
   copy_to_clipboard();
   begin_line_text_toggle();
   cursor_down();
   execute('push-bookmark');
   bottom_of_buffer();
   slick_enter();
   paste();
   pop_bookmark();
   clear_message();
}

Graeme