Monday, January 09, 2006

lab 51 - plumbing from firefox

NAME

lab 51 - plumbing from firefox

NOTES

I often want to copy and paste text from the firefox browser into my Acme session. Copy and paste isn't implemented for hosted Inferno. It could be implemented easily enough, but not in a general way for all hosted environments, and there might be more interesting ideas to explore especially when including plumber in the mix.

To solve my particular problem, getting text from the browser to Acme, I created a bookmarklet that opens a window on a URL that I serve from my Inferno session. The URL http://localhost/magic/plumb is a shell script that calls the plumb command to open the query string in Acme.

plumb -d edit -a action showdata 
 -a filename /httpd/plumb $"msg >[2=1]

I have a modified httpd that calls shell scripts and sets environment variables to the cgi data from the query string. In this case msg is a query parameter.

I install a plumb bookmarket (drag it to toolbar), then I can select text in Firefox, click on the plumb and the text pops up in Acme.

I also go the otherway by having a file /services/httpd/root/snarf.txt which I plumb to firefox by right-clicking http://localhost/snarf.txt in Acme.

I'll finish this off with a few other tricks for users running Inferno on Windows. The winstart/winplumb scripts from Plan 9 work for Inferno too. These allow you to plumb messages from Inferno to Plan 9 and have the Windows shell launch programs. I've included both in the files for this lab. See the 9fans archives for more info. I've also included my current plumbing rules that use winstart. But basically, the windows shell usually knows what program handles a file or URL. So just calling winstart http://google.com will open the URL in your default browser. Or winstart file.pdf will open Acrobat reader, for example. The plumbing rules for files local to the inferno namespace then need to be mapped to the Host namespace, which I talk about in an earlier lab.

FILES

caerwyn.com/lab/51

lab 50 - structural expressions

NAME

lab 50 - structural expressions

NOTES

Sometimes I write some code but I'll let it sit for ages because I can't do the lab write-up for it. I think it's probably better to just throw it out there and get on with the next thing. This is one of those labs. Maybe I'll come back and edit it more if I end up using the tool.

I've been reading again Rob Pike's Structural Regular Expressions paper. It suggests variations on existing tools (sort, grep, diff and awk) where applying structural expressions might make the tools more versatile or change their character entirely.

Inferno is missing awk and though it can be run externally I still feel such a tool ought to exist within Inferno. Text manipulation, software tools, filters, regular expressions, pattern-action languages: these make up the core of what I think Inferno should be about. If there's a specific user I have in mind for Inferno it's me, and my main use for it is as a programming environment; one that integrates all the tools I use but implements the core set I need most often.

I've thought about porting awk to Inferno, but the paper suggests an alternative: to consider replacing it with new tools built around the idea of structural expressions. Inferno has an implementation of the sam language described in the paper. This is the Edit builtin command in Acme. The aim of this lab was to extract the Edit command into a stand alone command but to work more like a filter.

The commands implemented are x, y, g, v, p, which behave the same, and a, c, i which don't. Since the file being operated on is not being edited, the edit commands change the text represented by dot, in memory, and print it to standard output. For example, a will append it's argument text to dot and the write to stdout the dot text.

% xp ',x a/ foo/p'

To try out the language I tried to implement the two awk scripts that are used when building emu. The two scripts are mkdevlist and mkdevc. You can compare the implementation with the awk scripts in the inferno distribution /emu/port/(mkdevc mkdevlist). Note that the change in the language semantics means that c behaves like a print command.

This tool is potentially a mistake because the same 'sam' language means something different in the new context. I think it would be better to go further and try and build the awk like language from the paper.

FILES

caerwyn.com/lab/50