Enable and Disable

From Gwen Morse's Wiki
Jump to: navigation, search
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; disable.tf                                                          ;;;
;;; by Susan Dittmar (dittmar at ph dash cip dot uni dash koeln dot de) ;;;
;;;  march 1997                                                         ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; /~loadedlocal disable.tf
; (if you want to make this a library, use /~loaded disable.tf
; The loadedlocal.tf library was once posted on the tf mailing list. It is
; a copy of the /~loaded command, but with a local library directory,
; which allows me to have library files of my own without touching the
; library of the whole computer pool.)

; changes:
; 25.1.1998
; Changed the direction of the loop in /enable. This way the last /disable
; of one command which was disabled (redefined) several times is made
; undone with the /enable command.
; example:
;    /def foo = say 1 %; /disable foo
;    /def foo = say 2 %; /disable foo
;    /def foo = say 3                  ==> foo = say 3
;    /undef foo %; /enable foo         ==> foo = say 2
;    /undef foo %; /enable foo         ==> foo = say 1

/require lisp.tf

/set _disableTop=0

/def disable = \
    /if /ismacro %{1} %; /then %;\
        /set _disableTop=$[_disableTop+1] %;\
        /set _disableName__%{_disableTop}=%{1} %;\
        /eval /set _disableBody__%{_disableTop}=$$(/cddr $$(/list -i - %{1})) %;\
        /undef %{1} %;\
    /else %;\
        /echo -e %%% macro %{1} not definded %;\
    /endif

/def enable = \
    /let _lauf=%{_disableTop} %;\
    /let _test1 $[_lauf >= 1] %;\
    /let _test2 _disableName__$[{_lauf}] !/ "$[{1}]" %;\
    /while (_test1 & (_test2)) \
        /test --_lauf%;\
        /let _test1 $[_lauf >= 1] %;\
        /let _test2 _disableName__$[{_lauf}] !/ "$[{1}]" %;\
    /done %;\
    /if (_lauf<1) \
        /echo -e %%% macro %{1} not found %;\
    /else %;\
        /eval /eval -s0 %%{_disableBody__%{_lauf}} %;\
        /while (_lauf<_disableTop) \
            /eval /set _disableName__%{_lauf}=%%{_disableName__$[_lauf+1]} %;\
            /eval /set _disableBody__%{_lauf}=%%{_disableBody__$[_lauf+1]} %;\
            /test ++_lauf%;\
        /done %;\
        /set _disableTop=$[_disableTop-1]%;\
    /endif

/def echoDisabled = \
    /let _lauf=1 %;\
    /echo %;\
    /while (_lauf<=_disableTop) %;\
        /eval /echo %%{_disableBody__%{_lauf}} %;\
        /echo %;\
        /test ++_lauf%;\
    /done