old-www/LDP/LG/issue25/marsden.html

148 lines
5.7 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>EMACSulation LG #25</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<h1>EMACSulation</h1>
<h4>By
<a href="mailto:emarsden@mail.dotcom.fr">Eric Marsden</a></h4>
</center>
<p><hr>
<img align="left" src="./gx/marsden/EMACSulation.gif">
This column is devoted to making the best use of Emacs, text editor
extraordinaire. Each issue I plan to present an Emacs extension
which can improve your productivity, make the sun shine more
brightly and the grass greener.
<P> <HR>
<p> <b>Jka-compr</b> is a package written by Jay K. Adams which allows
Emacs to handle compressed files transparently. When you open a
compressed file, Emacs will automatically decompress it before
displaying it. If you make changes and save the file, it will be
compressed transparently before being written to the disk. To
enable jka-compr, just add the following line to your emacs
configuration file (normally called <tt>~/.emacs</tt>) :
<pre>
(require 'jka-compr)
</pre>
<p> jka-compr works by looking at the filename extension, and in its
default configuration recognizes <tt>.gz</tt> (gzip), and
<tt>.Z</tt> (compress) files. It also recognizes the extension
<tt>.tgz</tt> and unzips tarballs before passing them to tar-mode,
which lets you look inside tar files. If you use other compression
programs you can tell Emacs about them too, for example to use
Julian Seward's <a href="http://www.muraroa.demon.co.uk/">bzip2</a>
(faster and slightly better compression than gzip, under GPL) you
could add the following to your <tt>.emacs</tt> (<em>before</em>
loading jka-compr)
<pre>
(setq jka-compr-compression-info-list
'(["\\.Z\\(~\\|\\.~[0-9]+~\\)?\\'"
"compressing" "compress" ("-c")
"uncompressing" "uncompress" ("-c")
nil t]
["\\.tgz\\'"
"zipping" "gzip" ("-c" "-q")
"unzipping" "gzip" ("-c" "-q" "-d")
t nil]
["\\.gz\\(~\\|\\.~[0-9]+~\\)?\\'"
"zipping" "gzip" ("-c" "-q")
"unzipping" "gzip" ("-c" "-q" "-d")
t t]
["\\.bz2\\(~\\|\\.~[0-9]+~\\)?\\'"
"bzipping" "bzip2" ()
"bunzipping" "bzip2" ("-d")
nil t]))
</pre>
<h3>How does it work?</h3>
<p> Packages like jka-compr are written in Emacs Lisp; you can read
the source code in the directory
<tt>/usr/local/lib/emacs/${VERSION}/lisp/jka-compr.el</tt> for GNU
Emacs, or
<tt>/usr/local/lib/xemacs-${VERSION}/lisp/packages/jka-compr.el</tt>
for XEmacs users (if you are using a Red Hat Linux distribution,
you need to install the emacs-el package to see the source
files). How can they change the behaviour of Emacs at such a low
level as reading and writing files? The answer comes from the
concept of <em>hooks</em>.
<p> Most of Emacs' low-level functions (which are written in C) have
an associated hook, to which user-level functions (written in
Emacs Lisp) can be attached. Hooks are fundamental to the
customizability of Emacs, allowing users to override default
behaviour in ways that its developers could not have imagined.
Hooks are explained in the Emacs and Elisp manuals, which are
available online from within Emacs by typing <code>C-h i</code>
(or from the Help menubar or (blech!) the XEmacs toolbar).
<p> As an example of using a hook, the <code>after-init-hook</code> is
run right after Emacs is lauched and has loaded your
initialization file. Let's say you want Emacs to tell your fortune
each time you start it. Just add the following lines to your
<tt>.emacs</tt> :
<pre>
(add-hook 'after-init-hook
(function
(lambda ()
(pop-to-buffer (get-buffer-create " *Fortune*"))
(shell-command "fortune -a" t))))
</pre>
<h3>Next time ...</h3>
<p> In the next issue I'll discuss <b>ange-ftp</b>, which lets Emacs
see the Internet as a huge virtual filesystem. Please contact me
at <tt>&lt;emarsden@mail.dotcom.fr&gt;</tt> with comments,
corrections or suggestions. <code>C-u 1000 M-x hail-emacs</code> !
<p> <b>PS</b>: Emacs isn't in any way limited to Linux, since
implementations exist for many other operating systems. However,
as one of the leading bits of free software, one of the most
powerful, complex and customizable, I feel it has its place in the
<i>Linux Gazette</i>. Don't forget, <b>E</b>macs <b>m</b>akes
<b>a</b>ll <b>c</b>omputing <b>s</b>imple :-)
<!--===================================================================-->
<P> <hr> <P>
<center><h5>Copyright &copy; 1998, Eric Marsden<br>
Published in Issue 25 of <i>Linux Gazette</i>, February 1998</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./pavlicek.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./appleton.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->