Next: Remote Files, Previous: Manipulating Symlinks, Up: Files [Contents][Index]
As noted earlier, Librep supports virtual files; that is it allows file names to be accessed that don’t reside on the local filing system, or aren’t normally valid as file names. This is achieved through the use of file handlers, Lisp functions that have signalled that they should be used to redirect all accesses to files whose names match a particular regular expression (see Regular Expressions).
For example, in Unix, a leading tilde ~ expands to the home directory. See below.
This variable contains a list of file handler declarations, each one of
the form (regexp . function). Whenever a file
operation is performed on a file whose name matches regexp,
function is invoked to perform the action. The function is called
as (function operation args…), where
operation and args are from the original call.
For example if the file-handler-alist contains the entry
("^~" . tilde-file-handler), then all file operations on files
starting with a tilde are redirected to the tilde-file-handler
function.
Thus if a form (file-exists-p "~/foo") is executed, it would
result in a call to tilde-file-handler as
(tilde-file-handler 'file-exists-p "~/foo").
The list of operations that may be redirected to a file handler is:
file-name-absolute-p, expand-file-name,
local-file-name, canonical-file-name,
file-name-nondirectory, file-name-directory,
file-name-as-directory, directory-file-name,
open-file, close-file, flush-file,
seek-file, write-buffer-contents,
read-file-contents, insert-file-contents,
delete-file, rename-file, copy-file,
copy-file-to-local-fs, copy-file-from-local-fs,
make-directory, delete-directory, file-exists-p,
file-regular-p, file-readable-p, file-writable-p,
file-directory-p, file-symlink-p, file-owner-p,
file-nlinks, file-size, file-modes,
file-modes-as-string, set-file-modes,
file-modtime, directory-files,
make-symlink, read-symlink.
There are several undefined functions in this list. The
write-buffer-contents, read-file-contents, and
insert-file-contents pertain to the Jade text editor. The other
two are defined as follows.
Called when copying files between file handlers, this operation should copy the file matching the handler file-name, to the file on the local file system local-name.
Called when copying files between file handlers, this operation should copy the local file file-name to the file matching the handler file-name.
To prevent infinite recursion, while a particular operation is being processed by a file handler, that operation may not be passed back to the same handler.
To allow file handlers to handle the open-file operation, it is
possible to create file handles from arbitrary streams.
Return a new file object that refers to the logical file called file-name, that is not in the local filing system. All access to the file object will be directed through the stream object stream, and the file handler function handler.
An alternative method of opening remote files is to use a temporary
file in the local file system with either one (read or
write modes), or two (append mode) synchronisations with
the remote system. This is the method used by the FTP remote file
backend (see the next section). It has the advantage of simplifying the
seek-file operation.
Librep provides the following file handlers by default:
In Unix, a leading tilde ~ is expanded to the user’s home directory.
Some archive files’ contents are treated like a directory, by adding ``#tar/''. For example, the file foo/bar.jl stored in /dir/baz.tar.gz can be accessed with
(load "/dir/baz.tar.gz#tar/foo/bar")
Supported compressions are gz with suffixes gz and tgz,
bzip2 with bz2, lzma with xz, lz and lzma.
Next: Remote Files, Previous: Manipulating Symlinks, Up: Files [Contents][Index]