9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] autoroff
@ 2007-03-08 16:49 Russ Cox
  2007-03-08 19:41 ` Anthony Sorace
  2007-03-11  6:58 ` Scott Schwartz
  0 siblings, 2 replies; 7+ messages in thread
From: Russ Cox @ 2007-03-08 16:49 UTC (permalink / raw)
  To: 9fans

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.*


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-03-11  8:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-08 16:49 [9fans] autoroff Russ Cox
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

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).