Lugaru's Epsilon
Programmer's
Editor

Context:
Epsilon User's Manual and Reference
   Primitives and EEL Subroutines
      . . .
      Control Primitives
         Control Flow
         Character Types
         Examining Strings
         . . .
         Help Subroutines
      Input Primitives
         . . .
         Other Input Functions
         Dialogs
         The Main Loop
         Binding Primitives
      Defining Language Modes
         Language-specific Subroutines

Previous   Up    Next
Windowed Dialogs  Primitives and EEL Subroutines   Binding Primitives


Epsilon User's Manual and Reference > Primitives and EEL Subroutines > Input Primitives >

The Main Loop

While Epsilon runs, it repeatedly gets keys, executes the commands bound to them, and displays any changes to buffers that result. We call this process the main loop. Epsilon loops until you call the leave_recursion( ) primitive, as described in Control Flow. The steps in the main loop are as follows:

  • Epsilon resets the in_echo_area variable. See Printf-style Format Strings.

  • Epsilon calls the check_abort( ) primitive to see if you pressed the abort key since the last time check_abort( ) was called. If so, an abort happens. See Control Flow.

  • Epsilon sets the current buffer to be the buffer connected to the current window.

  • Epsilon calls maybe_refresh( ), so that all windows are brought up to date if the next key is not ready yet.

  • Epsilon calls undo_mainloop( ), to make sure undo information is kept for the current buffer, and to tell the undo system that future buffer changes will be part of the next command.

  • Epsilon sets the this_cmd and has_arg variables to 0, and the iter variable to 1. See below.

  • Epsilon calls the EEL subroutine getkey( ). This subroutine in turn calls the wait_for_key( ) primitive to wait for the next key, mouse click, or other event.

  • Epsilon executes the new key by calling the primitive do_topkey( ) as described in Binding Primitives.

  • Epsilon sets the prev_cmd variable to the value in this_cmd.

user short this_cmd;
user short prev_cmd;
invisible_cmd()

Some commands behave differently depending on what command preceded them. For example, up-line behaves differently when the previous command was also up-line. To get this behavior, the command acts differently if prev_cmd is set to a certain value and sets this_cmd to that value itself. Epsilon copies the value in this_cmd to prev_cmd and then clears this_cmd, each time through the main loop.

Sometimes a command doesn't wish to be counted when determining the previous command. For example, when you move the mouse, Epsilon is actually running a command. But the up-line command of the previous example must behave the same, whether or not you happen to move the mouse between one up-line and the next. A command may call the invisible_cmd( ) primitive to make commands like up-line ignore it. (In fact, the primitive simply sets this_cmd equal to prev_cmd.)

user char has_arg;
user int iter;

Numeric arguments work using the has_arg and iter variables. The main loop resets iter to 1 and has_arg to 0. The argument command sets iter to the value of the argument, and sets has_arg to 1 so other commands can distinguish an argument of 1 from no argument. The do_command( ) primitive, described in Binding Primitives, will repeatedly execute a command while iter's value is greater than one, subtracting one from iter's value with each execution. If a command wants to handle arguments itself, it must set iter to one or less before returning, or the main loop will call it again.

user short cmd_len;

Any command may get more keys using the wait_for_key( ) primitive (usually by calling getkey( ); see Keys). Epsilon counts the keys used so far by the current command and stores the value in the variable cmd_len. This counter is reset to zero each time Epsilon goes through the main loop. The counter doesn't count mouse keys or other events that appear as keys.



Previous   Up    Next
Windowed Dialogs  Primitives and EEL Subroutines   Binding Primitives


Lugaru Copyright (C) 1984, 2012 Lugaru Software Ltd. All Rights Reserved.