328 lines
14 KiB
HTML
328 lines
14 KiB
HTML
<!--startcut ==========================================================-->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<title>EMACSulation Issue 26</title>
|
|
<link rev="made"
|
|
href="mailto:emarsden@mail.dotcom.fr">
|
|
<meta name="keywords"
|
|
content="emacs, ange-ftp, efs, browse-url, ffap, Emacs-w3, fff, webjump">
|
|
<meta name="description"
|
|
content="Emacs in a networked world">
|
|
<meta name="author"
|
|
content="Eric Marsden">
|
|
<meta name="made"
|
|
content="with Emacs">
|
|
</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> <P>
|
|
|
|
<blockquote><small>
|
|
|
|
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.
|
|
|
|
</small></blockquote>
|
|
|
|
|
|
|
|
<h2>Internet-ready!</h2>
|
|
|
|
<p> You've probably heard the hype about ``Internet-ready'' operating
|
|
systems where you can access the Internet with a click of your mouse.
|
|
Well, users of the customizable <a
|
|
href="http://www.jimpick.com/gnome/ui-proposal/">Emacs user
|
|
interface</a> have had the Net only a keypress away since as early as
|
|
1989!
|
|
|
|
<p> Emacs has built-in networking capability, which it uses for connecting
|
|
to news or SMTP servers and for web browsing. To illustrate its use,
|
|
here is a bit of code which opens a TCP connection to port 13 of your
|
|
local machine to request the current time :
|
|
|
|
<pre>
|
|
;; usage: M-x display-date
|
|
(defun display-date ()
|
|
(interactive)
|
|
(let ((stream (open-network-stream "DAYTIME" nil "localhost" "daytime")))
|
|
(set-process-filter stream 'my-process-filter))
|
|
|
|
(defun my-process-filter (proc string)
|
|
(message "Current date is %s" (substring string 0 -1)))
|
|
</pre>
|
|
|
|
<p> This code --which assumes you're running inetd-- should display
|
|
something like the format of <code>date</code> in the minibuffer. The
|
|
rich set of primitives and the integrated error management provided by
|
|
Emacs make it easy to program useful utilities; consider how many
|
|
lines of code would have been required to provide the equivalent
|
|
functionality in C.
|
|
|
|
|
|
<h3>Ange-ftp</h3>
|
|
|
|
<p> <b>Ange-ftp</b> is a package by <a
|
|
href="http://hplbwww.hpl.hp.com/people/ange/">Andy Norman</a> which
|
|
allows Emacs to see the entire Internet as a virtual filesystem. It
|
|
adds remote editing capability by mapping requests for remote files to
|
|
FTP commands. For example, if you ask Emacs to open a file named
|
|
|
|
<pre>
|
|
/marsden@ondine.cict.fr:~/.emacs
|
|
</pre>
|
|
|
|
<p> then ange-ftp will spawn an FTP process, connect to the host
|
|
<tt>salines.cict.fr</tt> as user <tt>marsden</tt>, CWD to my home
|
|
directory, GET my Emacs initialization file and display the file as if
|
|
it were on your local filesystem. If ange-ftp needs a password it will
|
|
read one from the minibuffer. If you make changes to the file and save
|
|
it, it will be PUT back to the server for you. You can even copy files
|
|
from one remote machine to another by typing <code>M-x copy-file RET
|
|
/user1@host1:/path/to/file1 RET /user2@host2:/path/file2</code> ;
|
|
ange-ftp looks after opening two ftp connections for you.
|
|
|
|
<p> Ange-ftp comes pre-installed with Emacs (XEmacs features <b>efs</b>, a
|
|
complete rewrite by the same author). The only customization you might
|
|
need to make is to configure a gateway, if you don't have direct
|
|
Internet access. You can use <tt>~/.netrc</tt> to configure default
|
|
logins for oft used hosts in the traditional way (and even passwords if
|
|
you're foolhardy).
|
|
|
|
<p> Perhaps the most elegant feature of ange-ftp is its seamless
|
|
integration with Emacs; the only visible change it introduces is the
|
|
extended filename syntax. Filename completion (by pressing <tt>TAB</tt>
|
|
in the minibuffer) is available on remote hosts in the same way as on
|
|
your local machine. Ange-ftp works well with Dired, the directory
|
|
editor, allowing you to browse though distant machines, operate on
|
|
several remote files at once, etc. It also works with <a
|
|
href="http://www.cl.cam.ac.uk/texinfodoc/emacs_14.html#SEC71">bookmarks</a>,
|
|
so you can memorize an interesting spot on your favorite ftp server,
|
|
and jump back to the same spot next week with ease. Take a typical
|
|
usage: ask Emacs to open the following directory (with <code>C-x
|
|
C-f</code> or from the Files menubar) :
|
|
|
|
<pre>
|
|
/anonymous@ftp.kernel.org:/pub/linux/kernel/
|
|
</pre>
|
|
|
|
<p> You will be presented with a directory listing many different releases
|
|
of Linux kernels (if you have a line like <code>default login anonymous
|
|
password user@site</code> in <tt>~/.netrc</tt> then ange-ftp can infer
|
|
the <tt>anonymous@</tt> for you automatically). Type <code>C-x r
|
|
m</code> to bookmark the location. There's more on bookmarks in Jesper
|
|
Pedersen's <a
|
|
href="http://www.linuxgazette.com/issue01to08/emacs_mar96.html">article</a>
|
|
in issue 7 of the <i>Linux Gazette</i>.
|
|
|
|
|
|
|
|
<h3>Web browsing</h3>
|
|
|
|
<p> <a href="http://www.cs.indiana.edu/elisp/w3/docs.html">Emacs-w3</a>
|
|
(also referred to by some as <i>Gnuscape</i>) is a web browser written
|
|
by William Perry in Emacs Lisp. It is fairly sophisticated in certain
|
|
respects, having been the first production browser to support cascading
|
|
style sheets. It understands tables, and can display images inline
|
|
under <a href="http://www.XEmacs.org/">XEmacs</a>, or by invoking
|
|
external viewers when hosted by GNU Emacs. Its author notes that
|
|
Emacs-w3 is yet another reason never to leave the comfort of the One
|
|
True Editor, but to me it serves more as a reminder of the deficiencies
|
|
of Emacs Lisp : it is slow, and has a tendency to block while waiting
|
|
on a slow link (unfortunately Emacs is not multi-threaded, though you
|
|
can set the variable <tt>url-be-asynchronous</tt> to t to reduce this
|
|
annoyance). If you want to try it out get the latest version from the
|
|
<a href="ftp://ftp.cs.indiana.edu/pub/elisp/w3/.betas/">betas
|
|
directory</a>, which has many improvements over the version distributed
|
|
on most Linux CDROMs.
|
|
|
|
<p> <b>browse-url</b> is an nifty Emacs extension which can dispatch
|
|
references to URLs to Mozilla or to Emacs-w3. It does this by using
|
|
Netscape's <a
|
|
href="http://home.netscape.com/newsref/std/x-remote.html">remote
|
|
invocation protocol</a>, which as a side note even works when you're
|
|
running the browser on a distant machine (the implementation uses the
|
|
X11 inter-application communication protocol). Emacs features its own
|
|
remote control mechanism which lets you send commands to a running Emacs
|
|
(even on another machine), called gnuserv/emacsclient, which I might
|
|
talk about another time.
|
|
|
|
<p> Recent versions of Emacs are set up to use browse-url in mail and news
|
|
reading modes. URLs should be highlighted when you pass the mouse over
|
|
them, and you can click on them with the middle mouse button to invoke
|
|
your favorite browser. Here's how you can set up browse-url to use
|
|
Mozilla when you're running X11 and Emacs-w3 otherwise :
|
|
|
|
<pre>
|
|
(if (eq window-system 'x)
|
|
(setq browse-url-browser-function 'browse-url-netscape
|
|
browse-url-new-window-p t)
|
|
(setq browse-url-browser-function 'browse-url-w3))
|
|
</pre>
|
|
|
|
<p> Another more indirect use of browse-url is <a
|
|
href="http://nwv.www.media.mit.edu/people/nwv/projects/webjump/">WebJump</a>
|
|
by Neil W. Van Dyke. This Emacs plugin provides a programmable hotlist
|
|
of interesting web sites with which to feed your browser. Perhaps its
|
|
most interesting feature is the ability to send a query to Internet
|
|
search engines such as <a
|
|
href="http://www.altavista.digital.com/">AltaVista</a> and <a
|
|
href="http://www.yahoo.com/">Yahoo!</a> without having to load the
|
|
first page of ads, but it also includes features for dispatching
|
|
searches to FAQ and RFC archives, to the <a
|
|
href="http://www.m-w.com/dictionary.htm">online Webster</a> or <a
|
|
href="http://www.thesaurus.com/">Thesaurus</a>, or to bring up an
|
|
appropriate page of the Java API. Naturally (this is Emacs) you can
|
|
extend it to include your own favorite sites. You might find yourself
|
|
using it more than your browser's bookmarks.
|
|
|
|
|
|
<h3>Files at your Fingertips</h3>
|
|
|
|
<p> <b>ffap</b> is a powerful package which extends the
|
|
<code>find-file</code> command (the one which prompts for a file name
|
|
in the minibuffer, normally bound to <code>C-x C-f</code>). It searches
|
|
the text around the cursor position for something which might represent
|
|
a filename -- a file in the current directory, a C #included file, a
|
|
newsgroup reference, an ange-ftp style reference to a file on a remote
|
|
machine or an URL -- and prompts you either to open that file, or to
|
|
send the URL to a browser (via browse-url). Once experiencing this you
|
|
quickly get sick of typing filenames into the minibuffer, and may find
|
|
yourself inserting ``hyperlinks'' in strategic places in your files to
|
|
save typing. ffap is distributed with both Emacs and XEmacs; I bind it
|
|
to the F3 key as follows :
|
|
|
|
<pre>
|
|
(autoload 'find-file-at-point "ffap" nil t)
|
|
(define-key global-map [(f3)] 'find-file-at-point)
|
|
</pre>
|
|
|
|
<p> or if you prefer you can simply override the traditional
|
|
<tt>find-file</tt> by saying
|
|
|
|
<pre>
|
|
(autoload 'find-file-at-point "ffap" nil t)
|
|
(define-key global-map [(control x) (control f)] 'find-file-at-point)
|
|
</pre>
|
|
|
|
<p> ffap is pretty good at determining interesting filenames; it even knows
|
|
how to recognize RFC names, and from which server they may be obtained.
|
|
It goes to the trouble of pinging remote machines to determine whether
|
|
they are alive, and can naturally be extended to recognize personal
|
|
types of filename references. To conclude on filename shortcuts, you
|
|
might enjoy Noah Friedman's <a
|
|
href="http://www.splode.com/users/friedman/software/emacs-lisp/index.html#fff">fff</a>
|
|
(Fast File Finder) which helps you find files hidden somewhere deep in
|
|
inode-space by querying your <tt>locate</tt> database (part of the GNU
|
|
findutils).
|
|
|
|
|
|
|
|
<h2>Feedback</h2>
|
|
|
|
<p> Several people wrote to me with comments on last month's article on
|
|
<b>jka-compr</b>. <a href="mailto:cbbrowne@hex.net">Chistopher B.
|
|
Browne</a> told me he prefers <a
|
|
href="ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive/misc/crypt++.el.Z">crypt++</a>,
|
|
which provides on-the-fly decryption and encryption as well as
|
|
automatic compression and decompression. Whereas jka-compr trusts the
|
|
filename extension, crypt++ reads the first few bytes of the file to
|
|
determine its type. The package also has functions for dealing with
|
|
DOS-style linefeeds which you might find useful if you have to exchange
|
|
files with other operating systems, although you could just as well say
|
|
<code>(standard-display-ascii 13 "")</code>, which simply hides those
|
|
<tt>^M</tt> characters. Crypt++ is not a standard part of Emacs (it's
|
|
not included in the GNU Emacs distribution, though it is bundled with
|
|
XEmacs). I haven't tested its cryptographic capabilities, because
|
|
|
|
<blockquote>
|
|
<tt><POLITICS></tt> <br>
|
|
|
|
As a French citizen I am <a
|
|
href="http://cwis.kub.nl/~frw/people/koops/cls2.htm#fr">prohibited</a>
|
|
from using any form of encryption. In France encryption requires
|
|
authorization from the <a
|
|
href="http://www.elysee.fr/pdt/pdt.htm">President</a>, which is
|
|
accorded only to large military companies and to financial institutions
|
|
(and then only if the keys are held in escrow). These laws are <a
|
|
href="http://www.uwsg.indiana.edu/hypermail/linux/kernel/9611/0396.html">one
|
|
of the reasons</a> holding back the incorporation of kernel-level
|
|
support for encryption in Linux. Before accusing France of being
|
|
backward, please consider the fact that countries such as Iran, China
|
|
and Russia impose similar restrictions on the freedom of their
|
|
citizens.
|
|
|
|
<br> <tt></POLITICS></tt>
|
|
</blockquote>
|
|
|
|
<p> If you're using the latest version of XEmacs (20.3 stable as of this
|
|
writing), the suggestion I make last month for enabling
|
|
<b>jka-compr</b> won't work. The XEmacs maintainers have decided that
|
|
the behaviour of your editor shouldn't be modified by loading an
|
|
extension module, but by calling an appropriate initialization
|
|
function. The correct way of enabling jka-compr is to say
|
|
<code>(toggle-auto-compression 1 t)</code>. Sorry 'bout that, folks.
|
|
|
|
|
|
|
|
<h2>Next time ...</h2>
|
|
|
|
<p> In the next issue I'll review ediff, a powerful interface to diff
|
|
and patch. Don't hesitate to contact me at
|
|
<tt><emarsden@mail.dotcom.fr></tt> with comments, corrections or
|
|
suggestions (what's <em>your</em> favorite couldn't-do-without Emacs
|
|
extension package?). <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 <a
|
|
href="http://earthspace.net/~esr/open-source.html">open-source</a>
|
|
software, one of the most powerful, complex and customizable, I feel it
|
|
has its place in the <i>Linux Gazette</i>.
|
|
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<center><H4>Previous ``EMACSulation'' Columns</H4></center>
|
|
<P>
|
|
<A HREF="../issue25/marsden.html">EMACSulation #1, February 1998</A> <BR>
|
|
<P> <hr> <P>
|
|
<center><h5>Copyright © 1998, Eric Marsden<br>
|
|
Published in Issue 26 of <i>Linux Gazette</i>, March 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="./clueless.html"><IMG SRC="../gx/back2.gif"
|
|
ALT=" Back "></A>
|
|
<A HREF="./gm.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
|
|
<P> <hr> <P>
|
|
<!--startcut ==========================================================-->
|
|
</BODY>
|
|
</HTML>
|
|
<!--endcut ============================================================-->
|