Lugaru's Epsilon

Epsilon User's Manual and Reference
   Epsilon Extension Language
      . . .
         . . .
         Break and Continue Statements
         Return Statement
         Save_var Statements
         On_exit Statements
         Goto and Empty Statements
         . . .
      . . .

Previous   Up    Next
Return Statement  Epsilon Extension Language   On_exit Statements

Epsilon User's Manual and Reference > Epsilon Extension Language > Statements >

Save_var Statements

        save_var save-list;
        save_spot save-list;

        save-item , save-list

        identifier = expression
        identifier modify-operator expression
        identifier ++
        identifier --

The save_var statement tells Epsilon to remember the current value of a variable, and set it back to its current value when the function that did the save_var exits. Epsilon will restore the value no matter how the function exits, even if it calls another function which signals an error, and this aborts out of the calling function.

You can provide a new value for the variable at the same time you save the old one. Epsilon first saves the old value, then assigns the new one. You can use any of the assignment operators listed in Assignment Operators, as well as the ++ and -- operators.

For example, this command plays a note at 440 Hz for one second, without permanently changing the user's variable settings for the bell (in versions of Epsilon that support changing the bell's frequency and duration).

command play_note()
    save_var beep_frequency = 440;
    save_var beep_duration = 100;
    ding();      /* uses beep_ variables */

The save_spot statement functions like save_var, but it creates a spot (see Spots) in the current buffer to hold the old value. The spot will automatically go away when the function exits. Use save_spot instead of save_var when you wish to save a buffer position, and you want it to stay in the right place even if the buffer contents change.

The save_var and save_spot statements can apply to global variables with "simple" types: those that you can directly assign to with the = operator. They don't work on structures, for example, or on local variables.

Although the save_var and save_spot statements resemble variable declarations, they are true statements. You can use the if statement (above), for example, to only save a variable in certain cases. These statements operate with a "stack" of saved values, so that if you save the same variable twice in a function, only the first setting will have an effect on the final value of the variable. (Repeated save statements take up space on the saved value stack, however, so they should be avoided.) When you save a buffer-specific or window-specific variable, Epsilon remembers which buffer's or window's value was saved, and restores only that one.

The restore_vars( ) primitive restores all variables saved in the current function. After a restore_vars( ), future modifications to any saved variables won't be undone.

Previous   Up    Next
Return Statement  Epsilon Extension Language   On_exit Statements

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