示例#1
0
/*
 * doRunKeyMap - execute a key map a specified number of times
 */
static vi_rc doRunKeyMap( key_map *scr, long total )
{
    int         max;
    vi_rc       rc = ERR_NO_ERR;
    undo_stack  *cstack;

    if( EditFlags.InputKeyMapMode ) {
        return( ERR_INPUT_KEYMAP_RUNNING );
    }
    cstack = UndoStack;
    StartUndoGroup( cstack );
    while( total > 0 ) {
        /*
         * set up key map to run
         */
        CurrentKeyMap = scr->data;
        if( scr->no_input_window ) {
            EditFlags.NoInputWindow = TRUE;
        }
        // max = strlen( CurrentKeyMap );
        for( max = 0; CurrentKeyMap[max] != 0; max++ );

        EditFlags.KeyMapInProgress = TRUE;
        EditFlags.KeyMapMode = TRUE;
        LastError = ERR_NO_ERR;

        /*
         * run until done
         */
        for( CurrentKeyMapCount = 0; CurrentKeyMapCount < max; ) {
            LastEvent = GetNextEvent( FALSE );
            rc = DoLastEvent();
            if( rc > ERR_NO_ERR || LastError != ERR_NO_ERR ) {
                break;
            }
            DoneLastEvent( rc, TRUE );
        }

        EditFlags.KeyMapMode = FALSE;
        EditFlags.NoInputWindow = FALSE;
        EditFlags.KeyMapInProgress = FALSE;
        if( rc > ERR_NO_ERR || LastError != ERR_NO_ERR ) {
            break;
        }
        total--;
    }

    TryEndUndoGroup( cstack );
    EditFlags.Dotable = FALSE;
    return( rc );

} /* doRunKeyMap */
示例#2
0
/*
 * EditMain - main driver for editor (command mode)
 */
void EditMain( void )
{
    vi_rc       rc;
    char        *msg = NULL;
    bool        doclear;

    /*
     * loop forever, or at least until all done
     */
    for( ;; ) {

#if 0
#ifdef __WIN__
        PushMode();
        UpdateFiles();
        PopMode();
#endif
#endif
        if( !EditFlags.InsertModeActive || EditFlags.Modeless ) {
            if( EditFlags.Modeless ) {
                UpdateEditStatus();
                EditFlags.NoCapsLock = false;
            } else {
                UpdateCurrentStatus( CSTATUS_COMMAND );
                EditFlags.NoCapsLock = true;
            }

            if( !EditFlags.Modeless && EditFlags.ReturnToInsertMode &&
                                !NonKeyboardEventsPending() ) {
                EditFlags.ReturnToInsertMode = false;
                if( EditFlags.WasOverstrike ) {
                    LastEvent = 'R';
                } else {
                    LastEvent = 'i';
                }
            } else {
                DCUpdateAll();
#ifdef __WIN__
                SetWindowCursorForReal();
#endif
                LastEvent = GetNextEvent( true );
            }
            EditFlags.NoCapsLock = false;
            doclear = true;
            if( LastEvent == VI_KEY( MOUSEEVENT ) ) {
                if( LastMouseEvent == MOUSE_MOVE ) {
                    doclear = false;
                }
            }
            if( doclear ) {
                if( EditFlags.AutoMessageClear ) {
                    ClearWindow( MessageWindow );
                }
#ifndef __WIN__
                ResetDisplayLine();
#endif
            }
        } else {
            // Cannot do a RestoreInfo while we are in insert mode
            // because it will call ValidateCurrentColumn which will
            // do something stupid on us... PushMode/PopMode solution
            // not working yet... this needs a little work
            DCUpdate();
#ifdef __WIN__
            SetWindowCursorForReal();
#endif
            LastEvent = GetNextEvent( true );
        }

        rc = DoLastEvent();

        if( EditFlags.ReadOnlyError && rc <= ERR_NO_ERR ) {
            EditFlags.ReadOnlyError = false;
            rc = ERR_READ_ONLY_FILE_MODIFIED;
        }
        if( rc > ERR_NO_ERR ) {
            msg = GetErrorMsg( rc );
        }

        DoneLastEvent( rc, false );

        if( rc > ERR_NO_ERR ) {
            Error( msg );
        }

    }

} /* EditMain */