Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 4: Basic Editing

Previous HourNext Hour

Sections in this Hour:

 

Miscellaneous File Commands


In this section you will learn how to edit a file on a remote machine and how to edit a compressed file. If you are in a hurry, you can skip this section, but please make sure that you get back here later, because it contains very useful information.

Files on Remote Machines

Emacs enables you to edit files on a remote host. This is almost transparent to you with two exceptions:

To load a file from another host, you must tell it two things:

Emacs then uses FTP to connect to this host and download the file for you to edit.

Note - To use this feature, you must be able to FTP to the remote host.


To ask Emacs to load a file on another host, simply use the commands that you already know for opening files on your local host. You've already learned about C-x C-f (find-file) and C-x C-v (find-alternate-file). As the name of the file, you need to specify your username on the remote host and its name. Use the following syntax:


/user@host:filename

That is a slash, your username, the symbol @, the hostname, a colon, and the filename on the local system.

For example, to load the file /etc/passwd as the user root on the host linux.homenet, type /[email protected]:/etc/passwd.

If your username on the remote machine is the same as the one on your current machine, you can leave out the username@ part. An example would be to edit the file .tcshrc in your home directory on the host linux.homenet. This is done with the filename /linux.homenet:~/.tcshrc

Note how I used the tilde (~) in the preceding. The tilde refers to your home directory on the remote host.

Tip - If you are using a UNIX machine, this is a convenient way of editing a file as root on your local machine. As the username, type root and, as the name of host, type localhost, which refers to the machine on which you are located. This saves you from logging in as root and starting a new Emacs session, which would likely have a setup other than you are used to.

Be warned, however, that some systems don't enable you to FTP into the machine as the superuser.


When Emacs is connected to the remote host it asks you in the minibuffer for the password on the remote host.

Compressed Files and Archives

Emacs has the capability to edit compressed files and archives; that is, files ending in .gz, .Z, .tar, .zip, .arc, .lzh, and .zoo. This makes it possible to avoid uncompressing files or extracting archives when you are low on disk space, for example, or when you do not want to clutter up your hard drive with the content of an archive.

Compressed Files

The library named jka-compr adds capability to Emacs, which makes it capable of transparently reading and writing files compressed by gzip or compress. Transparent means you never notice that the file is, in fact, compressed.

For Emacs to recognize that the file is compressed, the file must end in .gz, .Z or .tgz. The last suffix is for files archived with tar and compressed with gzip.

When you load a compressed file, Emacs simply decompresses it for you before it shows it to you. When you later save the file, it compresses it before writing it to the hard drive. Totally transparent to you! To enable this feature, add the following to your .emacs file:


(require 'jka-compr) 
(jka-compr-install) 

If you are not using XEmacs, the second line is unnecessary.

Archives

When you load an archive, Emacs shows you a list of the files in the archive. Tar archives are handled by the library called tar-mode, whereas Zip, Arc, Lzf, and Zoo archives are handled by the library called arc-mode. This means that the interfaces for these two sets of archives are a bit different, as can be seen in Figures 4.14 and 4.15.

Figure 4.14
Emacs reading a tar archive.

Figure 4.15
Emacs reading a Zip archive.

If you press Enter when point is located on a file, the file is loaded into a buffer, where you can edit it. When you save it, the archive is automatically updated.

This is only half true for tar files. To make it update the tar files, you need to save the buffer that contains the archive (that is, the tar file). In Hour 6, "Editing Several Files at Once," you will learn how to get to this buffer.

In the menus are different functions for manipulating the files of the archive: copying files to or from the archive, renaming files in the archive, changing their permissions, and so on.

Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 4: Basic Editing

Previous HourNext Hour

Sections in this Hour: