From: "Russ Cox" <rsc@swtch.com>
To: 9fans <9fans@cse.psu.edu>
Subject: [9fans] autoroff
Date: Thu, 8 Mar 2007 11:49:27 -0500 [thread overview]
Message-ID: <ee9e417a0703080849w55fd6df1k56403318fd814a33@mail.gmail.com> (raw)
One really nice thing about troff is that it is very fast.
It hasn't changed appreciably in decades, so it is riding
out the hardware performance improvements quite nicely.
I was marvelling about how when I middle-click a troff | page
command line in acme it just pops up instantly, and I decided
to write a little shell script to do that for me.
This script watches the acme window it is executed in,
and every time you type a newline or cut/paste with
the mouse, it re-runs troff with the window contents,
updating a postscript file being watched by gv --watch.
There is a slight lag before gv notices the file has
changed, but it's certainly good enough, and even
better than repeatedly clicking Put and then executing
the troff command.
If one were going to write a real command, you'd want
to reroff in the background, waiting for pauses in the
editing. But for a shell script, this isn't bad.
One unfortunate effect is that because the window is
attached to a program, Undo, Redo, and Put go away
and have to be added on the other side of the tag | .
Enjoy.
Russ
#!/usr/local/plan9/bin/rc
. $PLAN9/lib/acme.rc
nl='
'
tmp=/tmp/autoroff.$pid
fn reroff {
9p read acme/$winid/body >$tmp.tr
{ 9 tbl $tmp.tr | 9 troff -ms | tr2post >$tmp.ps_
&& mv $tmp.ps_ $tmp.ps } >[2]/dev/null
}
fn event {
switch($1$2){
case KI
if(~ $9 $nl)
reroff
case KD MD MI
reroff
}
switch($1$2){
case Mx MX Ml ML
winwriteevent $*
}
}
if(! winread tag | 9 grep -s Put)
echo -n ' Put' | winwrite tag
reroff
wineventloop &
psv --watch $tmp.ps
kill $apid
killall 9p # BUG
rm $tmp.*
next reply other threads:[~2007-03-08 16:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-08 16:49 Russ Cox [this message]
2007-03-08 19:41 ` Anthony Sorace
2007-03-08 20:00 ` Russ Cox
2007-03-08 20:31 ` Anthony Sorace
2007-03-08 21:15 ` Russ Cox
2007-03-11 6:58 ` Scott Schwartz
2007-03-11 8:08 ` Bakul Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee9e417a0703080849w55fd6df1k56403318fd814a33@mail.gmail.com \
--to=rsc@swtch.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).