[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[eev] eevnow and eevnow-at (revised)
From: |
Eduardo Ochs |
Subject: |
[eev] eevnow and eevnow-at (revised) |
Date: |
Fri, 22 Apr 2005 09:22:51 -0300 |
Oh nooo, my first message to this mailing list was full of errors...
I found that so embarassing that I revised it and rewrote a few parts.
Here is the new version.
Sometimes we have e-scripts that end up being composed of many small
"tasks"; for example, now I'm trying to create inside a "host" Debian
system a small "guest" system that can be run in parallel with the
"host" in two different ways; either by chrooting into the guest,
with, for example,
chroot /guest /bin/sh
or by running the guest inside an emulator; if /guest is a partition,
and the "block device image" of that partition is in the file
/tmp/guest.img, mounted on /guest with
mount -o loop /tmp/guest.img /guest/
then we can start an emulator and make it boot the filesystem in
/guest with a command like this:
qemu -hda /tmp/guest.img \
-kernel /tmp/vmlinuz \
-pci
Well, it turns out that task that I'm trying to accomplish, "create a
guest system and run it inside the host", comes in two flavours,
"chroot" and "emulator", and that these two flavours have many
sub-tasks in common... for example, both include "copy libraries from
host", "set up the root password" and "create a user `edrx'". But
there are many subtasks.
After a while it became very boring to choose one by one the blocks
containg the commands for the subtasks, and inside each one of the
blocks to type F3, then switch to an xterm, then type `ee' to execute
the commands...
The default action of F3 is to run `eev-bounded', which just saves the
bounded region to the file $EE; but it is easy to define other
functions that act on bounded regions:
(defun eevnow (s &optional e)
(interactive "r")
(eev s e)
(eech "ee\n"))
(eeb-define 'eevnow-bounded 'eevnow 'ee-delimiter-hash nil t t)
this `eevnow' not only saves the selected region to $EE, but also
sends (like an F9 would do) an `ee' to a controlled shell via a
communication channel; and `eevnow-bounded' runs `eevnow' using the
bounded region around Emacs's "point". Also, running M-x
eevnow-bounded sets the default action of F3 to eevnow-bounded, and so
after a first M-x eev-bounded we would only need to position Emacs's
"point" inside each block and then type F3 there; the part of going to
the shell and typing `ee' there would have been automated.
But that is not enough! Those create-guest-system-blah-blah-blah "big
tasks" are composed of a gruesomely high number of little tasks, and
that method would force me to select each block "visually" and type F3
inside each one to execute it; that is like playing a sequence of
notes on a musical instrument, and it's a long sequence, on an
instrument that is hard to play... playing the sequence demands a lot
of attention, and as I'm mostly interested in playing the same few
"tunes" many many times, with just a few occasional variations, it
ought to be possible to "semi-automate" the sequences of notes so that
they would become easier to play...
The solution that I've found is a kind of subroutine scheme for
e-scripts; it is essentially a 2-line hack, and my impression is that
until a person can see that working (either "in reality" or by
imagining it very clearly) it tends to look quite alien...
Each delimited block can have a "name" in a comment line. We can
establish the convention that the name will always appear in the first
line of the block (this is not necessary, actually), and that it will
be enclosed in "«»"s (this is essential). The "«»"s make these names
work as "anchors", exactly like the ones that are used by `to' and
`find-anchor'. The idea is to have a command, eevnow-at, that jumps to
a named delimited block _temporarily_, runs eevnow there, and then
returns the point to the original position; its code can be:
(defun eevnow-at (tag)
(save-excursion (ee-to tag) (ee-once (eevnow-bounded))))
and it is meant to be called from inside "red star lines" inside F9
blocks - remember that they are executed as Lisp instead of sent
through the communication channel. Here's an example, with the ^Os
(the red stars) having been substituted by "<*>"s:
#<*>
# «iptables-del-inputfilter»
iptables -D INPUT -p TCP --dport telnet -j INPUTFILTER
iptables -F INPUTFILTER
iptables -X INPUTFILTER
#<*>
# «iptables-create-inputfilter»
iptables -N INPUTFILTER
iptables -A INPUTFILTER -s 127.0.0.1 -j ACCEPT
iptables -A INPUTFILTER -j DROP
iptables -A INPUT -p TCP --dport telnet -j INPUTFILTER
#<*>
# Begin typing F9 here
<*> (eechannel-xterm "A")
<*> (eevnow-at "iptables-del-inputfilter")
<*> (eevnow-at "iptables-create-inputfilter")
chroot /guest /usr/sbin/telnetd &
telnet 127.0.0.1
root
root
exit
<*> End of the F9 block
The two first blocks can now be considered as "subroutines", and to
execute the e-script we go to the "Begin typing F9 here" line and
start typing F9s. Ta-daaaa!
Huh, I think that I need to make an animation about this...
By the way: the example file
<http://angg.twu.net/eev-current/examples/busybox.e.html>
was all written using this technique, but its contents are (currently)
a total mess...
Cheers,
Edrx
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [eev] eevnow and eevnow-at (revised),
Eduardo Ochs <=