Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#######
#
# E-scripts on creating interactive demos using eeg and eeg3.
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
# An introduction to eev can be found here:
#
#   (find-eev-quick-intro)
#   http://angg.twu.net/eev-intros/find-eev-quick-intro.html
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/a/e/emacs.e>
#           or at <http://angg.twu.net/e/emacs.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######





# «.debugging_eeg3»	(to "debugging_eeg3")
# «.capture»	(to "capture")


# «.escripts_demo_1»	(to "escripts_demo_1")

# (find-es "console" "screen_demo_eeg2")


# «screen_demo_eeg2»  (to ".screen_demo_eeg2")
# (find-node "(screen)Screen Command" "`C-a c'")
# (find-node "(screen)Split" "`C-a S'")
# (find-node "(screen)Focus" "`C-a Tab'")
# (find-node "(screen)Redisplay" "`C-a l'")
# (find-node "(screen)Bell" "`C-a C-g'")
# (find-angg "EXPECT/eeg2")
#*
cat > $EEG <<'---'
 Tcl: ac " " ^AS^A^I^Ac ^A^I
echo hello
echo hi
 Tcl: a  {message "An EEG-message!! Time to redraw the screen..."}
 Tcl: ac ^Al ^A^I
echo -e '\a'
 Tcl: ac ^A^G {^[[A} ^M ^A\\ y
---
eeg2 -c 'allowtcl' screen
# Eeg2 done.
#*









#####
#
# Interactive demos using eeg2
# 2000jan15
#
#####

# «escripts_demo_1»  (to ".escripts_demo_1")
#*
# (find-angg ".zshrc" "save-input")
# (find-fline "/tmp/o2")
save-input /tmp/o emacs -nw $ES/anatocc.e
expandctrls < /tmp/o > /tmp/o2
#*
# (find-angg "EEG/gdbk.eeg")
# (find-angg ".zshrc")

cat > $EEG <<'---'
 Tcl: # set gluelines 1
 Tcl: now_in screen
 Tcl:
 Tcl: am1 {Next key: C-s (isearch-forward)}
 Tcl: am+ {Will start an interactive search.}
 Tcl: am+ {}
 Tcl: am+ {Keyboard input will appear at the last line of the screen (the}
 Tcl: am+ {"minibuffer") but the cursor will be pointing to the matching}
 Tcl: am+ {position.}
 Tcl: am
 Tcl: ac ^S d l o p e n
 Tcl:
 Tcl: am1 {Next key: M-e (end-of-line-then-eval-last-sexp)}
 Tcl: am  {Will follow the "to" hyperlink.}
 Tcl: ac {^[e}
 Tcl:
 Tcl: am  {Arrows move.}
 Tcl: ac {^[[B} {^[[B} {^[[B} {^[[B} {^[[B}
 Tcl:
 Tcl: am1 {M-0 ... M-9 form a number that some commands use as a repetition}
 Tcl: am+ {count.  The next command is M-5 down.}
 Tcl: am
 Tcl: ac {^[5} {^[[B}
 Tcl:
 Tcl: am1 {C-l (recenter) adjusts the display to place the cursor in the}
 Tcl: am   {middle.}
 Tcl: ac ^L
 Tcl:
 Tcl: am1 {F3 (ee-default-strbounded, will work as eev-bounded now)}
 Tcl: am+ {Will save the block between the delimiters to a temporary}
 Tcl: am  {script file (~/bin/ee.sh).}
 Tcl: ac {^[[[C}
 Tcl:
 Tcl:     a {_ 10}
 Tcl:     a {set gluelines 0}
 Tcl:
 Tcl: am1 {We will now switch to a shell with C-a c.}
 Tcl: am+ {This C-a c is not an Emacs command; we are now running Emacs under}
 Tcl: am+ {a program called "screen", that makes a single terminal act as}
 Tcl: am+ {many, and screen will interpret C-a c as its command to create a}
 Tcl: am+ {new shell "window" and switch to it;  I hope you have tried the}
 Tcl: am+ {demo of "screen" before this one, because if you haven't you may}
 Tcl: am  {become somewhat puzzled.}
 Tcl: ac ^Ac
 Tcl: am1 {Now the command "ee" will execute the saved block.}
 Tcl: am  {It is not exactly a command, it is a shell alias:}
alias ee
echo $EE
cat $EE

 Tcl: am {Let's run "ee" now.}
ee
 Tcl: am {It wrote two C programs, "x.c"...}
cat x.c
 Tcl: am {and "so.c"...}
cat so.c
 Tcl: am1 {and compiled "so.c" into a shared library and "x.c" into an}
 Tcl: am   {executable file, "x":}
laf
 Tcl: am1 {then "x" was ran, and it called a function that was}
 Tcl: am+ {defined in so.c. Let's run "x" again and then clear}
 Tcl: am+ {the screen and run "ee" again, and you'll see how "ee"}
 Tcl: am  {did all that in a single blow.}
./x
 Tcl: ac ^L
ee
 Tcl: am1 {As we compiled everything with "-g" it will be possible to run}
 Tcl: am+ {gdb (a debugger) on "x". Emacs provides a fantastic debugging}
 Tcl: am+ {environment, so we will switch back to Emacs... We'll use the}
 Tcl: am+ {key sequence C-a 0 for that; screen interprets it as "go to the}
 Tcl: am  {window 0".}
 Tcl: ac ^A0
 Tcl:
 Tcl: am {Go to the "gdbk-gdb" hyperlink (using "C-s (gdbk-").}
 Tcl: ac ^S(gdbk-
 Tcl:
 Tcl: am1 {Now execute the hyperlink with M-e; this will 1) save everything}
 Tcl: am+ {between the delimiters another temporary file, ~/bin/ee.generic}
 Tcl: am+ {(this step would have been skipped if the first argument to}
 Tcl: am+ {`gdbk-gdb' were not `t'), and 2) invoke gdb, inside Emacs, on}
 Tcl: am+ {/tmp/x, adding support for some convenient keys.}
 Tcl: am 
 Tcl: ac {^[e}
 Tcl:
 Tcl: am1 {GDB also supports an "ee" command; it will make it execute the}
 Tcl: am {commands stored in ~/bin/ee.generic, that were "br main" and "run".}
ee
 Tcl:
 Tcl: am {Now single-step several times (10, to be precise) with M-s.}
 Tcl: ac {^[s} {^[s} {^[s} {^[s} {^[s}
 Tcl: ac {^[s} {^[s} {^[s} {^[s} {^[s}
 Tcl:
 Tcl: am {Now kill the gdb window, with M-k enter.}
 Tcl: ac {^[k} ^M
 Tcl:
 Tcl: am {Kill the buffer visiting x.c, with M-k enter.}
 Tcl: ac {^[k} ^M
 Tcl:
 Tcl: am1 {Leave Emacs with C-x C-c (save-buffers-kill-emacs), and after}
 Tcl: am+  {that leave the shell with C-d; screen will notice that all}
 Tcl: am   {programs it was running have finished, and will finish too.}
 Tcl: ac ^X^C
 Tcl: ac ^D
---
# eeg2 -c 'allowtcl; exit' emacs -nw $ES/anatocc.e; return
# eeg2 -c 'allowtcl' emacs -nw $ES/anatocc.e; return
eeg2 -c allowtcl  screen emacs -nw $ES/anatocc.e; set +v; return
#*





#*
cat > $EEG <<'---'
echo foo
Tcl: ak up
Tcl: ak enter
exit
---
eeg2 -c 'allowtcl' bash
# eeg2 -c 'allowtcl; ak up; ak enterputs $lines' bash
# eeg2 -c 'puts [k up right]; exit' bash
# eeg2 -c allowtcl  screen emacs -nw $ES/anatocc.e; set +v; return
#*





#*
cat > $EEG <<'---'
# line 1
tcl: a {_ 20}
# line 2
tcl: a {_ 3}
# line 3
tcl: puts $lines
tcl: set threshold 25
tcl: ac ^D
---
eeg2 -c 'allowtcl' cat

#*


cat > $EEG <<'---'
tcl: set gluelines 1
#line 1
#line 2
tcl: a {set gluelines 0}
#line 3
#line 4
tcl: ac ^D
---
eeg2 -c 'allowtcl; showlines' cat

#*




tcl: # set gluecommands 1







 Tcl: msg ""
 Tcl: msg {Any key not supported by the search mode makes Emacs}
 Tcl: msg {interrupt the search mode, return to the usual mode and}
 Tcl: msg {interpret that key. We're using F4 (redraw-screen) to clear}
 Tcl: msg {the colored messages, and that's why you saw} 




#####
#
# debugging eeg3 (and adding features)
# 2001may15
#
#####

# «debugging_eeg3»  (to ".debugging_eeg3")
#*
# eeg3 -c 'parray keyseq2name' |& l -S
# eeg3 -c 'parray prefixtable' |& l -S
# (find-angg "EXPECT/eeg3" "rev_key_lookups")

eeg3 -c 'puts [isprefix "\033ab\b"]; exit'
eeg3 -c 'puts [isprefix "\033ab"]; exit'
eeg3 -c 'puts [isprefix "\033a"]; exit'
eeg3 -c 'puts [isprefix "\033"]; exit'
eeg3 -c 'puts [isprefix ""]; exit'

eeg3 -c 'puts [isnamedkeyseq "\033ab\b"]; exit'
eeg3 -c 'puts [isnamedkeyseq "\033ab"]; exit'
eeg3 -c 'puts [isnamedkeyseq "\033a"]; exit'
eeg3 -c 'puts [isnamedkeyseq "\033"]; exit'
eeg3 -c 'puts [isnamedkeyseq ""]; exit'

# eeg3 -c 'puts [unk "\033ab\b"]' |& l -S

#*
# (find-angg "EXPECT/eeg3" "rev_key_lookups")

# eeg3 -c 'puts [maxnamedkeyseqlen hello 0]; exit' |& l -S
# eeg3 -c 'puts [maxnamedkeyseqlen "\033ab\b" 0]; exit' |& l -S
eeg3 -c 'puts [unk "\033ab\b\000"]; parray keyseqtable; exit' |& l -S

#*


proc defkey0 {keyname keyseq}



proc defkey0 {keyname keyseq} {
  global K
  set K($keyname) $keyseq
  #
  # The rest is to prepare for reverse key lookups...
  global keyseq2name prefixtable
  set keyseq2name($keyseq) $keyname
  for {set i 0} {$i<[string length $keyseq]-1} {incr i} {
    set prefixtable([string range $keyseq 0 $i]) yes
  }
}
set defkeyfun defkey0
proc defkey {args} {
  global defkeyfun
  foreach {keyname keyseq} $args {
    $defkeyfun $keyname $keyseq
  }
}

proc defkey+M {name keyseq} {
  global defkey
  $defkey $name $keyseq
  $defkey M-$name "\033$keyseq"
}


set defkeyfun defkey0
proc defkey {args} {
  global defkeyfun
  foreach {keyname keyseq} $args {
    $defkeyfun $keyname $keyseq
  }
}

proc defkey+M {name keyseq} {
  global defkey
  $defkey $name $keyseq
  $defkey M-$name "\033$keyseq"
}




#####
#
# Adding a way to capture keys
#
#####

# «capture»  (to ".capture")
#*
cat > $EEG <<'---'
 Tcl: set tcl_prefix ""

set captures ""
set capture_clauses {
  "\033?" {send_user :::[unk $captures]; set captures ""}
  -re "(.)" {set c $interact_out(1,string); append captures $c; send $c}
}
set base_clauses $base_clauses$capture_clauses
send_user $base_clauses

---
eeg3 cat

#*
expect -c '
  spawn cat
  stty raw
  interact {
    ya {send_user YA!}
    -re (.) {set c $interact_out(1,string); send_user hello($c); send $c}
    timeout 4 exit
  }
'

#*
expect -c '
  proc inner {} {
    interact "l" {send_user "(inner l)"; return} \
         -re "(.)" {send_user "(inner esc+char)"; return}
  }
  proc outer {} {
    interact "\033" {inner} \
         -re . {send_user "etc"}
  }
  spawn cat
  stty raw
  outer
'
#*
# (find-node "(expect)interact" "inter_return")
expect -c '
  proc inner {} {
    interact "l" {send_user "(inner l)"; inter_return 0} \
	     "q" {send_user "(inner q)"; inter_return 1} \
         -re "(.)" {send_user "(inner esc+char)"; inter_return 0}
  }
  proc outer {} {
    interact "\033" { if {[inner]} { return } } \
         -re "(.)" {send_user "etc"}
  }
  spawn cat
  stty raw
  outer
  send_user "bye\n"
'
#*




#####
#
# Dealing with nulls
#
#####






# (find-node "(expect)interact" "$interact_out(1,string)")


Idéia pra um script em expect que pode ser usado pra demonstrar um
monte de coisas: o usuário só bate letras maiúsculas; o expect
responde essas letras com echos, 



"exptester a__bcd_ef" runs as
  send_user a
  expect_user 


# (find-angg "EXPECT/eeg3" "rev_key_lookups")
# (find-angg "EEG/gdbk.eeg3")
# (find-angg ".zshrc" "demo")

          eeg3 screen emacs -nw $ES/anatocc.e;;








#  Local Variables:
#  coding:               utf-8-unix
#  End: