Author Topic: SE22 remembering search options from macros, SE21 didn't and I liked it better  (Read 3079 times)

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Attached is a macros file that I use on a daily basis.

One macro I use heavily is:
xsearch-cur-buffer-for-cur-word-now

To use it, highlight a word you want to search for, then execute this macro. It finds all occurrences in the current file and turns on "match case" and "match whole word".

With beta1, when I press "Ctrl+F" to search (I have minifind off) right after I did a search with 'xsearch-cur-buffer-for-cur-word-now', the "match case" and "match whole word" are now highlighted, which is undesirable for me. Before executing the macro, these 2 were unchecked with Ctrl+F on the previous search, and I'd like to keep it that way by default with Ctrl+F.

In v21, it did not retain the "match case" and "match whole word" from my macro, which I liked.

Any way to get back the old behavior, even with a new option? Or just make it like it was before by default?

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
The problem is mark_all_occurences is spelt incorrectly - it should be mark_all_occurrences.
J/K.  The call to save_last_search() in mark_all_occurrences is the problem.  You can get around it by calling xsave_old_search_options() before you call mark_all_occurrences.  Then xrestore after.  You actually only need to save/ restore old_search_options but you might as well do all of them.  Luckily they're global variables.

Code: [Select]
#import "search.e"
static _str save_old_search_options;
static int save_old_search_range;
static int save_old_search_mfflags;
static _str save_old_search_misc_options;

static void xsave_old_search_options()
{
   save_old_search_options = old_search_options;
   save_old_search_range = old_search_range;
   save_old_search_mfflags = old_search_mfflags;
   save_old_search_misc_options = old_search_misc_options;
}

static void xrestore_old_search_options()
{
   old_search_options = save_old_search_options;
   old_search_range = save_old_search_range;
   old_search_mfflags = save_old_search_mfflags;
   old_search_misc_options = save_old_search_misc_options;
}

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Thanks Graeme! Wrapping with your save/restore functions did the trick!

But this save/restore is not compatible with SE21, when I try to load my new robutils.e file that has the save/restore into SE21, I get an error: "Incorrect version".

Is there a way that I can test for which version the file is getting loaded into so that I can keep the new stuff out when I try to load into SE21?

In SE22, I found I also had to wrap my _mffind2() calls with the save/restore as well. Hopefully these globals don't change over time.

Attached is my new robutils.e where I added the save/restore in wrap functions, but it has a problem loading in SE21. Please help for that.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
I found that I can wrap the SE22 specific stuff in:

#if __VERSION__ >=22.0
#endif

Now my attached robutils.e file will load in both SE21 and SE22!

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
My main concern is whether SE team will keep these global variables around in future versions:

static _str save_old_search_options;
static int save_old_search_range;
static int save_old_search_mfflags;
static _str save_old_search_misc_options;

Perhaps it would be better if SE team gave us the equivalent of Graeme's xsave_old_search_options() and xrestore_old_search_options() as a public API so that we can call them from our personal macros?

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
There were changes new for v22 where search string and options are saved for all search actions and restored to both Mini-Find and Find and Replace tool window.  We can definitely add a def-var to optionally only save search string, string and options, or none at all.  We could definitely add an additional save/restore to wrap the new options as well.


rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
My preference is that I want them saved between BigFind sessions (I don't use mini-find). But not saved when I invoke from my personal macros: mffind2() and mark_all_occurences(). I think save/restore functions that I can wrap around mffind2() and mark_all_occurences() would work for me, but open to other solutions as well.

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
An option to save search options from GUI's only would be possible, but gets complicated with existing recorded macros.  Have to think about that.