#173 Save search/replace history (another persistent search)

development
open
nobody
Program (79)
5
2008-12-04
2008-12-04
No

This patch adds the option to share the search/replace
history between sessions. Coming from the windows editor
Textpad, I really missed this feature all the past years.

The history file is updated on each new search/replace and
is checked on opening the find- or replace-dialog box.
It can be switched on/off through the preferences-menu
(Preferences -> Default Settings -> Searching -> Save History).

The patch is against the cvs version from 2008-12-04.

Discussion

1 2 3 > >> (Page 1 of 3)
  • Save search/replace history patch

     
  • Bert Wesarg
    Bert Wesarg
    2008-12-04

    Thanks for doing this.

    I see, you have taken my complaints from the other implementation into account. But you did the file format wrong. You should have taken the format from the other patch, because your \t-separated format is broken, if there is a \t inside the search/replace string.

    He used this:

    "%d:%d:%d\n%s%s\n", type, strlen(search), strlen(replace), search, replace

    I see no reason for the first \n, it should probably a ':' too. I think you get the idea, if not look at the patch.

     
  • Bert Wesarg
    Bert Wesarg
    2008-12-04

    One more nit/pick: there are two definitions of "lastSearchdbModTime" in source/search.c. Don't know how this could compile.

     
  • Strange - there's only one "lastSearchdbModTime" on my side. The patch adds only one definition, too.
    How did you get the second one?

    For the file format point...
    I thought of this, but could find no way to enter a real tab in the dialog box.
    So I think, using a tab as separator is safe.
    If you enter a '\t' for regex mode it's written as this to file.
    Ok, the length/value variant is even safer. I'll try to implement it this way the next days.

    Peter

     
  • I found the way to enter a tab: copy&paste will do it.
    Sure, this corrupts the history file.
    The format will be changed asap. ;-)

    Peter

     
  • Bert Wesarg
    Bert Wesarg
    2008-12-04

    Ohh, yes the double definition was on my side.

    The simpliest way to search for a tab is to select one and press Ctrl+H ;-)

     
  • Bert Wesarg
    Bert Wesarg
    2008-12-04

    Ok, first test impression: it works ;-)

    But, there is one missing WriteSearchHistory() in case we do an incremental search. currently, only the first letter from a newly started iSearch gets into the file. The position is in this if:

    /* If the current history item came from an incremental search, and the
    new one is also incremental, just update the entry */
    if (currentItemIsIncremental && isIncremental) {
    XtFree(SearchHistory[historyIndex(1)]);
    SearchHistory[historyIndex(1)] = XtNewString(searchString);
    SearchTypeHistory[historyIndex(1)] = searchType;

    /* Save history to file */
    WriteSearchHistory();
    return;
    }

     
  • There's another pitfall, when searching for a newline (not \n).
    I think, I'll have to use a binary format for the history file.

     
  • Bert Wesarg
    Bert Wesarg
    2008-12-04

    I don't think so. If you have the length, and you *have* the length, before you read the search/replace strings, you can use fread() and not fgets() which relies on the \n at the line separator.

     
  • Chris Wareham
    Chris Wareham
    2008-12-04

    Hi guys, as lebert says, I recorded the lengths in my implementation of the saved search format in order to allow any characters in the search/replace strings (tabs, newlines, etc). I was then able to fread() the search and replace strings without having to parse them for a terminator. Regards, Chris.

     
1 2 3 > >> (Page 1 of 3)