File: marsden.html

package info (click to toggle)
lg-issue36 2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,920 kB
  • ctags: 242
  • sloc: makefile: 36; sh: 4
file content (297 lines) | stat: -rw-r--r-- 12,328 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>EMACSulation LG #36</title>
<link  rev="made"          href="mailto:emarsden@mail.dotcom.fr">
<meta name="keywords"      content="emacs, abbrev, expansions">
<meta name="author"        content="Eric Marsden">            
<meta name="generator"     content="Emacs">
<meta name="description"   content="Emacs abbreviation mechanisms save you typing">
</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><font color="maroon">EMACSulation</font></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 getting more out 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>

<hr noshade>

<blockquote><font face="Helvetica">
   Why is the word abbreviate so long?
</font></blockquote>


<h1>Time saving</h1>

<p> You've probably noticed that Emacs goes to a fair bit of trouble to
    save you typing. The minibuffer offers a history mechanism which allows
    you to recall and edit previous commands, and many minibuffer entry
    prompts try to complete whatever you're typing when you hit
    <tt>TAB</tt>. This behaviour was the inspiration for the readline and
    history libraries, which are used in several shells and commandline
    interpreters.

<p> This column is dedicated to another of these keystroke-saving features
    in Emacs: the abbreviation facility. Do you get sick of typing in
    repetitive phrases such as your company's name, or your phone number?
    Abbreviations are here to save your fingers. For example, you could ask
    Emacs to expand <strong>LAAS</strong> to <strong>Laboratoire d'Analyse
    et d'Architecture des Syst&egrave;mes</strong>. The expansion happens
    once you type a non word-constituent character after the abbreviation
    (a space, for instance, though the exact definition of a word
    separation depends on the mode you are using).

<p> This is the Emacs abbrev mechanism. You can either use a minor mode
    called abbrev-mode, which will cause abbrevs to expand automatically
    (you enable the minor-mode by saying <tt>M-x abbrev-mode</tt>), or you
    can expand them on demand by saying <tt>C-x a e</tt> with the cursor
    positioned after the abbreviation. Your abbreviations can be saved to a
    file when you quit Emacs and reloaded automatically when you launch it:
    </p>

<table border="0" bgColor="#E0E0E0" width="100%">
<tr><td>
<pre class="programlisting">
    <font color="red">
    ;; if there is an abbrev file, read it in</font>
    (if (file-exists-p abbrev-file-name)
       (read-abbrev-file))</pre>
</td></tr></table>


<h2>Defining an abbrev</h2>

<p> To create an abbrev definition, type the abbreviation
    (<strong>LAAS</strong> in the example above) in a buffer, say <tt>C-x a
    i g</tt>, then enter the text you would like it to expand to in the
    minibuffer. This slightly arcane sequence creates a <em>global
    abbrev</em>, which will apply in all modes. Try it out by entering the
    abbreviation and saying <tt>C-x a e</tt> (<tt>e</tt> for
    <em>expand</em>). Emacs also allows you to create abbreviations which
    will be active only in a specific mode by saying <tt>C-x a i l</tt>
    instead (in a buffer which is already in the appropriate mode). <tt>M-x
    list-abbrevs</tt> displays a list of all currently defined abbrevs.


<h2>Mail abbrevs</h2>

<p> Since the dawn of time, Unix mail programs have used the
    <tt>~/.mailrc</tt> file to allow users to create their own email
    aliases. The mail-abbrevs mechanism reads in the contents of this file
    and defines abbreviations which will be expanded in the
    <strong>To:</strong> and <strong>Cc:</strong> fields of any email you
    compose in Emacs. Here is an example of the <tt>~/.mailrc</tt> alias
    syntax: </p>

<pre>
    alias dsssl        dssslist@mulberrytech.com
    alias cohorts      rabah jarboui almeida behnia
    alias bond         "James Bond &lt;bond@guerilla.net&gt;"
</pre>

<p> There are other more sophisticated addressbook systems around, such as
    Jamie Zawinski's <a
    href="http://pw2.netcom.com/~simmonmt/bbdb/">BBDB</a>, but they
    won't allow you to share aliases with other mailers. You can have
    mail-abbrev minor mode activated whenever you compose an email in
    Emacs using the following line in your <tt>~/.emacs</tt>: </p>

<table border="0" bgColor="#E0E0E0" width="90%">
<tr><td>
<pre class="programlisting">
    <font color="red">
    ;; unnecessary if you use XEmacs</font>
    (add-hook 'message-setup-hook 'mail-abbrevs-setup)</pre>
</td></tr>
</table>

    

<h2>Dynamic abbrevs</h2>
    
<p> The standard abbreviation facility requires you explicitly to register
    your abbrevs, which is fine for things you type every week, but is a
    hassle for expressions which only occur in one document. Emacs also
    supports <em>dynamic abbrevs</em>, which try to guess the word you are
    currently typing from the surrounding text. This is very useful for
    programming in languages which encourage VeryLongVariableNames: you
    only need type the variable name once, after which it suffices to type
    the first few letters followed by <tt>M-/</tt>, and Emacs will try to
    complete the variable name.

