jed-users mailing list

[2004 Date Index] [2004 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: next_word/prev_word


OK, I admit that I'm beating this to death.  But, the following
really is an improvement.  This version searches forward (or
backward) for the next occurance of a word, as the earlier version
did, but also skips occurances of the string within longer words.
It's a little lengthy.  But for me, since I prefer this behavior,
it's worth it.


    autoload("get_word", "txtutils");

    define search_current_word(direction)
    {
        variable word;
        variable mark;
        variable result;
        variable s1;
        mark = create_user_mark();
        skip_word();
        bskip_word();
        word = get_word();
        if (direction == 1)
        {
            while (1)
            {
                go_right_1();
                result = fsearch(word);
                if (result == 0)
                {
                    break;
                }
                % Search again if the word is a substring of a longer word.
                s1 = get_word();
                !if (strcmp(s1, word))
                {
                    break;
                }
            }
        }
        else
        {
            while (1)
            {
                result = bsearch(word);
                if (result == 0)
                {
                    break;
                }
                % Search again if the word is a substring of a longer word.
                s1 = get_word();
                !if (strcmp(s1, word))
                {
                    break;
                }
            }
        }
        if (result == 0)
        {
            goto_user_mark(mark);
            message(word + " not found");
        }
    }

    % Bind to Alt-z+Alt-comma (alt-z then alt-comma) and Alt-z+Alt-period.
    setkey ("search_current_word(-1)", "\ez\e,");
    setkey ("search_current_word(1)", "\ez\e.");


Dave

-- 
Dave Kuhlman
dkuhlman@xxxxxxxx
http://www.rexx.com/~dkuhlman

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2004 date index] [2004 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]