Ejemplo n.º 1
0
int EBuffer::InsertString(const char *aStr, int aCount) {
    int P;
    int C, L;
    int Y = VToR(CP.Row);

    if (BFI(this, BFI_InsertKillBlock) == 1)
        if (CheckBlock() == 1)
            if (BlockKill() == 0)
                return 0;

    if (BFI(this, BFI_Insert) == 0)
        if (CP.Col < LineLen())
            if (KillChar() == 0)
                return 0;
    if (InsText(Y, CP.Col, aCount, aStr) == 0)
        return 0;
    C = CP.Col;
    L = VToR(CP.Row);
    P = CharOffset(RLine(L), C);
    P += aCount;
    C = ScreenPos(RLine(L), P);
    if (SetPos(C, CP.Row) == 0)
        return 0;
    if (BFI(this, BFI_Trim) && *aStr != '\t')
        if (TrimLine(L) == 0)
            return 0;
    if (BFI(this, BFI_WordWrap) == 2) {
        if (DoWrap(0) == 0) return 0;
    } else if (BFI(this, BFI_WordWrap) == 1) {
        int P, C = CP.Col;
        PELine LP;
        int L;

        if (C > BFI(this, BFI_RightMargin)) {
            L = CP.Row;

            C = BFI(this, BFI_RightMargin);
            P = CharOffset(LP = RLine(L), C);
            while ((C > BFI(this, BFI_LeftMargin)) &&
                    ((LP->Chars[P] != ' ') &&
                     (LP->Chars[P] != 9)))
                C = ScreenPos(LP, --P);

            if (P <= BFI(this, BFI_LeftMargin)) {
                C = BFI(this, BFI_RightMargin);
            } else
                C = ScreenPos(LP, P);
            if (SplitLine(L, C) == 0) return 0;
            IndentLine(L + 1, BFI(this, BFI_LeftMargin));
            if (SetPos(CP.Col - C - 1 + BFI(this, BFI_LeftMargin), CP.Row + 1) == 0) return 0;
        }
    }
    return 1;
}
Ejemplo n.º 2
0
int EBuffer::TypeChar(char aCh) { // does abbrev expansion if appropriate
    if (BFI(this, BFI_InsertKillBlock) == 1)
        if (CheckBlock() == 1)
            if (BlockKill() == 0)
                return 0;
    if (ChClass(aCh) == 0 && BFI(this, BFI_Abbreviations) == 1) {
        PELine L = VLine(CP.Row);
        int C, P, P1, C1, Len, R;
        char Str[256];
        EAbbrev *ab;

        R = VToR(CP.Row);
        C = CP.Col;
        P = CharOffset(L, C);
        if (P >= 0 && P <= L->Count) {
            //fprintf(stderr, "TypeChar 1\n");
            P1 = P;
            C1 = ScreenPos(L, P);
            while ((P > 0) && ((ChClass(L->Chars[P - 1]) == 1) || (L->Chars[P - 1] == '_'))) P--;
            Len = P1 - P;
            C = ScreenPos(L, P);
            assert(C1 - C == Len);
            if (Len > 0 && Len < int (sizeof(Str))) {
                //fprintf(stderr, "TypeChar 2\n");
                memcpy(Str, L->Chars + P, Len);
                Str[Len] = 0;
                ab = Mode->FindAbbrev(Str);
                if (ab) {
                    //fprintf(stderr, "TypeChar 3\n");
                    if (ab->Replace != 0) {
                        //fprintf(stderr, "TypeChar 4\n");
                        if (DelText(R, C, C1 - C) == 0)
                            return 0;
                        if (ab->Replace) {
                            //fprintf(stderr, "TypeChar 5 %s <- %s\n", ab->Replace, ab->Match);
                            Len = strlen(ab->Replace);
                            if (InsText(R, C, Len, ab->Replace) == 0)
                                return 0;
                            if (SetPos(C + Len, CP.Row) == 0)
                                return 0;
                        } else {
                            if (SetPos(C, CP.Row) == 0)
                                return 0;
                        }
                    } else {
                        if (((EGUI *)gui)->ExecMacro(View->MView->Win, ab->Cmd) == 0)
                            return 0;
                    }
                }
            }
        }
    }
    return InsertString(&aCh, 1);
}
Ejemplo n.º 3
0
// remove selected text and paste information from clipboard to replace it
int EBuffer::BlockPasteOver(int clipboard) {
    // if there is existing selection, remove it's contents
    if (CheckBlock())
    {
        BlockKill();
    }

    // paste text from clipboard
    if (BlockPaste(clipboard))
    {
        // go to end of selection
        SetPos(BE.Col, BE.Row);

        // remove selection
        return BlockUnmark();
    }

    return 0;
}
Ejemplo n.º 4
0
int EBuffer::InsertSpacesToTab(int TSize) {
    int P = CP.Col, P1;

    if (BFI(this, BFI_InsertKillBlock) == 1)
        if (CheckBlock() == 1)
            if (BlockKill() == 0)
                return 0;

    if (TSize <= 0)
        TSize = BFI(this, BFI_TabSize);

    P1 = NextTab(P, TSize);
    if (BFI(this, BFI_Insert) == 0) {
        if (CP.Col < LineLen())
            if (DelText(VToR(CP.Row), CP.Col, P1 - P) == 0) return 0;
    }
    if (InsText(VToR(CP.Row), CP.Col, P1 - P, 0) == 0) return 0;
    if (SetPos(P1, CP.Row) == 0) return 0;
    return 1;
}
Ejemplo n.º 5
0
int EBuffer::Delete() {
    int Y = VToR(CP.Row);
    if (CheckBlock() == 1 && BFI(this, BFI_DeleteKillBlock)) {
        if (BlockKill() == 0)
            return 0;
    } else if (CP.Col < LineLen()) {
        if (BFI(this, BFI_DeleteKillTab)) {
            int P;
            int C = CP.Col, C1;

            P = CharOffset(RLine(Y), C);
            C1 = ScreenPos(RLine(Y), P + 1);
            if (DelText(Y, C, C1 - C) == 0) return 0;
        } else {
            ELine *L = RLine(Y);
            int C = CharOffset(L, CP.Col);

            if (L->Count > 0 && L->Chars[C] == '\t') {
                /* We're on top of tab character. Skip over all spaces and
                   tabs so that only the last space/tab gets deleted. */
                while (C < L->Count &&
                        (L->Chars[C+1] == '\t' || L->Chars[C+1] == ' ')) C++;
            }

            if (DelText(Y, ScreenPos(L, C), 1) == 0) return 0;
        }
    } else
        if (LineJoin() == 0) return 0;
    if (BFI(this, BFI_WordWrap) == 2) {
        if (DoWrap(0) == 0) return 0;
        if (CP.Col >= LineLen(Y))
            if (CP.Row < VCount - 1) {
                if (SetPos(BFI(this, BFI_LeftMargin), CP.Row + 1) == 0) return 0;
            }
    }
    if (BFI(this, BFI_Trim))
        if (TrimLine(VToR(CP.Row)) == 0)
            return 0;
    return 1;
}
Ejemplo n.º 6
0
int EBuffer::BackSpace() {
    int Y = VToR(CP.Row);

    if (CheckBlock() == 1 && BFI(this, BFI_BackSpKillBlock)) {
        if (BlockKill() == 0)
            return 0;
    } else if (BFI(this, BFI_WordWrap) == 2 && CP.Row > 0 && !IsLineBlank(Y - 1) &&
               CP.Col <= BFI(this, BFI_LeftMargin) && CP.Col <= LineIndented(Y)) {
        if (SetPos(LineLen(Y - 1), CP.Row - 1) == 0) return 0;
    } else if (CP.Col == 0) {
        if (CP.Row > 0)
            if (ExposeRow(VToR(CP.Row) - 1) == 0) return 0;
        if (MoveUp() == 0) return 0;
        if (MoveLineEnd() == 0) return 0;
        if (LineJoin() == 0) return 0;
    } else {
        if (BFI(this, BFI_BackSpUnindents) && (LineIndented(Y) == CP.Col)) {
            int C = CP.Col, C1 = 0;
            int L = VToR(CP.Row);

            C1 = C;
            while (L > 0 && (IsLineBlank(L - 1) || (C1 = LineIndented(L - 1)) >= C)) L--;
            if (L == 0) C1 = 0;
            if (C1 == C) C1--;
            if (C1 < 0) C1 = 0;
            if (C1 > C) C1 = C;
            if (SetPos(C1, CP.Row) == 0) return 0;
            if (C > LineIndented(Y)) return 0;
            if (DelText(Y, C1, C - C1) == 0) return 0;
            if (BFI(this, BFI_Insert) == 0)
                if (InsText(Y, C1, 1, " ") == 0) return 0;
        } else if (BFI(this, BFI_BackSpKillTab)) {
            int P;
            int C = CP.Col, C1;

            P = CharOffset(RLine(Y), C - 1);
            C1 = ScreenPos(RLine(Y), P);
            if (SetPos(C1, CP.Row) == 0) return 0;
            if (DelText(Y, C1, C - C1) == 0) return 0;
            if (BFI(this, BFI_Insert) == 0)
                if (InsText(Y, C1, 1, " ") == 0) return 0;
        } else {
            if (MovePrev() == 0) return 0;

            ELine *L = RLine(Y);
            int C = CharOffset(L, CP.Col);

            if (L->Count > 0 && L->Chars[C] == 9) {
                /* We're on top of tab character. Skip over all spaces and
                   tabs so that only the last space/tab gets deleted. */
                while (C < L->Count &&
                        (L->Chars[C+1] == 9 || L->Chars[C+1] == ' ')) C++;
            }

            if (DelText(Y, ScreenPos(L, C), 1) == 0) return 0;
            if (BFI(this, BFI_Insert) == 0)
                if (InsText(Y, ScreenPos(L, C), 1, " ") == 0) return 0;
        }
    }
    if (BFI(this, BFI_WordWrap) == 2) {
        if (DoWrap(0) == 0) return 0;
    }
    if (BFI(this, BFI_Trim)) {
        Y = VToR(CP.Row);
        if (TrimLine(Y) == 0) return 0;
    }
    return 1;
}
Ejemplo n.º 7
0
int EBuffer::KillBlockOrCharPrev() {
    if (CheckBlock() == 0)
        return KillCharPrev();
    else
        return BlockKill();
}
Ejemplo n.º 8
0
int EBuffer::KillBlock() {
    return BlockKill();
}
Ejemplo n.º 9
0
int EBuffer::BlockCut(int Append) {
    if (BlockCopy(Append) && BlockKill()) return 1;
    return 0;
}