<p> To be very precise, dabbrev searches for the least distant word of
    which the word under the cursor is a prefix, starting by examining
    words in the current buffer before the cursor position, then words
    after the cursor, and finally in all the other buffers in your Emacs.
    If there are several possible expansions (<i>ie</i> the text you have
    typed isn't a unique prefix), pressing <tt>M-/</tt> cycles though the
    successive possibilities. Saying <tt>SPC M-/</tt> lets you complete
    phrases which contain several words.

<p> Diehard vi users might be interested to read the <a
    href="http://www.eskimo.com/~seldon/dabbrev-vi.txt">tribulations of a
    user</a> who tried to implement a limited version of dabbrevs in vi.
    

<h2>Completion</h2>
    
<p> The Completion package, by Jim Salem, is similar in function to dynamic
    abbrevs, but uses a different keybinding (<tt>M-RET</tt>) and a subtly
    different algorithm. Rather than searching for a completion which is
    close in the buffer, it starts by searching through words which you
    have typed in recently (falling back to searching open buffers if this
    fails). The history of recently used words is saved automatically when
    you quit Emacs. To enable completion (you can use it instead of, or as
    well as, dabbrevs), put the following in your <tt>~/.emacs</tt>: </p>

<table border="0" bgColor="#E0E0E0" width="90%">
<tr><td>
<pre class="programlisting">

    (require 'completion)
    (initialize-completions)</pre>
</td></tr>
</table>



<h2>Hippie Expand</h2>
    
<p> Filename completion in the minibuffer is a truly wonderful keystroke
    saver, and you might find yourself wishing you could use it when
    entering a filename in a regular buffer. Wish no longer: this is one of
    the features offered by the fabulous hippie-expand package.

<p> Hippie-expand, by Anders Holst, is a singing and dancing abbrev
    mechanism, which is capable of many different types of dynamic abbrevs.
    It can expand according to:

<ul>    
<li> file name: if you type <tt>/usr/X</tt> then hit the
     expansion key, it will expand to <tt>/usr/X11R6/</tt>;
<li> exact line match: searches for a line in the buffer which has the
     current line as a prefix;
<li> the contents of the current buffer, and other buffers on failure, just
     like dabbrev;
<li> the contents of the kill-ring (which is where Emacs stores text that
     you have <em>killed</em>, or ``cut'' in MacOS terminology, in
     a circular buffer). Rather than typing <tt>M-y</tt> to cycle through
     positions in the kill-ring, you can hippie-expand on the first word in
     the killed text.
</ul>

<p> Hippie-expand is not active by default, so you need to bind it to a
    key. Here's what I use: </p>

<table border="0" bgColor="#E0E0E0" width="90%">
<tr><td>
<pre class="programlisting">

    (define-key global-map (read-kbd-macro "M-RET") 'hippie-expand)</pre>
</td></tr>
</table>
    

<p> Go forth and save keystrokes.
    

<h2>Feedback</h2>

<p> <a href="mailto:gtb@Eng.Sun.COM">Glenn Barry</a> sent me a comment on
    the EMACSulation on gnuclient/gnuserv:

<blockquote>

<! b69454 >
<table bgColor="#BBDDFF" width="80%" border="0">
<tr><td>    
    Just read and enjoyed your article on gnuserv/gnuclient in the
    Linux Gazette.

<p> But you forgot the use of gnuserv/gnuclient that makes it incredibly
    useful; one can access their full running emacs session by logging-in
    via a tty remotely (rlogin/telnet) and running &quot;gnuclient -nw&quot; ...
    makes working from home a breeze (even over low speed (28.8) links).

<p> Note you do have to rlogin to the system running the emacs
    w/gnuserv, as the <tt>gnuclient -nw</tt> does not work over the net
    (at least that's what the man page says). It took me awhile to
    figure this out so it would be nice to make sure folks know about
    this great capability.
</td></tr>
</table>
</blockquote>

<p> The <tt>-nw</tt> switch asks Emacs to start up in console mode, which
    makes it much more useable over a slow connection than using a remote
    display with X11. Note that XEmacs is able to use ANSI colors on the
    console or in an xterm, while GNU Emacs currently can't do color but
    does offer a text-mode menubar.

<p> Glenn also gave an illustration of the power of ffap: he has customized
    it to recognize Sun bug numbers under the cursor and dispatch a
    dynamically generated URL to a web front end for their bug tracking
    system.


<h2>Next time ...</h2>

<p> Next month I'll look at skeleton insertion and templating mechanisms
    in Emacs. Don't hesitate to contact me at
    <tt>&lt;emarsden@mail.dotcom.fr&gt;</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> <strong>PS</strong>: Emacs isn't in any way limited to Linux, since
    implementations exist for many other operating systems (and some
    systems which only halfway operate). 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>.
<!--===================================================================-->
<P> <HR> <P> 
<A HREF="../issue25/marsden.html">EMACSulation #1, February 1998</A><BR>
<A HREF="../issue26/marsden.html">EMACSulation #2, March 1998</A><BR>
<A HREF="../issue27/marsden.html">EMACSulation #3, April 1998</A><BR>
<A HREF="../issue29/marsden.html">EMACSulation #4, June 1998</A><BR> 
<A HREF="../issue31/marsden.html">EMACSulation #5, August 1998</A>

<!--===================================================================-->
<P> <hr> <P> 
<center><H5>Copyright &copy; 1999, Eric Marsden <BR> 
Published in Issue 36 of <i>Linux Gazette</i>, January 1999</H5></center>

<!--===================================================================-->
<P> <hr> <P> 
<A HREF="./lg_toc36.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif" 
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../lg_frontpage.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./defurne1.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./defurne2.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P> 
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->