~ubuntu-branches/ubuntu/karmic/zsh/karmic

« back to all changes in this revision

Viewing changes to Src/Zle/zle_hist.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-06-02 10:40:25 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090602104025-lg6wynxpzqi08k2i
Tags: 4.3.10-1ubuntu1
* Resynchronise with Debian. Remaining changes:
  + debian/zshrc: Enable completions by default, unless
    skip_global_compinit is set

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
/* Previous search string use in an incremental search */
45
45
 
46
46
/**/
47
 
ZLE_STRING_T previous_search = NULL;
48
 
 
49
 
/**/
50
 
int previous_search_len = 0;
51
 
 
 
47
char *previous_search = NULL;
 
48
 
 
49
/**/
 
50
int previous_search_len;
 
51
 
 
52
/* Previous aborted search string use in an incremental search */
 
53
 
 
54
/**/
 
55
char *previous_aborted_search = NULL;
 
56
 
 
57
/* Local keymap in isearch mode */
 
58
 
 
59
/**/
 
60
Keymap isearch_keymap;
52
61
 
53
62
/*** History text manipulation utilities ***/
54
63
 
887
896
int
888
897
historyincrementalsearchbackward(char **args)
889
898
{
890
 
    doisearch(args, -1, 0);
891
 
    return 0;
 
899
    return doisearch(args, -1, 0);
892
900
}
893
901
 
894
902
/**/
895
903
int
896
904
historyincrementalsearchforward(char **args)
897
905
{
898
 
    doisearch(args, 1, 0);
899
 
    return 0;
 
906
    return doisearch(args, 1, 0);
900
907
}
901
908
 
902
909
/**/
903
910
int
904
911
historyincrementalpatternsearchbackward(char **args)
905
912
{
906
 
    doisearch(args, -1, 1);
907
 
    return 0;
 
913
    return doisearch(args, -1, 1);
908
914
}
909
915
 
910
916
/**/
911
917
int
912
918
historyincrementalpatternsearchforward(char **args)
913
919
{
914
 
    doisearch(args, 1, 1);
915
 
    return 0;
 
920
    return doisearch(args, 1, 1);
916
921
}
917
922
 
918
923
static struct isrch_spot {
1019
1024
    return -1;
1020
1025
}
1021
1026
 
 
1027
/*
 
1028
 * Save an isearch buffer from sbuf to sbuf+sbptr
 
1029
 * into the string *search with length *searchlen.
 
1030
 * searchlen may be NULL; the string is a NULL-terminated metafied string.
 
1031
 */
 
1032
static void
 
1033
save_isearch_buffer(char *sbuf, int sbptr,
 
1034
                    char **search, int *searchlen)
 
1035
{
 
1036
    if (*search)
 
1037
        free(*search);
 
1038
    *search = zalloc(sbptr+1);
 
1039
    memcpy(*search, sbuf, sbptr);
 
1040
    if (searchlen)
 
1041
        *searchlen = sbptr;
 
1042
    (*search)[sbptr] = '\0';
 
1043
}
 
1044
 
1022
1045
#define ISEARCH_PROMPT          "XXXXXXX XXX-i-search: "
1023
1046
#define FAILING_TEXT            "failing"
1024
1047
#define INVALID_TEXT            "invalid"
1030
1053
int isearch_active, isearch_startpos, isearch_endpos;
1031
1054
 
1032
1055
/**/
1033
 
static void
 
1056
static int
1034
1057
doisearch(char **args, int dir, int pattern)
1035
1058
{
1036
1059
    /* The full search buffer, including space for all prompts */
1037
1060
    char *ibuf = zhalloc(80);
1038
 
    /* The part of the search buffer with the search string */
 
1061
    /*
 
1062
     * The part of the search buffer with the search string.
 
1063
     * This is a normal metafied string.
 
1064
     */
1039
1065
    char *sbuf = ibuf + FIRST_SEARCH_CHAR;
1040
1066
    /* The previous line shown to the user */
1041
1067
    char *last_line = NULL;
1137
1163
     * command line.
1138
1164
     */
1139
1165
    ZleIntFunc exitfn = (ZleIntFunc)0;
 
1166
    /*
 
1167
     * Flag that the search was aborted.
 
1168
     */
 
1169
    int aborted = 0;
1140
1170
 
1141
1171
    if (!(he = quietgethist(hl)))
1142
 
        return;
 
1172
        return 1;
 
1173
 
 
1174
    selectlocalmap(isearch_keymap);
1143
1175
 
1144
1176
    clearlist = 1;
1145
1177
 
1440
1472
        zrefresh();
1441
1473
        if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) {
1442
1474
            int i;
 
1475
            aborted = 1;
 
1476
            save_isearch_buffer(sbuf, sbptr,
 
1477
                                &previous_aborted_search, NULL);
1443
1478
            get_isrch_spot(0, &hl, &pos, &pat_hl, &pat_pos, &end_pos,
1444
1479
                           &i, &sbptr, &dir, &nomatch);
1445
1480
            he = quietgethist(hl);
1572
1607
                feep = 1;
1573
1608
            else
1574
1609
                goto ins;
 
1610
        } else if (cmd == Th(z_acceptsearch)) {
 
1611
            break;
1575
1612
        } else {
1576
1613
            if(cmd == Th(z_selfinsertunmeta)) {
1577
1614
                fixunmeta();
1589
1626
#endif
1590
1627
            } else {
1591
1628
                ungetkeycmd();
1592
 
                if (cmd == Th(z_sendbreak))
 
1629
                if (cmd == Th(z_sendbreak)) {
 
1630
                    aborted = 1;
 
1631
                    save_isearch_buffer(sbuf, sbptr,
 
1632
                                        &previous_aborted_search, NULL);
1593
1633
                    sbptr = 0;
 
1634
                }
1594
1635
                break;
1595
1636
            }
1596
1637
        ins:
1621
1662
        feep = 0;
1622
1663
    }
1623
1664
    if (sbptr) {
1624
 
        zfree(previous_search, previous_search_len);
1625
 
        previous_search = zalloc(sbptr);
1626
 
        memcpy(previous_search, sbuf, previous_search_len = sbptr);
 
1665
        save_isearch_buffer(sbuf, sbptr,
 
1666
                            &previous_search, &previous_search_len);
1627
1667
    }
1628
1668
    statusline = NULL;
1629
1669
    unmetafy_line();
1640
1680
     */
1641
1681
    if (savekeys >= 0 && kungetct > savekeys)
1642
1682
        kungetct = savekeys;
 
1683
 
 
1684
    selectlocalmap(NULL);
 
1685
 
 
1686
    return aborted ? 3 : nomatch;
1643
1687
}
1644
1688
 
1645
1689
static Histent
1732
1776
    selectkeymap("main", 1);
1733
1777
    while (sptr) {
1734
1778
        sbuf[sptr] = '_';
1735
 
        sbuf[sptr] = '\0';
 
1779
        sbuf[sptr+1] = '\0';
1736
1780
        zrefresh();
1737
1781
        if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) {
1738
1782
            ret = 0;
1750
1794
                cmd == Th(z_vicmdmode)) {
1751
1795
            sbuf[sptr] = ZWC('\0');
1752
1796
            visrchstr = ztrdup(sbuf+1);
 
1797
            if (!strlen(visrchstr)) {
 
1798
                zsfree(visrchstr);
 
1799
                visrchstr = ztrdup(vipenultsrchstr);
 
1800
            }
1753
1801
            ret = 1;
1754
1802
            sptr = 0;
1755
1803
        } else if(cmd == Th(z_backwarddeletechar) ||