Friday, February 26, 2010

Everything is a filesystem. Everything is an emacs buffer.

I finally started hacking on TRAMP to add libferris support. I notice that in 2009 GVFS support was added to TRAMP which is very cool. I was originally poking around the lisp sources for the various things that TRAMP can use as a virtual filesystem when a fairly clean design hit me. Instead of bringing TRAMP to libferris, why not do the opposite?

So I started digging into the 8,000 odd line main tramp.el file and tracing ssh connections to see what commands were executed in the background. The plan being to add any of the POSIX commands that tramp wanted which libferris didn't already have clones of. It turns out there weren't too many, mainly ftest and fstat. These are needed to poke around and obtain details from the filesystem in order for tramp to know if things exist and more information about them. The twist of course if that much of the "stat" data is not available for some libferris filesystems. For example, an element in an XML file might not have a proper octal access mask, or indeed any explicit user/group information.

I currently have load/save working for subelements in XML files, and keys in an ISAM file like a berkeley db4. The patch to tramp itself is around 10-15 lines. Much of this can be abstracted out so you can nominate to use "the libferris command" instead of the normal coreutils one. eg, using fstat instead of stat.

$ fcreate --create-type=db4 --rdn=isam.db .
$ date | ferris-redirect -T isam.db/subfile1
$ db_dump -p isam.db
VERSION=3
format=print
type=btree
db_pagesize=4096
HEADER=END
subfile1
Fri Feb 26 18:24:55 EST 2010\0a
DATA=END

And to edit the subfile1 inside that berkeley db file over the network:
$ emacs "/monkeyiq@myserver:/tmp/isam.db/subfile1"

For performance, it is handy to play with version control and how backup files are made. The later is actually quite important for editing part of an XML file, because you can't have "elementname~" as a valid element in an XML document.

This works OK, but having the backups on the local machine is even faster.
(setq backup-directory-alist
'(("^/[a-z]*:monkeyiq@myserver:.*"
. "/monkeyiq@myserver:/tmp/.saves")))

And now to get editing data from postgresql happening too, and oh, editing a buffer in an emacs process on a remote host which is mounted by libferris?

1 comment:

眼睛為貧 said...
This comment has been removed by a blog administrator.